开发者

GLSL Fragment Shader texturing a cylinder, just getting gray?

Ok, trying to debug another problem I have, I decided to make sure my texture was rendering properly in my fragment shader. But, it doesn't. All I get is a gray color across my whole cylinder. If I comment out "setShaders()" the texture is applied properly in the fixed function pipeline.

All I'm doing in my fragment shader is assigning the texture value to the fragment color. It should work, right? I swear I've got开发者_JAVA技巧 all the pieces in place. grr

Here's the code before I draw my cylinder:

vertexShader = "fish.vert";
fragmentShader = "fish.frag";

glBindTexture(GL_TEXTURE_2D, checkerTexture);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

setShaders();

GLint loc1;
loc1 = glGetUniformLocation(shaderProgram,"fish_y_offset");
glUniform1i(loc1,0);    

glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
glLightfv(GL_LIGHT0, GL_AMBIENT, white);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_SPECULAR, white);
glMaterialfv(GL_FRONT, GL_SHININESS, highShine);

drawCylinder();

And here is my fish fragment shader:

uniform float spec_factor;
uniform sampler2D fish_y_offset;

varying vec3 lightDir,normal;
varying vec4 mycolor;
void main()
{
    float angle, shiny;
    angle = max(0.0, dot(normal, lightDir));


    shiny = pow(angle, gl_FrontMaterial.shininess);

    gl_FragColor = texture2D(fish_y_offset, gl_TexCoord[0].st);


    //gl_Color;//(gl_LightSource[0].ambient * gl_FrontMaterial.ambient +
                    //gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * angle +
                    //gl_LightSource[0].specular * gl_FrontMaterial.specular * shiny * spec_factor);

}


put

gl_TexCoord[0] = gl_MultiTexCoord0;

in the vertex shader to fix.

man i have a lot to learn about glsl....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜