My problem is that I have a (working) spelling vertex and a couple of fragment shaders that allow me to specify the center X and Y of the sprite through the transmitted forms "translateX" and "translateY". I multiply by the projection matrix, which is hard-coded and works great. Everything works before the spelling operation. My input geometry for this shader is based on 0, 0, 0 as the center point.
Now I want to find out exactly which point of the center (0, 0, 0 in the local coordinate space) becomes after translations. I need to know this information in the fragment shader. I suggested that I can create a vector at 0, 0, 0, and then apply the same translations. However, I am NOT getting the correct answer.
My question is: what am I doing wrong, and how can I debug what is happening? I know that the calculated value must be wrong, but I donβt understand what it is. (My Xcode 4.2 platform for OS X for OpenGL ES 2.0 iOS)
Here is my vertex shader:
// Vertex Shader for pixel-accurate rendering attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; uniform float translateX; uniform float translateY; // Set up orthographic projection // this is for 640 x 960 mat4 projectionMatrix = mat4( 2.0/960.0, 0.0, 0.0, -1.0, 0.0, 2.0/640.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0); void main() { // Set position gl_Position = a_position; // Translate by the uniforms for offsetting gl_Position.x += translateX; gl_Position.y += translateY; // Translate gl_Position *= projectionMatrix; // Do all the same translations to a vector with origin at 0,0,0 vec4 toPass = vec4(0, 0, 0, 1); // initialize. doesn't matter if w is 1 or 0 toPass.x += translateX; toPass.y += translateY; toPass *= projectionMatrix; // this SHOULD pass the computed value to my fragment shader. // unfortunately, whatever value is sent, isn't right. //v_translatedOrigin = toPass; // instead, I use this as a workaround, since I do know the correct values for my // situation. of course this is hardcoded and is terrible. v_translatedOrigin = vec4(500.0, 200.0, 0.0, 0.0); }
EDIT: In response to my spelling matrix incorrectly, the following: wikipedia should say about orthoprojections, and my -1 looks right. because in my case, for example, the 4th element of my mat should be - ((right + left) / (right-left)), which has a right of 960 to the left of 0, therefore -1 * (960/960), which is -1.
EDIT: I may have uncovered a root problem here - what do you think?
