How can I change [-1,1] range from gluPerspective?

Started by
9 comments, last by ak09 10 years, 11 months ago

Thanks for the replies.

I assumed this is what he wants, for example to be able to do a 2D UI with nice 3D transitions.



That's exactly what I want: be able to see my layers from different perspectives and choose one among them with a nice interface.

However, I couldn't make it work yet. Tried both approaches, from Bob and Olof, but stills nothing.

I don't know if I'm doing the calculations ok. Let me try to explain exactly how it's being done so far:

The layer l1 is drawn over the layer l2. Every layer have it's own attributes, i.e, xPosition, yPosition, width, height, and angle, so I must (I guess) apply the properly transformations in the modelview matrix before each draw.

As posted before, that's my perspective function, called before anything:



void setPerspective(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    // gluOrtho2D(0, w, h, 0); (the old guy)
    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 0.001, 5000.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    ... (transformations suggested by you)
}
 

And that's the mess with which my layer is drawn, working perfectly with ortho2D:


            glLoadIdentity();
            setPerspective(dst->width, dst->height);

               // Dest transformations
            glTranslatef(dst->cx, dst->cy, 0);  // cx = width/2   cy = height/2
            glRotatef(-dst->angle, 0, 0, 1);
            glTranslatef(-dst->cx, -dst->cy, 0);
            glTranslatef(-dst->x, -dst->y, 0.0f);

               // Source transformations
            glTranslatef(src->x, src->y, 0.0f);
            glTranslatef(src->cx, src->cy, 0);
            glRotatef(src->angle, 0, 0, 1);
            glTranslatef(-src->cx, -src->cy, 0);

            glBindTexture(GL_TEXTURE_2D, src->texID;

            glBegin(GL_QUADS);
            glTexCoord2f(0.0f, 1.0f);  glVertex2i(0,0);    
            glTexCoord2f(1.0f, 1.0f);  glVertex2i(src->width,0);  
            glTexCoord2f(1.0f, 0.0f);  glVertex2i(src->width,src->height);  
            glTexCoord2f(0.0f, 0.0f);  glVertex2i(0,src->height);
            glEnd();

            glBindTexture(GL_TEXTURE_2D, 0);
 

This topic is closed to new replies.

Advertisement