Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I have the following shaders which work (to the extent that they are completed anyway).

//Vertex Shader
uniform float offset;
void main()
    gl_TexCoord[0].t = gl_MultiTexCoord0.t;
    gl_TexCoord[0].s = gl_MultiTexCoord0.s + offset;

    vec4 vert = gl_Vertex; //does nothing atm
    //vec4 vert123  = (gl_ModelViewMatrix * vert); //problem code that should have no effect but instead stops my shader from using the offset
    gl_Position = vec4(gl_Vertex.x,gl_Vertex.y,-1,gl_Vertex.w);

//Fragment Shader
uniform sampler2D texture;
void main()
    vec4 TextureColor = texture2D(texture, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t));
    gl_FragColor = TextureColor;

Basically it draws a rectangle the size of the screen, centered on the screen but with offset on the x value of the texture. This gives me panoramic background scenery.

I would like to add some functionality so I can look up and down but I have the following problem:

As soon as I multiply something by gl_ModelViewMatrix, my offset stops working and I get a static background image. Literally, all I do is uncomment that line and my code breaks. No errors, and there are no shader compiler warnings and it still draws the image centered on the screen—but without the offset.

Am I blind or is that multiplication somehow being destructive?


Also replacing gl_ModelViewMatrix with gl_ModelViewProjectionMatrix or ftransform() all cause the same problem.

This also breaks it: mat3 modelview = gl_ModelViewProjectionMatrix;. So it seems that just accessing it causes things to stop working. I'm using these matrices in other shaders without problems though.

share|improve this question

put on hold as off-topic by Josh Petrie Dec 16 at 22:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

How are you setting the matrices? They don't just materialize out of thin air with the correct values for your application. –  Sean Middleditch Jun 12 '13 at 17:29
They're set on the api side with gluLookAt and glFrustum. Also some glRotatef and glTranslatef calls. –  slicedtoad Jun 12 '13 at 17:31
That tells us nothing of use. Your calls are probably wrong, hence your matrices are wrong, hence the matrix concatenation in the GPU produces the wrong results. Can't see why without that code. Sounds like this might be a bit localized for GDSE though, maybe better suited to chat or a forum site like gamedev.net. –  Sean Middleditch Jun 12 '13 at 17:44
@SeanMiddleditch Ok, I've found a workaround. I pass the matrix in as a uniform. The matrix is gotten from glGetFloatv(GL_MODELVIEW_MATRIX,modelview);. I'll come back to it later when I have time but I imagine the performance hit won't be too big, right? –  slicedtoad Jun 12 '13 at 18:34
Where are your #version declarations? –  Nicol Bolas Jun 12 '13 at 19:29

Browse other questions tagged or ask your own question.