Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Materials in Shaders

This topic is 3554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm making a program, and I'm getting a strange bug when rendering a material with this shader (http://www.lighthouse3d.com/opengl/glsl/index.php?pointlight). It runs, but strangely, the ambient and diffuse aspects of the colors aren't being accessed correctly. I set the material every frame, like so:
#This should make a gold color with a weak specular highlight.
glMaterialfv(GL_FRONT,GL_AMBIENT,(0.2,0.2,0.2,1.0))
glMaterialfv(GL_FRONT,GL_DIFFUSE,(0.8,0.8,0.4,1.0))
glMaterialfv(GL_FRONT,GL_SPECULAR,(1,1,1,1))
glMaterialfv(GL_FRONT,GL_EMISSION,(0,0,0,1))
glMaterialfv(GL_FRONT,GL_SHININESS,128)
If I set the material and then use the shader with only specular, I see the specular highlights using the material parameters rendered correctly, and nothing else. This is the expected behavior. However, if I set the material and then use the shader with only ambient and/or only diffuse, the ambient and diffuse material properties aren't used--instead, both are (1,1,1,1). In shader jargon, I can change gl_FrontMaterial.specular and gl_FrontMaterial.shininess, but I can't change gl_FrontMaterial.ambient or gl_FrontMaterial.diffuse. This is a very strange error, and I want to know how to fix it. Thank you, -Geometrian

Share this post


Link to post
Share on other sites
Advertisement
In a very simple example, when using this shader:
//vertex shader
void main() {
gl_Position = ftransform();
}
//fragment shader
void main() {
gl_FragColor = gl_FrontMaterial.specular;
}
I get a red object. But when using this shader:
//vertex shader
void main() {
gl_Position = ftransform();
}
//fragment shader
void main() {
gl_FragColor = gl_FrontMaterial.ambient;
}
I get a white object. I set the materials for this like this
glMaterialfv(GL_FRONT,GL_SPECULAR,(1,0,0,1))
glMaterialfv(GL_FRONT,GL_AMBIENT,(1,0,0,1))


[EDIT: more specific problem continues here: http://www.gamedev.net/community/forums/topic.asp?topic_id=512598]

[Edited by - Geometrian on October 25, 2008 1:31:46 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!