OpenGL - 纹理 glutSolidSphere?

发布于 2024-12-25 09:56:38 字数 513 浏览 1 评论 0原文

如何将纹理应用到 glutSolidSphere?

这是我尝试过的,但它不起作用:

GLuint textureid;
    glGenTextures(1, &textureid);
    glBindTexture(GL_TEXTURE_2D, textureid);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, "stone.tga");
// Planet
    glDisable(GL_LIGHTING);
    glBindTexture(GL_TEXTURE_2D, textureid);
    glutSolidSphere(35.0f, 30, 17);
    glEnable(GL_LIGHTING);

有人可以指导我如何加载纹理并启用它。

我听说 glutSolidSphere 已经发出纹理坐标,所以我不必在那里做任何特别的事情。

How can I apply a texture to a glutSolidSphere?

this what i have tried but it doesn't work:

GLuint textureid;
    glGenTextures(1, &textureid);
    glBindTexture(GL_TEXTURE_2D, textureid);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, "stone.tga");
// Planet
    glDisable(GL_LIGHTING);
    glBindTexture(GL_TEXTURE_2D, textureid);
    glutSolidSphere(35.0f, 30, 17);
    glEnable(GL_LIGHTING);

can some one direct me on how to Load the texture and enable it.

i heard that glutSolidSphere emits texture coordinates already, so i don't have to do anything special there.

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

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

发布评论

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

评论(1

秋凉 2025-01-01 09:56:38

您的问题是您实际上并没有使用 glTexImage2D 创建纹理。最后一个参数应该是像素通道颜色的 byte[],顺序为红、绿、蓝、Alpha(由其他参数指定 - GL_UNSIGNED_BYTEGL_RGBA),而不仅仅是文件名。

OpenGL 不知道文件是什么、如何从特定于系统的文件系统读取文件或如何解析 TGA 文件格式。它需要原始颜色数据,因此您需要加载并解析图像并将 byte[] 传递给 OpenGL(技术上讲,指向第一个元素的指针为 void*) 。有几个 指南,为您提供解析所需的最少代码TGA 文件,但您也可以使用像 FreeImage 这样的库来处理加载纹理,并且它适用于很多不仅仅是 TGA。

Your issue is that you're not actually creating a texture with glTexImage2D. The last parameter should be a byte[] of pixel channel colors in the order Red, Green, Blue, Alpha (as specified by your other parameters - GL_UNSIGNED_BYTE and GL_RGBA), and not just the name of the file.

OpenGL has no clue what a file is, how to read a file from a system-specific filesystem, or how to parse the TGA file format. It's expecting raw color data, so you need to load and parse your image and pass the byte[] to OpenGL (technically the pointer to the first element as a void*). There are several guides that give you the minimum code necessary to parse a TGA file, but you can also use a library like FreeImage to handle loading your textures, and it works with much more than just TGA.

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