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?

edit:

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
1  
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
3  
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
1  
@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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.