0
votes

I'm implementing a pan/zoom viewer for jpegs. I show one image at a time mapped to a texture, then on a key press, swap between images.

My problem is that although the image does change, the size of the quad is fixed to the width and height of the first image loaded and does not update. Here is the code for drawing the quad etc:

note that ROI_WIDTH and ROI_HEIGHT are global variables that do update successfully each time a new image is loaded, however this is not reflected in the output:

void orthogonalStart (void) {
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, ROI_WIDTH, 0, ROI_HEIGHT);
    glScalef(1, -1, 1);
    glTranslatef(0, -ROI_HEIGHT, 0);
    glMatrixMode(GL_MODELVIEW);
}

void orthogonalEnd (void) {
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
}


void display (void) {
    glClearColor (1.0,1.0,1.0,0.0);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    orthogonalStart();

    glEnable( GL_TEXTURE_2D );
    glEnable( GL_DEPTH_TEST );
    glDepthFunc(GL_LESS);

    glBindTexture( GL_TEXTURE_2D, texture );
    glRotatef(180.0, 250.0f, 250.0f, 0.0f);

    glBegin(GL_QUADS);
    glTexCoord2i(0,0); glVertex2f(0, 0);
    glTexCoord2i(1,0); glVertex2f(0, ROI_WIDTH);
    glTexCoord2i(1,1); glVertex2f(ROI_HEIGHT, ROI_WIDTH);
    glTexCoord2i(0,1); glVertex2f(ROI_HEIGHT, 0);
    glEnd();


    orthogonalEnd();
    zoomFac();
    glViewport (xView, yView, (GLsizei)(winx*zoomFactor), (GLsizei)(winy*zoomFactor));
    glutSwapBuffers();
}
1

1 Answers

1
votes

Your call to gluOrtho2D() is telling OpenGL that the width and height of your output is always ROI_WIDTH by ROI_HEIGHT units. So your quad is always going to cover the entire output area. You should probably set width and height in gluOrtho2D() to the pixel width and height of your output area (your window, or view, or screen, depending on how you've set things up).