如何为 GLUT 立方体赋予不同的颜色?

发布于 2024-08-08 07:38:00 字数 423 浏览 1 评论 0原文

正如它所说:我有一些代码正在绘制 GLUT 立方体,但它们都是灰色的。我如何使它们具有不同的颜色?

到目前为止我所尝试的一切都失败了。我认为我的问题是我试图使用 OpenGL 函数来改变它们的颜色,但 GLUT 正在维护它自己的内部颜色或材质数据,我不知道如何让它改变这些数据。

这只是在线游戏测试客户端的填充图形,因此它们不必看起来很好,我只需要能够区分事物即可。我知道 GLUT 并不被认为是伟大的,所以如果有人想发布一个使用普通 OpenGL 而不是 glutCube 绘制立方体的示例,我会洗耳恭听。我并不关心如何在屏幕上显示立方体,而且它也不是我想花费大量时间的代码的一部分。我有一个合作伙伴正在做真实的图形;我只需要显示一些东西,以便我可以直观地看到我的代码正在做什么。

我使用 OpenGL/GLUT 的语言称为 Io,但它公开的 API 应该与我从 C 调用它时相同。

Just what it says: I have some code that's drawing GLUT cubes, but they're all grey. How do I make them different colors?

Everything I've tried so far has failed. I think my problem is that I'm trying to use OpenGL functions to change their colors, but GLUT is maintaining it's own internal color or material data and I don't know how to make it change that data.

This is just filler graphics for a test-client for an online game, so they don't have to look good, I just need to be able to tell things apart. I know GLUT isn't considered great, so if anyone wants to post an example of drawing a cube with plain OpenGL instead of glutCube I'm all ears. I don't really care how I get the cubes on the screen, and it's not a part of the code I want to spend a lot of time on. I have a partner who's doing the real graphics; I just need to get something showing so that I can visualize what my code is doing.

The language I'm using OpenGL/GLUT from is called Io, but the API it exposes should be the same as if I were calling it from C.

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

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

发布评论

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

评论(2

红墙和绿瓦 2024-08-15 07:38:00

事实证明,如果我这样做:

            glEnable(GL_COLOR_MATERIAL)

那么即使启用了照明,它也会使材质跟踪我用 glColor 设置的任何颜色。

It turns out that if I just do:

            glEnable(GL_COLOR_MATERIAL)

then it makes the material track whatever color I set with glColor, even when lighting is enabled.

墨落画卷 2024-08-15 07:38:00

只需预先使用 glColor 设置颜色()。但是,如果您使用照明(即启用 GL_LIGHTING),则必须使用 glMaterial() 设置立方体的颜色。

Just set the color beforehand with glColor(). If you're using lighting (i.e. GL_LIGHTING is enabled), though, then you'll instead have to use glMaterial() to set the cube's color.

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