For some functions in OpenGL, one must specify a byte offset, such as in glVertexAttribPointer()
, for stride. At first I would have guessed that it would be a normal number value like an integer. But upon inspection, I realized that it needs to be casted to void*
(more specifically GLvoid*
). My question is: what is the intended meaning of void*
and why must it be used for a byte offset?
Void as a Function Return TypeThe void function accomplishes its task and then returns control to the caller. The void function call is a stand-alone statement. For example, a function that prints a message doesn't return a value. The code in C++ takes the form: void printmessage ( )
param has type void * , which in C serves as a "generic" pointer type; any object pointer type can be converted to void * and vice versa without need for an explicit cast (some implementations allow function pointer types to be converted to void * , but that's not universal and not guaranteed by the language standard).
When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."
glVertexAttribPointer() is an older function from before Vertex Buffer Objects.
Before VBO's your vertex data would be stored in client side arrays and you would need to pass a pointer to the data to OpenGL before you could draw.
When VBO's came along they repurposed this function by allowing the pointer to be used to pass an integer offset.
e.g.
void* offset = (void*)offsetof(vertexStructName, vertexMemberName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With