I have a working project of 2D texturemaps.
Using glOrthof(0, 320 ,0, 480 , -1.0f, 1.0f); everything is fine and works as desired.
I’d now like to be able to rotate some of the textures in x and y axis (flipping them on screen). (I’m already using the z-axis rotation)
Of course this requires perspective since the ortho is crushing everything. (x and y rotations just show the images as a bar)
If I switch out glOrthof and replace it with glFrustumf then no images show up.
I’ve probably have been working so long I’m overlooking something obvious. It’s been awhile since I’ve used OpenGL for 3D.
Not planning to turn it into a full 3D model, just to be able to flip some flat images.
I’ve tried different far/near parameters.
Do I need to:
setup depth buffers?
here’s the basic texture drawing code:
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
Do I need to supply a different value for z (other than 0) in the texturemap vertices?
You don’t need to set up the depth buffer if you know in which order the objects should be drawn. You need a projection matrix that is equivalent to your orthoprojection at the Z-plane you are using. I assume it’s Z=0, though I wonder why you’re using 3-component vertex data.
The exact values to use for glFrustumf depend on what field-of-view angle you want and the depth of the largest object you want to rotate (the view volume needs to be big enough so objects don’t get clipped by the near and far planes). Then you need to add a translation to center the view volume on (160, 240, 0).
Thanks. I’ll give it a try.
I ended up doing a translation as you suggested - I reversed the offsets and added a Z axis offset as well with experimentation
gluPerspective(60, (GLfloat)320.0f/480.0f, 0.5f, 1500.0f);
// routine I found on web which calculates glFrustumf as:
// glFrustumf (-.1924, .1924, -.2886, 0.5f, 1500.0f);
glTranslatef(-160, -240,-430); // correctly center
I would assume there’s a math formula to get the correct Z distance to match the default ortho
but I haven’t looked into it yet.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.