switch from glOrtho to gluPerspective

Posted by Knitex on Stack Overflow See other posts from Stack Overflow or by Knitex
Published on 2012-11-07T14:46:54Z Indexed on 2012/11/07 17:00 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

I have a car draw at (0,0) and some obstacles set up but right now my main concern is switching from glPerspective to glOrtho and vice-versa. All that i get when i switch from perspective to ortho is a black screen.

void myinit(){
    glClearColor(0.0,0.0,0.0,0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60,ww/wh,1,100);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-5,5,3,backcarx,topcarx,0,0,0,1);
}

void menu(int id){
    /*menu selects if you want to view it in ortho or perspective*/
    if(id == 1){
        glClear(GL_DEPTH_BUFFER_BIT);
        glViewport(0,0,ww,wh);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-2,100,-2,100,-1,1);
        glMatrixMode(GL_MODELVIEW);
        glutPostRedisplay();
    }
    if(id == 2){
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60,ww/wh,1,100);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        viewx = backcarx - 10;
        viewy = backcary - 10;
        gluLookAt(viewx,viewy,viewz,backcarx,topcarx,0,0,0,1);
    }
}

i've tried using the clear depth buffer and still doesnt work.

© Stack Overflow or respective owner

Related posts about c

    Related posts about opengl