Materials in Shaders

Started by
0 comments, last by Geometrian 15 years, 5 months ago
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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
In a very simple example, when using this shader:
//vertex shadervoid main() {    gl_Position = ftransform(); }//fragment shadervoid main() {    gl_FragColor = gl_FrontMaterial.specular;}
I get a red object. But when using this shader:
//vertex shadervoid main() {    gl_Position = ftransform(); }//fragment shadervoid 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]

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement