views:

850

answers:

1

In OpenGL ES 2.0, you apparently can't do

 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

any more to set the model matrix, but I think these matrices are still built in somehow, since the GLSL spec tells you how to access them in a vertex shader.

// 
// Matrix state. p. 31, 32, 37, 39, 40. 
// 
uniform mat4  gl_ModelViewMatrix; 
uniform mat4  gl_ProjectionMatrix; 
uniform mat4  gl_ModelViewProjectionMatrix;

so how do I pass these values to my shader? do I use glUniformMatrix4fv somehow?

The source code from the OpenGL ES 2.0 Programming Guide has been helpful for the shader part but all the examples appear to just leave the matrix transforms alone and just make sure their vertices are between -1.0 and 1.0.

UPDATE: apparently the OpenGL ES Shader Language does not support the pre-defined entries like gl_ModelViewMatrix, so the only answer is to define your own custom model/view/projection matrices as done in the code linked below, using glGetUniformLocation and glUniformMatrix4fv. I was confused because the OpenGL Shader Builder does support them, but that's plain OpenGL, not OpenGL ES.

+1  A: 

According to his comment, this link gave enough information to fix his problem.

Mark Thalman
I don't want to use the fixed function pipeline. I definitely can keep using OpenGL ES 1.1 if I wanted to, but I'm trying to experiment with vertex and fragment shaders.
David Maymudes
Sorry I can't be of more help. You might try looking for updated sample code from Apple.I don't know if this sample code will be helpful or not.http://mgrundmann.com/2009/06/24/simple-opengl-es-20-iphone-example/
Mark Thalman
Thanks for the link! He solves this by defining his own shader variable for the model and projection matrices (i.e. defining his own names for them, then using glUniform to update values) rather than using the built-in ones. Perhaps they're not built-in at all in the iPhone version of OpenGL ES 2.0. In any case, this is enough of a workaround to let me write some code that works...
David Maymudes
I appreciate the persistence--edited my question so that it better matches your answer! :-)
David Maymudes