Pergunta

I use Tao Framework and I have a problem with using glLoadIdentity(), I'm loading picture in to a gluDisk successfully, I can see the picture, then when I try to change the camera's position with gluLookAt the picture I have loaded on the gluDisk is gone , instead, all I see is a color that reminds the background color of the picture I have loaded, after using debugging I saw that it happens because of the glLoadIdentity() function.

Here is the function that redraw the Disk:

Gl.glClearColor(0F, 0F, 0F, 1.0F);

while (true)
{
    world.drawWorld();
    Application.DoEvents();
    Thread.Sleep(20);
}

here is my code for changing the lookat:

Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glMatrixMode(Gl.GL_MODELVIEW); //Switch to the drawing perspective
Gl.glLoadIdentity(); 
switch (Convert.ToInt32(e.KeyChar))
{
    //down arrow
    case 76:
        rotAngle -= 0.5f;
        rotY -= 0.1f;
        //rotX = 0;
        break;
    //up arrow
    case 82:
        rotAngle += 0.5f;
        rotY += 0.1f;
        //rotX = 0;
        break;
    // left arrow
    case 85:
        rotAngle -= 0.5f;
        //rotY = 0;
        rotX -= 0.1f;
        break;
    //right arrow
    case 68:
        rotAngle += 0.5f;
        //rotY = 0;
        rotX += 0.1f;
        break;

    case 'a':
        xMove -= 1;
        Glu.gluLookAt(xMove, yMove, zMove, xMove + 2, yMove + 2, zMove + 2, 0, 1, 0);
        break;

    case 'd':
        xMove += 1;
        Glu.gluLookAt(xMove, yMove, zMove, xMove + 2, yMove + 2, zMove + 2, 0, 1, 0);
        break;

    case 'w':
        yMove +=1;
        Glu.gluLookAt(xMove, yMove, zMove, xMove + 2, yMove + 2, zMove + 2, 0, 1, 0);
        break;

    case 's':
        yMove -= 1;
        Glu.gluLookAt(xMove, yMove, zMove, xMove + 2, yMove + 2, zMove + 2, 0, 1, 0);
        break;

    case 'z':

        zMove += 1F;
        Glu.gluLookAt(xMove, yMove, zMove, 0, 0, 0, 0, 1, 0);
        break;

    case 'x':
        zMove -= 1F;
        Glu.gluLookAt(xMove, yMove, zMove, 0, 0, 0, 0, 1, 0);
        break;

    case '0':
        //zMove -= 1F;
        Glu.gluLookAt(1, 1, 1, 0, 0, 0, 0, 1, 0);
        break;

Here is my drawing code:

Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

Gl.glEnable(Gl.GL_TEXTURE_2D);
LoadTexture();
Glu.GLUquadric qobj = Glu.gluNewQuadric();
Glu.gluQuadricTexture(qobj, Gl.GL_TRUE);
//Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);
Gl.glPushMatrix();
Gl.glRotatef(80f, 1.0f, 0.0f, 0.0f);
Glu.gluDisk (qobj,0, 800, 900, 300);
Gl.glPopMatrix();
Foi útil?

Solução

Never(!) put OpenGL state change functions into an event handler! Right now you have exactly this. In your keypress handler change some variable, then issue a redraw event and use that to apropriately setup the matrices in the drawing function.

glLoadIdentity has to do with this only insofar, that you call it at a place, where it does not belong. OpenGL is a drawing API not a scene graph.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top