Jump to content
  • Advertisement
Sign in to follow this  
Xeeynamo

OpenGL Default color attribute

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

Hi,
I'm converting my application from using OpenGL 2.0 to OpenGL 3.0. I was using glVertexPointer, glTexCoordPointer and glColorPointer to send the vertices to the GPU and when I doesn't need of Color, I simply disabled it with glDisableClientState(GL_TEXTURE_COORD_ARRAY), so the GPU set gl_Color from vertex shader is white by default. 
Now I'm using glDisableVertexAttribArray to disable the vertices and glVertexAttribPointer to send stuff and now comes the problem. glDisableVertexAttribArray(COLOR) set black the color by default in vertex shader! Now I won't fill all the vertices of 1.0f and force to enable the color, so I'm asking you if there is a way to not send the color where it doesn't required without to use particular tricks (like to create a fragment shader for color stuff and another fragment shader to the texture-only stuff).
 
My shaders looks like this:
#version 330 core
varying vec3 texcoord;
varying vec4 vertex_color;
in  vec4 in_Position;
in  vec4 in_Color;
in  vec4 in_Texture;

void main()
{
	gl_Position = in_Position;
	texcoord = in_Texture;
	vertex_color = in_Color;
}
#version 330 core
uniform sampler3D texture
varying vec3 texcoord;
varying vec4 vertex_color;

void main()
{
	vec4 precolor = texture3D(texture, texcoord);
	precolor *= vertex_color;
	gl_FragColor = precolor;
}

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Use one of the glVertexAttrib-variants to set the default attribute state. If an attribute array is disabled, the corresponding default attribute is used instead.

Share this post


Link to post
Share on other sites
Use one of the glVertexAttrib-variants to set the default attribute state. If an attribute array is disabled, the corresponding default attribute is used instead.

Haha that's it? It works fine :D thank you!

Share this post


Link to post
Share on other sites

If you are using version 330 you should be doing some things a bit differently in GLSL:

 

- Use "in" and "out" instead of "varying" and "attribute"

- Use layout(location=X) to specify the index to bind the attribute to

- Use a custom output instead of gl_FragColor

 

Also just so you know, GL 3.0+ is still not very widely supported. If you are targeting a casual market, you may want to stick with 2.0 as your target. In one thread it was listed that as few as 51% of Minecraft users supports GL 3.0+. It really comes down to what you need; GL 2 is a fine target for most purposes and can be used in almost the same way as the 3+ programmable pipeline. Many drivers will support geometry shaders, FBOs, float textures, etc. through extensions.

Share this post


Link to post
Share on other sites
If you are using version 330 you should be doing some things a bit differently in GLSL:

 

- Use "in" and "out" instead of "varying" and "attribute"

- Use layout(location=X) to specify the index to bind the attribute to

- Use a custom output instead of gl_FragColor

 

Also just so you know, GL 3.0+ is still not very widely supported. If you are targeting a casual market, you may want to stick with 2.0 as your target. In one thread it was listed that as few as 51% of Minecraft users supports GL 3.0+. It really comes down to what you need; GL 2 is a fine target for most purposes and can be used in almost the same way as the 3+ programmable pipeline. Many drivers will support geometry shaders, FBOs, float textures, etc. through extensions.

 

Yes, my laptop with a Intel Atom Z supports only OpenGL 2.1. My real goal is to have a multi-platform framework, with OpenGL 2.1/3.0+/ES1.0/ES2.0 and probably also DirectX 11 for W8 and WP8. OpenGL 3.0 offers great improvements and cool stuff (one of these things that I wanted is "rendering to texture") but I'm not excluding the old platforms :)

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!