Default color attribute

Started by
3 comments, last by Xeeynamo 11 years, 4 months ago
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;
}

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.

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!

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.
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 :)

This topic is closed to new replies.

Advertisement