How to cast int to const GLvoid*?

后端 未结 5 1982
不思量自难忘°
不思量自难忘° 2020-12-04 02:01

In my cross platform OpenGL application I want to draw using vertex buffer objects. However I run into problems invoking glDrawRangeElements.

glDrawRangeEle         


        
5条回答
  •  时光说笑
    2020-12-04 02:42

    Since it's so commonly used, people frequently use a macro for his type conversion. It can be defined like this:

    #define BUFFER_OFFSET(i) ((char *)NULL + (i))
    

    This is a clean and safe way of doing the cast, because it does not make any assumptions about integer and pointer types having the same size, which they often don't on 64-bit systems.

    Since I personally prefer C++ style casts, and don't use NULL, I would define it like this:

    #define BUFFER_OFFSET(idx) (static_cast(0) + (idx))
    

提交回复
热议问题