GLSL shaders acting weird

Started by
25 comments, last by adam17 18 years, 9 months ago
btw u dont need to enable textures (thats only for the fixed pipeline)

so this is your fragment shader

uniform sampler2d tex0;
uniform sampler2d tex1;

void main(void)
{
gl_FragColor = vec4( texture2D( tex0, gl_TexCoord[0].xy ) );
}

this should draw texture0 now change the tex0 to tex1 and it should draw texture1 if it does both of those then it should work (youre setting them up correctly)
so u should be able to go
gl_FragColor = vec4( texture2D( tex0, gl_TexCoord[0].xy ) * texture2D( tex1, gl_TexCoord[0].xy ) );
if not then i dont know whats up, try shaderdesigner do the examples there work?

Advertisement
ok here are my two shaders

vertex
uniform sampler2D texture0, texture1;void main(){	gl_Position = ftransform();	gl_TexCoord[0] = gl_MultiTexCoord0;}


fragment
uniform sampler2D texture0, texture1;uniform float alpha;void main(){	vec4 tex1 = texture2D(texture0, gl_TexCoord[0].st);	vec4 tex2 = texture2D(texture1, gl_TexCoord[0].st);			gl_FragColor = tex2;}

setting gl_FragColor to either tex1 or tex2, i get the same exact output. now when i multiply or add the two textures, i get the correct output with the two different textures. i tried the shaders in shader designer and my program and the exact same thing happens
so youre saying theres visually no difference between

uniform sampler2D texture0, texture1;
void main()
{
vec4 tex1 = texture2D(texture0, gl_TexCoord[0].st);
vec4 tex2 = texture2D(texture1, gl_TexCoord[0].st);

gl_FragColor = tex2;
}

and

uniform sampler2D texture0, texture1;
void main()
{
vec4 tex1 = texture2D(texture0, gl_TexCoord[0].st);
vec4 tex2 = texture2D(texture1, gl_TexCoord[0].st);

gl_FragColor = tex1;
}

if thats the case youre buggered (if u want send me a testapp + ill run it and see whats wrong, billybolluxbouncingballs (at) yahoo.co.uk
i have discovered a big chunk of my problem. whenever i render my model there were a bunch of calls to opengl inside of the draw function. i was enabling GL_TEXTURE_2D, setting certain colors and a bunch of other "idiot proofing" i had set in place. apparently it only made me look like more of an idiot. my model was only setup for using a single texture unit and not multiple units.
For all OpenGL-related problems, first thing you should do is use GLIntercept.
You can get it to break on invalid arguments, you can see the textures actually bound when the stuff get's rendered etc etc. Really a great tool. :)
With that tool you should be able to find any other bugs you have...

Good luck!
woohoo!!! i ordered the orange book and its been interesting. at the same time ive been debugging my program still. i discovered if i pass a simple float value like 0.0 or 0.25 or 1.0 the shader runs correctly. if i pass it a float variable with a non-changing value it still displays correctly. at the moment i start changing the value i get a black model. if you dont want to look back at the code ill give it briefly.

i have a uniform value in the shader to change the intensity of a texture. it doesnt change between glBegin and glEnd, only before glBegin.
WOW i feel like an idiot now. i solved the problem. whenever i made changes to the alpha value, the program wasnt active. all i had to do was

glUseProgram(glslContext);
glUniform....
//draw object
glUseProgram(0);

This topic is closed to new replies.

Advertisement