Jump to content
  • Advertisement
Sign in to follow this  
Shawn619

OpenGL Model turns all black in shader

This topic is 1925 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

In both Rendermonkey and Shaderdesigner programs used for testing glsl shading, I get a complete black model while I'm trying to learn and test different shaders. Image: http://oi46.tinypic.com/dpg6mu.jpg This image shows the black model in Shaderdesigner, with the following vertex and fragment files:
Vert:

out vec4 color; void main(void)

{

  color = gl_Color;

  vec4 v = vec4(gl_Vertex); 

  v.z = sin(5.0*v.x )*0.25;

 

  gl_Position = gl_ModelViewProjectionMatrix * v;

}

 

Frag:

in vec4 color;

void main()

{

gl_FragColor = color;

}

 

What I think is happening, is the shaderdesigner is send the gl_Color from the opengl application to the shader with a black value, and I have no clue how to change that value. I have tried messing around with ALL the menus, options, anything relates to changing color and nothing is working. Why is my model black and how can I fix it?

Share this post


Link to post
Share on other sites
Advertisement

If its for testing purpose only, why don't you just hard-code the value for gl_Color (or give it some initial value other than 0.0f)? Having one single color supplied to a mesh is not such a huge feature in game developement (as far as I'm concerned) that you do not necessary need to know how to change that. If setting gl_Color in the shader doesn't help, you at least know there is a problem somewhere else.

 

EDIT: not that there is anything wrong with you wanting to know that, just so you don't have to wait for hours until someone answers but can go on in the meanwhile ^^

Edited by Juliean

Share this post


Link to post
Share on other sites

Thanks!

Yeah, using a constant color works fine, but I would still like to know how to change gl_Color's default value of black.

Share this post


Link to post
Share on other sites

I don't know that you can change the default color from black.. maybe using glColor call in your app.. but why not just make a uniform in your fragment shader to set the color how you want.. you can use the format like this in your fragment shader...

 

 

uniform vec4 customColor;

 

 

 

and then in your code set the uniform with gl calls...

 

 

Vec4Df colorVec = (1.0f,0.0f,0.0f,1.0f); // red
GLuint varIndex = glGetUniformLocation( progID, customColor);  // where progID is the GLuint program ID given to your shader when you compiled it
glUniform4fv(varIndex, 1, colorVec);

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!