iDevGames Forums
Using the glEnable() Command Inside a Class - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Using the glEnable() Command Inside a Class (/thread-2491.html)



Using the glEnable() Command Inside a Class - Jaden - Aug 2, 2008 09:21 PM

I'm using the program structure from www.meandmark.com as the basis for my little opengl program.

Anyways, the tutorial basically puts all of the game engine into it's own class. I really like this structure, but it's recently caused me some issue.

The main program basically looks like this:
Code:
int main(int argc, char *argv[])
{
    gEngine theGame;
    
    theGame.InitApp();
    theGame.EventLoop();
    theGame.Cleanup();
    
    return 0;
}

Anyways, inside of InitApp, I have various initlization functions, including my function which sets up opengl. This works great for setting up my SDL_Surface, setting the viewport, etc.

But I realized after a bit, that a lot of commands weren't having any effect.
Like, glEnable(fog); or glEnable(Lighting);.

I eventually tried dropping all of those commands, (the glEnable ones) inside of theGame.EventLoop();. (I tied them to a key event.) Suddenly, all the commands were having their desired effect!

I assume I misunderstand some facet of the C++ language, or object-orientated programming in general that's causing this to happen. If anyone could explain to me why this is happening and how I could appropriately get my initialization code back inside of theGame.InitApp(); I would be greatly appreciative!


Using the glEnable() Command Inside a Class - akb825 - Aug 2, 2008 11:28 PM

My guess is you were calling the functions before you initialized the render window and OpenGL context. No OpenGL commands will work correctly (and may sometimes even crash) if you call them before you initialize the OpenGL context. I take it the InitApp function also creates the SDL window etc., so just make sure you move all of your OpenGL calls after the render window is completely initialized. (but it can still reside in the same function, of course)