Sign in to follow this  
nekx

glVertexAttribPointer and gl_Normal

Recommended Posts

nekx    100
I'm trying to pass some normals to a shader written in GLSL using glVertexAttribPointer but I can't seem to get it working. I read that vertex positions should be at index 0 and normals at 2. It works fine with vertex positions. glVertexAttribPointer(0, 3, GL_FLOAT, ...) But it doesn't work when I try to use it with my vertex normals. glVertexAttribPointer(2, 3, GL_FLOAT, ...) If I just use the deprecated glNormalPointer gl_Normal is populated with my normals in the shader as it should. Likewise if I bind index 2 to a custom value called in_Normal that variable is filled with the expected value. Therefore it can't be something with my normal array. Thanks in advance.

Share this post


Link to post
Share on other sites
bubu LV    1436
Quote:
Original post by nekx
Likewise if I bind index 2 to a custom value called in_Normal that variable is filled with the expected value.

This is correct way how to use glVertexAttribPointer.
GL driver can assign any attribute index to vertex attribute.

Share this post


Link to post
Share on other sites
nekx    100
Thanks for your answers.

Is there any way I can use glVertexAttribPointer to fill the gl_Normal value? Using a custom variable like in_Normal works but I'd like to just use the standard variable.

Share this post


Link to post
Share on other sites
skydave    128
Same here. Is it possible to treat built in attributes like generic ones? means can I fill built in attributes like normals/colors etc. withglVertexAttribPointer ?

cheers,
dave

Share this post


Link to post
Share on other sites
karwosts    840
Quote:

Is there any way I can use glVertexAttribPointer to fill the gl_Normal value? Using a custom variable like in_Normal works but I'd like to just use the standard variable.



I'm not sure if this is technically possible, but gl_Normal is not really "the standard variable" anymore, its depreciated and as such you've got no reason to use it.

As bubu said, the proper and forward-looking technique is to define your own variables for all attributes.



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this