OOP and OpenGL

Hi all,

Does someone see any problem with this piece of code?
Does it have anything to do with the fact that I don't call all the ogl functions in one single scope? And why does the update function work but the reshape doesn't?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Game {
    public:
        Game(int argc, char* argv[]);
        static void update(int value); // This Works with OGL
        static void reshape(int width,int height); // This does not seem to work
        void execute(void);
    /* other stuff */
};

Game::Game(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGBA);
    glutInitWindowSize(getScreenSize().x,getScreenSize().y);
    glutReshapeFunc(reshape); // set reshape function
    /* other stuff non-ogl */
    glutTimerFunc(m_timercallback,update,m_timercallback); // set update function
}

void Game::update(int value) // This works!
{
    glutPostRedisplay();
    glutTimerFunc(timercallback,update,timercallback);
}

void Game::reshape(int width,int height) // Doesn't work
{
    glViewport(0,0,width,height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0,
                   (double)width / (double)height,
                   1,
                   100.0);
    glMatrixMode(GL_MODELVIEW);
}

void Game::execute(void)
{
    glutCreateWindow("Window title");
    glutMainLoop();
}


Further I have an event manager (a singleton) that handles the glut-callbacks.
Game inherits from this But the only thing that's set is still the update callback... Can anybody tell me why or even how I could fix this?

Or maybe how I could debug this????...

Thanks for reading ;-)
Last edited on
I found out what it was (in case someone is interested...)

I had to set the draw function and reshape function after I create the window but before I enter the main loop....
Topic archived. No new replies allowed.