Hey…
I’m trying to create a simple shader that applies a texture onto a plane surface… I’ve verified that the shader is compiled and linked correctly (and works as expected in ShaderDesigner).
I think my problem is using the glUniform1iARB funktion, or simply transfering the data correctly.
It seem like the texture data is read as zero in the shader.
void setShader()
{
// compile and link shader (works correctly)
//
int error;
textureLocation = glGetUniformLocationARB(shaderProgram, "texture");
error = glGetError();
// Init texture data
GLubyte *pTexture = new GLubyte[TEXTURE_HEIGHT*TEXTURE_WIDTH*3];
// Init texture
for(int i=0; i<TEXTURE_WIDTH*TEXTURE_HEIGHT; i++) {
pTexture[i*3] = 0; // R
pTexture[i*3+1] = 255; // G
pTexture[i*3+2] = 255; // B
}
// Create and Bind texture on Graphics Card
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); // Binds the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, pTexture); // inits the texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
delete pTexture;
}
int DrawGLScene(GLvoid)
{
enableShader(); // Enables my shader
if(textureLocation != -1) // check if variable exists in linket shader program
glUniform1iARB(textureLocation, texture);
glPushMatrix();
glTranslatef(-1.2f,0.0f,0.0f); // Move to the left
glBegin(GL_QUADS); // Draw A Quad
glTexCoord2f( 0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f( 0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f( 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f( 1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glPopMatrix();
disableShaders();
return TRUE;
}
// VS
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
// FS
uniform sampler2D texture;
void main()
{
vec4 texelColor0 = texture2D(texture, gl_TexCoord[0].xy);
gl_FragColor = texelColor0;
}
Can anybody help me with this (maybe simple problem)… Oh, my graphics card is an ATI X600 Mobility
Thanks
BBliksed