Dear Opengl Programmers,
I wanted to texture a quad using Pixel shaders. I have attempted to write the source code which is given below. My problem is Texture is getting mapped only when I disable the shader.
void init
//This is my texture initialization code
glClearColor(0.0f,0.0f,0.0f,0.0f);
//Checkered textured image from opengl redbook
makeCheckImages();
glGenTextures( 1, &tex1D);
glBindTexture(GL_TEXTURE_2D,tex1D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Sometimes setting these params
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // is REQUIRED for FBOs!!
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,checkImageHeight,0,GL_RGBA, GL_UNSIGNED_BYTE,checkImage);
glEnable(GL_TEXTURE_2D);
//This is my Render loop
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0,1.0,0.0);
glTranslatef(0.0f,0.0f,-7.0f);
glBindTexture(GL_TEXTURE_2D,tex1D);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f(-3.0f,-3.0f);
glTexCoord2f(0.0, 1.0);
glVertex2f(3.0f,-3.0f);
glTexCoord2f(1.0, 1.0);
glVertex2f(3.0,3.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(-3.0,3.0);
glEnd();
//a+=0.5;
glFlush();
glutSwapBuffers();
}
//In the nain
void main()
{
//Other app and shader initialization
//Passing the texture unit to shader
glUniform1i(getUniLoc(p, "tex1"), tex1D);
}
//my Vertex Program
varying vec2 texture_coordinate;
void main()
{
// gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
texture_coordinate = vec2(gl_MultiTexCoord0);
//gl_Position = ftransform();
}
//my fragment programm
uniform sampler2D tex1;
varying vec2 texture_coordinate;
void main()
{
gl_FragColor = texture2D(tex1, texture_coordinate);
}
I am new to GLSL.
Please help
RAJESH.R