Richard Cripps
Richard Cripps

Reputation: 193

Camera control opengl

I have found a difficulty in my opengl game i am creating. i have a camara class with code that should all work. i.e.

void keyboard (unsigned char key, int x, int y) {

    keyStates[key] = false;

    if (key=='q')
    {
    xrot += 1;
    if (xrot >360) xrot -= 360;
    }

    if (key=='z')
    {
    xrot -= 1;
    if (xrot < -360) xrot += 360;
    }
etc..

}

however, when i try to put this into my main() it throws up an exception handling error. my main code is:

int main(int argc,char** argv)
{

    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_OPENGL);
    bool running=true;
    Uint32 start;
    SDL_Event event;
    init();
    glutKeyboardFunc(keyboard);

    while(running)
    {

        start=SDL_GetTicks();


        while(SDL_PollEvent(&event))
        {
            switch(event.type)
            {

                case SDL_QUIT:
                    running=false;
                    break;
            }
        }

        display();

        SDL_GL_SwapBuffers();
        angle+=0.0;
        if(angle>360)
            angle-=360;
        if(1000/30>(SDL_GetTicks()-start))
            SDL_Delay(1000/30-(SDL_GetTicks()-start));  
    }

    SDL_Quit();

    return 0;   

}

sorry if my code is unclear, i have blender integrated into the opengl.

Upvotes: 0

Views: 273

Answers (1)

Freezerburn
Freezerburn

Reputation: 1013

First of all, why are you using GLUT and SDL at the same time? SDL provides all the facilities that GLUT does, but generally better. You can use the event queue SDL provides for input, and not GLUT's keyboard function.

Second, I'm pretty sure that attempting to use any GLUT functions without calling glutInit(argc, argv) will cause it to hard shut down the program. Looking at some documentation, that definitely seems to be the case. Try removing that, and extend your SDL event cases to handle keyboard input. Here is a small and simple example for doing just that.

Upvotes: 1

Related Questions