c++ - int to void* - avoiding c-style cast? -
c++ - int to void* - avoiding c-style cast? -
i need cast int
(which specifies byte offset) const void*
. solution works me c-style casts:
int offset = 6*sizeof(glfloat); glvertexattribpointer(1,3,gl_float,gl_false,0,(void*)offset);
i want rid of c-style cast, dont't find working solution. tried
static_cast<void*>(&offset)
and compiles, cannot right solution (whole output different approach). here right solution?
link documentation of glvertexattribpointer
: link
considering it's hopeless case (see link provided derhass), best approach concentrate questionable code in 1 place, tack appropriately snide remark onto , @ to the lowest degree maintain remaining code clean:
/** * overload/wrapper around opengl's glvertexattribipointer, avoids * code smell due shady pointer arithmetic @ place of call. * * see also: * https://www.opengl.org/registry/specs/arb/vertex_buffer_object.txt * https://www.opengl.org/sdk/docs/man/html/glvertexattribpointer.xhtml */ void glvertexattribpointer(gluint index, glint size, glenum type, glsizei stride, size_t offset) { glvoid const* pointer = static_cast<char const*>(0) + offset; homecoming glvertexattribpointer(index, size, type, stride, offset); }
c++ pointers opengl casting void-pointers
Comments
Post a Comment