Small problem with SDL and OpenGL

Started by
2 comments, last by Dysprosium 16 years, 1 month ago
Hey guys! I have a small problem I haven't been able to solve in the past few hours. I have just switched from GLUT to SDL for obvious reasons, and after having set up the window, I can't get my program to actually draw anything. I have located the problem and it is the lack of glutPostRedisplay(). I haven't been able to find the equivalent of this function anywhere. Does anyone know what to call? This is the code for my screen updating function.
void updateScreen(){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    updateObjects(timer.getTime());
    for(int i = 0; i < totalObjects; i++) {
        objects->draw();
    }
    SDL_GL_SwapBuffers();
    
    if (timer.elapsed(randObjTime)){
        createRandomObject();
        randObjTime += 200;
    }
    //glutPostRedisplay();
}

Thanks in advance. [Edited by - Dysprosium on March 14, 2008 8:45:05 PM]
Give a man a fire and he'll be warm for the rest of the night.Set a man on fire and he'll be warm for the rest of his life.
Advertisement
SDL_GL_SwapBuffers should do that for you. I can't really tell what's wrong with your code, can you post a small program that replicates it? Often in writing the smaller, more simple program you see what's wrong.

Perhaps the problem is with the OpenGL calls. I'd call glMatrixMode(GL_MODELVIEW) before glLoadIdentity just in case. If you never called glMatrixMode after setting up your projection matrix, you can often see something the first frame then nothing in later frames.

Oh, and when posting code, put the code in source tag, like this (but without that spaces in the tags):
[ source ]code goes here[ /source ]
That didn't work. Though now I know that the lack of glutPostRedisplay is not the problem. I'll look for the issue elsewhere in the code then, before asking another question. Thanks for the quick reply! :)

P.S. And thanks for the
 tip!
Give a man a fire and he'll be warm for the rest of the night.Set a man on fire and he'll be warm for the rest of his life.
For those of you who were curious, I managed to find out what it was.

I cleared the background after a few seconds, and noticed that worked, so it WAS actually drawing on my screen.
Then I changed one of my objects coordinates to (0,0) and noticed it being drawn, hideously malformed.

Turns out the problem was my 'reshape' function that GLUT used to call, wasn't used in my new program (duh!). I have solved the problem for fullscreen mode, so I'm happy. Thanks!
Give a man a fire and he'll be warm for the rest of the night.Set a man on fire and he'll be warm for the rest of his life.

This topic is closed to new replies.

Advertisement