PDA

View Full Version : simple texturing shader not working...Black Screen



abhishek bansal
06-18-2011, 02:49 AM
Hello All....

I am quit new to GLSL and trying to map a single texture through shaders...but all i get is a Black Screen in front of me...i googled a lot and compared my program to others..but no luck..!!!
my vertex shader


void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

here is the fragment shader........


uniform sampler2D sand;
void main()
{
gl_FragColor = texture2D(sand,gl_TexCoord[0].st);
//gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}


noe intresting thing is that both shaders are compiled and linked with no errors and when I try to give simple color in fragment shader it works...(line 2)

this is my init() function..


glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
textures[0]=loadTexture("sand.jpg");
multiTex.abCreate();
multiTex.abCompileAndLink();
multiTex.abSetUniformTexture("sand",textures[0]);


here is render function....


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,textures[0]);
multiTex.abSetUniformTexture("sand",textures[0]);
multiTex.abUseProgram();

glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0); glVertex3f(-10.0,-10.0,0.0);
glTexCoord2f(1.0,0.0); glVertex3f(10.0,-10.0,0.0);
glTexCoord2f(1.0,1.0); glVertex3f(10.0,10.0,0.0);
glTexCoord2f(0.0,1.0); glVertex3f(-10.0,10.0,0.0);
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();

it is the function in which i am setting my uniform variable..


glUseProgram(programID);
GLint parameterLocation = glGetUniformLocation(programID, name);
glUniform1i(parameterLocation, unit);
glUseProgram(0);

also texture is working without shaders....
plz help guys it is so frustating....!!!!

vivek vyas
06-18-2011, 10:11 AM
I am not sure for your solution but you can use nVidia Cg.
It supports wide varierty of shaders.
and I think that black screen is due
glClearColor(0,0,0,0); by default
try use this with other parameters and no more black screen.

abhishek bansal
06-18-2011, 10:34 AM
I am not sure for your solution but you can use nVidia Cg.
It supports wide varierty of shaders.
and I think that black screen is due
glClearColor(0,0,0,0); by default
try use this with other parameters and no more black screen.
i am sorry byt by black screen i meant that no geometric primitive is rendered....glClearColor() i knw...

I am not sure for your solution but you can use nVidia Cg.
It supports wide varierty of shaders.

no offense but i thought GLSL has wider support on ATI and Nvidia cards because only basic Cg profiles are supported on ATI Cards....and GLSL shaders do work for me...only in this program they are not working and that too for texture only...if i provide constant color in fragment shader (as line 2 in main function) the shader works perfectly as expected....

abhishek bansal
06-18-2011, 10:57 AM
thank you guys...
I was supplying texture object to shader instead of texture unit..problem solved..