-1

I'm trying to use the gluLookAt() function to control zooming in and out. Right now it isn't changing the matrix at all and I don't know why.

Here's the relevant code:

// Basic Opengl display function
void onDisplay()
{
   // Clear the initial buffer
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Set up viewing transformation, looking down -Z axis
    glLoadIdentity();
    gluLookAt(0, 0, zPosition, 0, 0, -1, 0, 1, 0);


    // Draw the complete Mandelbrot set picture
    glDrawPixels(520, 520, GL_RGB, GL_FLOAT, pixels);
    //glLoadIdentity();
    glutSwapBuffers();
}

void keyPressed (unsigned char key, int x, int y)
{
    if(key == 'w')
    {
        printf("pressed %a", key);
        printf("\n");
        zPosition -= 1.0;
        glutPostRedisplay();
    }
}

Is it something to do with the glLoadIdentity() calls? I'm not too familiar with the different identities in openGL.

So how can I change this code to make a keypress on w zoom in?

Sonofblip
  • 1,167
  • 3
  • 12
  • 20
  • 1
    Have you set your projection matrix? If not, then it will be identity, which means that you're using [orthographic projection](http://en.wikipedia.org/wiki/Orthographic_projection). That way, moving `z` will do nothing because that only changes what it looks like if you're using perspective. – vesan Jan 27 '15 at 21:41
  • @vesan: Doesn't matter. glDrawPixels isn't influenced in that way by the PMV transformation. – datenwolf Jan 27 '15 at 23:14
  • @datenwolf: Ah, it has glDrawPixels. My bad, didn't notice that. In that case you are right of course. – vesan Jan 27 '15 at 23:16

1 Answers1

0

glDrawPixels is not influences by the transformation matrix as one would naively assume. In particular the position set glRasterPos is transformed to a point in the viewport, which is then the origin for a regular pixel-by-pixel blitting from the data to the framebuffer. Which means no scaling or such happens by this.

Use a textured quad to get the desired effect. And don't use glDrawPixels. Ever! glDrawPixels is slow, has tons of problems and is so poorly supported, that it was decided that it's better to remove it completely from OpenGL-3 and later.

datenwolf
  • 159,371
  • 13
  • 185
  • 298