PDA

View Full Version : Switching 2D to 3D in OpenGL ES project



openglesuser
09-04-2008, 07:08 PM
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. 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?
glEnable(GL_DEPTH_TEST); ?
glDepthFunc(GL_LEQUAL); ?

glClear(GL_DEPTH_BUFFER_BIT); ?

here's the basic texture drawing code:
glBindTexture(GL_TEXTURE_2D, _name);
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?

Thanks.

openglesuser
09-05-2008, 01:19 PM
Here's what I ended up with so if anyone else has this same problem. Also if anyone has a refinement or alternate please post.


No need to enable depth buffers since I was sorting them. I offset the viewpoint and not the texture maps.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

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

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

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.