123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /*!
- * \file src/Window.cpp
- * \brief windowing implementation
- *
- * \author xythobuz
- */
-
- #include <cstdio>
- #include <cstring>
- #include <cstdarg>
- #include <assert.h>
-
- #ifdef __APPLE__
- #include <OpenGL/gl.h>
- #elif defined WIN32
- #include <gl/glew.h>
- #include <gl/wglew.h>
- #else
- #include <GL/gl.h>
- #endif
-
- #include "math/math.h"
- #include "Window.h"
-
- Window::~Window() {
- }
-
- 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);
- }
|