Using the glEnable() Command Inside a Class

Member
Posts: 23
Joined: 2006.12
Post: #1
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!
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
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)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Using GLUT With Multitouch and Command Keys Rasterman 7 4,757 Feb 10, 2010 07:40 PM
Last Post: Rasterman
  seeing the inside of a sphere Najdorf 10 4,232 Jul 17, 2006 09:19 PM
Last Post: OneSadCookie