/*! * \file src/Window.cpp * \brief windowing implementation * * \author xythobuz */ #include #include #include #include "global.h" #include "math/math.h" #include "utils/strings.h" #include "Window.h" Window::~Window() { if (mDriver) delete [] mDriver; } unsigned int Window::getWidth() { return mWidth; } unsigned int Window::getHeight() { return mHeight; } void Window::setDriver(const char *driver) { assert(driver != NULL); assert(driver[0] != '\0'); assert(mInit == false); mDriver = bufferString("%s", driver); } int Window::initializeGL() { // Print driver support information //printf("GL Vendor : %s\n", glGetString(GL_VENDOR)); //printf("GL Renderer: %s\n", glGetString(GL_RENDERER)); //printf("GL Version : %s\n", glGetString(GL_VERSION)); // Testing for goodies const char *s = (const char *)glGetString(GL_EXTENSIONS); if ((s != NULL) && (s[0] != '\0')) { //! \todo MultiTexture flag //if (strstr(s, "GL_ARB_multitexture")) //mFlags |= Render::fMultiTexture; } // Set up Z buffer glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); // Set up culling glEnable(GL_CULL_FACE); glFrontFace(GL_CW); //glFrontFace(GL_CCW); //glCullFace(GL_FRONT); // Set background to black glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Disable lighting glDisable(GL_LIGHTING); // Set up alpha blending glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //glEnable(GL_ALPHA_TEST); // Disable per pixel alpha blending glAlphaFunc(GL_GREATER, 0); glPointSize(5.0); // Setup shading glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_FOG_HINT, GL_NICEST); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DITHER); // AA polygon edges glEnable(GL_POLYGON_SMOOTH); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); glDisable(GL_AUTO_NORMAL); glDisable(GL_LOGIC_OP); glDisable(GL_TEXTURE_1D); glDisable(GL_STENCIL_TEST); glDisable(GL_FOG); glDisable(GL_NORMALIZE); glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_EDGE_FLAG_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glPolygonMode(GL_FRONT, GL_FILL); glMatrixMode(GL_MODELVIEW); return 0; } void Window::resizeGL() { float fovY = 40.0f; // 45.0f float clipNear = 10.0f; // 4.0f float clipFar = 600000.0f; // 4000.0f glViewport(0, 0, mWidth, mHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Adjust clipping GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear; GLfloat fW = fH * ((GLfloat)mWidth) / ((GLfloat)mHeight); glFrustum(-fW, fW, -fH, fH, clipNear, clipFar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void Window::glEnter2D() { glPushAttrib(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); /* This allows alpha blending of 2D textures with the scene */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glViewport(0, 0, mWidth, mHeight); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, (GLdouble)mWidth, (GLdouble)mHeight, 0.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } void Window::glExit2D() { glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glMatrixMode(GL_MODELVIEW); }