Jump to content

  • Log In with Google      Sign In   
  • Create Account


[Solved] Basics, passing color through a vertex shader.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 11 May 2013 - 03:06 PM

Hey everyone, I'm having a bit of an issue with shader's in JOGL 2 for Java (JRE 1.7) and I'm hoping you can help. I have an interleaved and un-indexed VBO containing 3 floats per position axis and 3 floats per colour component, I'm able to draw 4 quads absolutely fine if I use the traditional methods for setting up the projection matrix (i.e. glMatrixMode, glLoadIdentity, glOrtho2D). 

When I switch to using my own shader however everything draws fine projection wise, but I am unable to figure out how to pass the vertex colour from vert to frag shaders. So far I have tried various combinations switching between varying and in/out statements to no avail, I am sure I am just missing some syntactical knowledge here and would appreciate if someone could point me in the right direction.

 

Here is the fragment shader I am using:

 

in vec3 diffuse;

void main() {
    gl_FragColor = vec4(diffuse, 1.0);
}

 

 

And here is the vertex shader I am using:

 

uniform mat4 projMatrix;

in vec3 position;
in vec3 color;

out vec3 diffuse;

void main() {
    gl_Position = projMatrix * vec4(position.xyz, 1.0);
    diffuse = vec3(1,1,1);
    // diffuse = color;
}

 

 

Notice the commented out line of code, if I uncomment it and remove the line above the quads I am drawing change from opaque white to transparent (I've made sure by changing the background clear colour). Again I am sure this is just a lack of knowledge on my part but I've been going crazy trying to solve this all day so thanks in advance to anyone who can help me out.

 

 

Aimee


We are now on Tumblr, so please come and check out our site! 

 

http://xpod-games.com


Sponsor:

#2 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 12 May 2013 - 07:51 AM

Solved it, problem was that I forgot to use gl_Color the correct way, here is my modified vertex shader:

niform mat4 projMatrix;
in vec3 position;
out vec4 diffuse;

void main() {
	diffuse = gl_Color;
    gl_Position = projMatrix * vec4(position, 1.0);
}

 

and the matching frag shader:

in vec4 diffuse;

void main() {
    gl_FragColor = diffuse;
}

 

Also I was getting the zNear and zFar variables in my orthographic projection calculation the wrong way round, it's funny what a lack of sleep can do to the brain lol.

 

Aimee


We are now on Tumblr, so please come and check out our site! 

 

http://xpod-games.com





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS