Jump to content
  • Advertisement
Sign in to follow this  
jeff8j

GLSL frag shader position not set

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

I created a shader in shader maker it works great when I go to add it into my program it wasnt working and I believe to have narrowed it down to the position is not being set I use this to set my position

vec4 position = gl_TexCoord[0];

and I just copied shader makers vertex

// simple vertex shader

void main()
{
	gl_Position    = gl_ModelViewProjectionMatrix * gl_Vertex;
	gl_FrontColor  = gl_Color;
	gl_TexCoord[0] = gl_MultiTexCoord0;
}

I can manually set the gl_FragColor and that works just fine the rectangles color will change

I dont know if there is something that I have to enable or initialize for gl_Texcoord does someone know what I am missing or doing wrong?

I am using c on linux glx window gl 3.3 Thanks

Share this post


Link to post
Share on other sites
Advertisement

I created this simpler frag shader to help visualize and narrow down the issue

// fragment shader

vec4 position = gl_TexCoord[0];


void main(){

	// Calculate distance to center
	float d = distance(position.xy, vec2(0.5, 0.5));

	vec3 color = vec3(0.0,0.0,0.0);

	color += d;
	gl_FragColor = vec4(color, 1.0);

}

Heres how shader maker looks versus my program the shader maker one is the circle

 

Share this post


Link to post
Share on other sites

why dont you remove


vec4 position = gl_TexCoord[0];

and don't use directly your coordinates? anyway I would move the above line in the main function?

I am just guessing never used shader maker etc, but maybe shader maker is doing some extra step for you that in your stand alone case doesn't happen?

I have a feeling that your position get set once and never computed again, thus the uniform  color

Share this post


Link to post
Share on other sites

I set a position because its different on gles so I have a if gles do this else do what its doing now

 

I have changed it to not include that but it doesnt change the output :(

// fragment shader


void main(){

	// Calculate distance to center
	float d = distance(gl_TexCoord[0].xy, vec2(0.5, 0.5));

	vec3 color = vec3(0.0,0.0,0.0);

	color += d;
	gl_FragColor = vec4(color, 1.0);

}

Its still the same uniform grey

Share this post


Link to post
Share on other sites

I dont have a texture so I guess I'm not that must be what im missing what would I use to upload the coordinates?

Share this post


Link to post
Share on other sites

My vertex shader has gl_position

gl_Position    = gl_ModelViewProjectionMatrix * gl_Vertex;

Is that the same thing I am looking for can I use it instead of texture coordinates?

Share this post


Link to post
Share on other sites

My vertex shader has gl_position
gl_Position    = gl_ModelViewProjectionMatrix * gl_Vertex;
Is that the same thing I am looking for can I use it instead of texture coordinates?


I'm going to assume that you are sending vertices to the shader GPU and that those vertices include UV coordinates. Am I correct?

Edited by MarkS

Share this post


Link to post
Share on other sites

Your assuming a bit too much lol

This is my first shader program my only otheer opengl experience has been 1.5 fixed function and even that was limited experience

 

I was following this tutorial

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/

 

got it working got a shader working with colors and took my shader from shader maker and must have jumped some steps I figured since I am not using a texture I didnt need all that

 

I will look into the textured tutorial and learn some more and see about uv coordinates

Share this post


Link to post
Share on other sites

Shaders are not magical bits of code that make things appear on screen. You still must send geometry to the GPU. If you are not sending geometry, what does the shader have to work on? UV (texture) coordinates are required for the shader code you posted, along with standard x/y/z coordinates.

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!