E:/Eigene Dateien/Eigene Projekte/c0re/GLInterface.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of c0re.
00003 
00004         c0re is a multiplayer RTS on a hexagonal map with an evolving unit concept.
00005     Copyright (C) 2007 Stephan Hofmann
00006 
00007     c0re is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "GLInterface.h"
00022 
00023 #include "system.h"
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 
00027 #include "Window.h"
00028 
00029 GLInterface::GLInterface(Window* p_window)
00030 {
00031         window = p_window;
00032         window ->registerMessagequeue(&inputMessages);
00033 }
00034 
00035 GLInterface::~GLInterface()
00036 {
00037         delete window;
00038 }
00039 
00040 
00041 int GLInterface::initGL()
00042 {
00043         window->makeCurrent();
00044         base = window->BuildFont();
00045 
00046         glShadeModel(GL_SMOOTH);                                                // Enables Smooth Shading
00047         glClearColor(0.05f, 0.05f, 0.05f, 1.0f);                                        // Black Background
00048         glClearDepth(1.0f);                                                     // Depth Buffer Setup
00049         glEnable(GL_DEPTH_TEST);                                                // Enables Depth Testing
00050         glDepthFunc(GL_LEQUAL);                                                 // The Type Of Depth Test To Do
00051         glDepthRange(0,1);
00052         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);                      // Really Nice Perspective Calculations
00053         glMatrixMode(GL_PROJECTION);                            // Select The Projection Matrix
00054         
00055         GLfloat LModelAmbient[4] = {1.0, 1.0, 1.0, 1.0};
00056         GLfloat L0Position[4] = {0.0, 2000.0, 0.0, 0.0};
00057         glEnable(GL_LIGHT0);
00058 
00059         glEnable(GL_NORMALIZE);
00060         glEnable (GL_LIGHTING);
00061         glEnable (GL_COLOR_MATERIAL);
00062         glLightfv(GL_LIGHT0, GL_POSITION, &L0Position[0]);
00063         glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &LModelAmbient[0]);
00064         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
00065         glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
00066         glDisable (GL_CULL_FACE);
00067         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00068         glEnable(GL_TEXTURE_2D);
00069 
00070         return 0;
00071 }
00072 
00073 int GLInterface::glPrint2d(double x, double y, const char *fmt, ...)                                    // Custom GL "Print" Routine
00074 {
00075         int ret = 0;
00076 
00077         glPushMatrix();
00078 
00079         glRasterPos2d(x, y);
00080         char            text[256];                                                              // Holds Our String
00081         va_list         ap;                                                                             // Pointer To List Of Arguments
00082 
00083         if (fmt == NULL)                                                                        // If There's No Text
00084                 return -1;                                                                                      // Do Nothing
00085 
00086         va_start(ap, fmt);                                                                      // Parses The String For Variables
00087             vsprintf_s(text, fmt, ap);                                          // And Converts Symbols To Actual Numbers
00088         va_end(ap);                                                                                     // Results Are Stored In Text
00089 
00090         glPushAttrib(GL_LIST_BIT);                                                      // Pushes The Display List Bits
00091         glListBase(base - 32);                                                          // Sets The Base Character to 32
00092         glCallLists((GLsizei)strlen(text), GL_UNSIGNED_BYTE, text);     // Draws The Display List Text
00093         glPopAttrib();                                                                          // Pops The Display List Bits
00094         glPopMatrix();
00095         return ret;
00096 }
00097 

Generated on Tue Jul 17 22:02:22 2007 for C0re by  doxygen 1.5.2