user1607261
user1607261

Reputation: 402

Is there a difference between GLubyte and GL_UNSIGNED_BYTE?

I'm rendering an interleaved vbo using the following code which works fine.

    glVertexPointer(3, GL_FLOAT, sizeof(InterleavedVertexData), (GLvoid*)((char*)0));
    glNormalPointer(GL_FLOAT, sizeof(InterleavedVertexData), (GLvoid*)((char*)0+3*sizeof(GLfloat)));
    glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(InterleavedVertexData), (GLvoid*)((char*)0+6*sizeof(GL_UNSIGNED_BYTE)));

When I change glColorPointer's pointer paramater to use GLubyte i don't see anything rendered on the screen? I'm defining colour as GLubyte in my struct also.

    glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(InterleavedVertexData), (GLvoid*)((char*)0+6*sizeof(GLubyte)));

Upvotes: 2

Views: 9745

Answers (2)

tiguero
tiguero

Reputation: 11537

GL_UNSIGNED_BYTE is a symbolic const while GLubyte is a type. GLubyte is commonly implemented as a typedef of unsigned char; you can confirm this by looking at your gl.h.

You should use GL_UNSIGNED_BYTE inside your OpenGL method to specify the type of data you are passing along and use GLubyte to compute the size of your data.

Upvotes: 2

user149341
user149341

Reputation:

GLubyte is a type. GL_UNSIGNED_BYTE is an integer constant which is often used to indicate that you will pass a GLubyte in a pointer.

sizeof(GLubyte) is always 1 by definition. Taking sizeof(GL_UNSIGNED_BYTE) will typically return 4 or 8, because it's an integer constant, and has the size of whatever your system's integer size is.

Upvotes: 12

Related Questions