在 OpenGL 的 glVertexPointer 中(当使用 VBO 时)为什么不将其最后一个参数设置为零?

发布于 12-22 16:46 字数 270 浏览 2 评论 0原文

在OpenGL中,当使用VBO时,为什么我经常看到最后一个参数(指向数据的指针)指定如下...

glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL ); 

...而不是简单地这样...

glVertexPointer( 3, GL_FLOAT, 0, 0); 

这可能只是首选语法的问题,因为它似乎是双向的。但如果有理由不只使用零,那是为什么呢?

In OpenGL, when using VBO's, why do I often see the last parameter (the pointer to the data) specified as follows...

glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL ); 

...instead of simply like this...

glVertexPointer( 3, GL_FLOAT, 0, 0); 

It may just be a question of preferred syntax as it appears to work both ways. But if there's a reason not to just use zero, why is that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宣告ˉ结束2024-12-29 16:46:04

但是如果有理由不只使用零,那是为什么呢?

对C语言编程缺乏了解。在 C 中,空指针是 0,底层宏是

#define NULL 0

没有类型转换的。

此外,如果将某个数字(这不是将指针转换为 intptr_t 的结果)转换为指针,会发生什么也是未定义的。实际上你在欺骗编译器。我在这里解释了详细信息:

https://stackoverflow.com/a/8284829/524368

But if there's a reason not to just use zero, why is that?

Lack of understanding of the C programming language. In C the null pointer is 0, the underlying macro is

#define NULL 0

there's no typecast there.

Also it's undefined what happens if you cast some number (that's not the result of casting a pointer to intptr_t) to a pointer. Effectively you're cheating the compiler. I explained the details here:

https://stackoverflow.com/a/8284829/524368

野生奥特曼2024-12-29 16:46:04

只是为了(向读者)明确它是一个指针。

openGL 调用有很多参数,这些参数通常为零,因此如果连续有 3 个或 4 个零,则可以更清晰地读取

Just to make it clear (to the reader) that it's a pointer.

There are lots of parameters to openGL calls, which are often zero, so it just makes it a little clearer to read if there are 3 or 4 zeros in a row

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文