Skip to main content
GameDev.net gamedev.net
🔒 Locked

Default value for attributes

Started by k.pedersen Apr 13, 2012 at 10:02 AM 1 replies 1.8k views
Original Post
k.pedersen
k.pedersen
Hello,

Just checking if a function like glVertexAttrib3f() is meant to set the default value for an in attribute for a shader.

For example, if I am drawing a cube which doesnt actually have texture coordinates but my shader usually supports them, would I have to have multiple shaders or could I do something like the following...


glVertexAttrib3f(inTexCoords, 1, 2, 3);


And expect the attribute in my shader to have the vec3 value of 1, 2, 3?

So far it just seems to not draw anything, so I am wondering if this is correct functionaility or if I have a bug somewhere...

Cheers,

Karsten
Wavefront Animation Studio - Create simple animations for .obj 3D models.
libwavefront - Open-source C++/OpenGL library to load animated .obj models.
Lichtso
Lichtso
Hi,

I don't know anything about a function which can set a default value for the attributes.
But I know that, if no attribute is set, the values are 0 by default and if you want to disable single attributes, the best way to do this is using a uniform variable.
Also, to use VBOs is recommended so the function call should be:

void glVertexAttribPointer( GLuint index,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid * pointer);
tanzanite7
tanzanite7

glVertexAttrib3f(inTexCoords, 1, 2, 3);
And expect the attribute in my shader to have the vec3 value of 1, 2, 3?

Yes. I use them as per-draw call constants (the rest of the attributes are sourced from vertex buffers) for example (instead of uniforms). In that use they are commonly called "dangling attributes".

Edit: Oh, and no - you do not need to set a default value. Every vertex attribute has already a default value (all 0 most likely, or whatever else it was explicitly set to).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.