Shader giving purple color

Started by
10 comments, last by CirdanValen 12 years, 3 months ago
More problems, and no errors in the infologs.


Really banging my head against the desk with this problem. Been stabing around, tirelessly searching google, trying every combination possible...and I just can't get this to work.

I am rendering sprites to a Framebuffer. I know this is working perfectly fine because I can render out the framebuffer and see exactly what I drew to it. I want to pass this fbo texture to a shader, so I can eventually do light calculations. For what ever reason, it just will not work for me at all. I am following what various tutorials and sample code has told me, but it just will not work. >:(. My shader is compiling and linking without errors. I can set the gl_fragcolor to a color in the shader with great success. It's using the texture that is giving me problems. Right now, when I set gl_fragcolor to the texture, I get a dark gray color.

Vertex shader:
#version 120

varying vec4 texCoord;

void main()
{
texCoord = gl_MultiTexCoord0;
gl_Position = ftransform();

}


Fragment shader
#version 120

uniform sampler2D diffuseMap;
uniform sampler2D lightingMap;

varying vec4 texCoord;

void main()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].st);
vec4 light = texture2D(lightingMap, texCoord.st);

gl_FragColor = color;
}


How I'm using the shader.
graphics->useShader(mLightingCombinedShader);
mLightingCombinedShader->setUniformTexture("diffuseMap", mDiffuse->getTextureId());
graphics->drawPrimitive(mScreenRect, 0, 0);
graphics->clearShader();


And the relavant code:



void ShaderProgram::setUniformTexture(const std::string& name, GLuint t) {
GLint var = getUniformLocation(name);
glActiveTexture(GL_TEXTURE0 + ShaderProgram::mTextureUnits);
glBindTexture(GL_TEXTURE_2D, t);
glUniform1i(var, ShaderProgram::mTextureUnits);
}

void GraphicsDevice::useShader(ShaderProgram* p) {
glUseProgram(p->getId());
}

void GraphicsDevice::clearShader() {
glUseProgram(0);
}

void GraphicsDevice::drawPrimitive(Primitive *p, float x, float y) {
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, p->getVbo());

glPushMatrix();

glTranslatef(x, y, 0.f);

glVertexPointer(2, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, x));
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, tx));

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glPopMatrix();

glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);

}

Advertisement
You are only enabling vertices with glEnableClientState(GL_VERTEX_ARRAY); but you are not enabling texcoords.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Aha! Such a basic fix sleep.png . I am stoked I was able to get this working. Really appreciate your help!

This topic is closed to new replies.

Advertisement