Reputation: 625
I was playing around with gl-rs
and in the original opengl tutorial they set VertexAttribPointer
and it's offset with:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3* sizeof(float)));
With the gl-rs
I can't understand how to set offset of (void*)(3* sizeof(float)
. I can set (void*)0
with :
gl::VertexAttribPointer(
0,
3,
gl::FLOAT,
gl::FALSE,
(6 * std::mem::size_of::<f32>()) as gl::types::GLint,
std::ptr::null(), // offset
);
How do I set different values like (void*)(3* sizeof(float)
for the offset? I am not familiar with C so explanation would be appreciated.
Upvotes: 3
Views: 434
Reputation: 210908
The last parameter (offset) has to be cast to *const gl::types::GLvoid
:
gl::VertexAttribPointer(
1,
3,
gl::FLOAT,
gl::FALSE,
(6 * std::mem::size_of::<f32>()) as gl::types::GLint,
(3 * std::mem::size_of::<f32>()) as *const gl::types::GLvoid
);
See also
glVertexAttribPointer
Rust and OpenGL from scratch - Vertex Attribute Format
Upvotes: 3