Hello!
I'm starting to play around with OpenGL ES 2 and when trying to move an object in the Z coord it just either disappears or doesn't do anything.
It moves well in X and Y but not Z.
To move in Z I use the gl_Position.z in the shader.

The source of the project is in: http://cl.ly/24240x2D1t2A3I0c1l1P
It's a XCode project for iOS, the setup code can be found in EAGLView.m @ createFramebuffer, and the draw code can be found in TranslateSinZ.m @ drawView.

I believe the problem should be in the setup code but I can't figure out what's wrong...

Anyone can help me out?
Thank you!

11-30-2010, 04:45 AM

Xmas

Re: Problem when moving object in Z coord...

gl_Position is the position of the vertex in homogeneous clip space. Its Z component is only used for clipping against the near and far planes as well as for the depth test. It does not affect the position of the vertex in X and Y on screen.

I suspect that what you actually want is to translate the vertices in view space Z, before applying a projection transformation.

11-30-2010, 12:37 PM

lm2s

Re: Problem when moving object in Z coord...

I thought just changing the value in "gl_Position.z" would work since it works for "gl_Position.x" and "gl_Position.y".
So to translate the rectangle in Z, how can I achieve that?
"Translate the vertices in view space Z" can you explain in another fashion?
Thank you for your time.

04-23-2011, 03:44 AM

BKB

Re: Problem when moving object in Z coord...

Indeed, changing the value of gl_Position.z wont work because the rendered image is on a 2d plane with no depth :)

What you need to do is add back in the model, view and projection matrices that got deprecated in the move to programmable shaders, so my vertex shader looks a little something like:

Here, translations and rotations for a given model are loaded into the model matrix, m_model , the camera setup is loaded into the view matrix, m_view and the projection (ortho or perspective) is loaded into the projection matrix m_projection .