其他 PC 上的 OpenGL 白色纹理

发布于 2024-10-21 18:59:53 字数 1178 浏览 1 评论 0原文

我使用 SDL + OpenGL 制作了这个小游戏。该游戏在我的电脑上运行良好,但在朋友的电脑上,他只是看到白框和黑屏。

我认为这可能是一个问题,因为我的纹理的维度不是 2 的幂。我无法更改纹理尺寸,因此经过一番搜索,我发现使用 GL_ARB_texture_non_power_of_two 会以某种方式强制(?)npot 纹理。但是,令我惊讶的是,白框之类的东西出现在我的电脑上,而且它们甚至没有消失在我的朋友身上。我无法理解问题所在。任何帮助将不胜感激。

代码:

   numColors = images[i]->format->BytesPerPixel;
   if ( numColors == 4 )
   {
       if (images[i]->format->Rmask == 0x000000FF)
           textureFormat = GL_RGBA;
       else
           textureFormat = GL_BGRA;
   }
   else if ( numColors == 3 )
   {
       if (images[i]->format->Rmask == 0x000000FF)
           textureFormat = GL_RGBA;
       else
           textureFormat = GL_BGRA;
   }
   glPixelStorei(GL_UNPACK_ALIGNMENT,4);
   glGenTextures( 1, &textures[i] );
   glBindTexture( GL_ARB_texture_non_power_of_two, textures[i] );
   glTexParameteri(GL_ARB_texture_non_power_of_two,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_ARB_texture_non_power_of_two,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexImage2D(GL_ARB_texture_non_power_of_two, 0, numColors, images[i]->w, images[i]->h, 0, textureFormat, GL_UNSIGNED_BYTE, images[i]->pixels);

I've made this small game using SDL + OpenGL. The game runs fine on my PC, but on a friend's PC, he just gets white boxes and blank screen.

I thought it might be an issue due to my textures being non power of 2 in dimensions. I cannot change the texture dimensions, so after some searching, I found that using GL_ARB_texture_non_power_of_two would somehow force(?) npot textures. But, to my surprise, the white boxes and stuff appear on my PC and they aren't even gone on my friends. I'm unable to understand what the problem is. Any help would be greatly appreciated.

Code:

   numColors = images[i]->format->BytesPerPixel;
   if ( numColors == 4 )
   {
       if (images[i]->format->Rmask == 0x000000FF)
           textureFormat = GL_RGBA;
       else
           textureFormat = GL_BGRA;
   }
   else if ( numColors == 3 )
   {
       if (images[i]->format->Rmask == 0x000000FF)
           textureFormat = GL_RGBA;
       else
           textureFormat = GL_BGRA;
   }
   glPixelStorei(GL_UNPACK_ALIGNMENT,4);
   glGenTextures( 1, &textures[i] );
   glBindTexture( GL_ARB_texture_non_power_of_two, textures[i] );
   glTexParameteri(GL_ARB_texture_non_power_of_two,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_ARB_texture_non_power_of_two,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexImage2D(GL_ARB_texture_non_power_of_two, 0, numColors, images[i]->w, images[i]->h, 0, textureFormat, GL_UNSIGNED_BYTE, images[i]->pixels);

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

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

发布评论

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

评论(3

夜光 2024-10-28 18:59:53

您朋友的显卡可能不支持两个纹理的非幂,因此尽管使用 GL_ARB_texture_non_power_of_two 扩展,输出仍然错误。

如果您的游戏依赖于特定的 OpenGL 扩展来正确显示,您应该在启动时检查这些扩展,并告诉用户,如果他的硬件缺乏这些功能,他将无法运行游戏。

Your friend's video card may not support non power of two textures, therefore the output is still wrong despite using the GL_ARB_texture_non_power_of_two extension.

If your game relies on specific OpenGL extensions to display correctly, you should check for those extensions at start up and tell the user he can't run the game if his hardware is lacking the features.

若沐 2024-10-28 18:59:53

不要使用 GL_ARB_texture_non_power_of_two 而不是 GL_TEXTURE_2D。只需检查扩展是否受支持,然后使用 glTexImage(GL_TEXTURE_2D, w, h, ...) 发送 NPOT 纹理。

调用 glGetError() 查看是否出现错误。您应该这样做,因为 GL_ARB_...npot 在您使用时不是有效值。

GL_ARB_NPOT 也用于 1D 和 3D 纹理。

Don't use GL_ARB_texture_non_power_of_two instead of GL_TEXTURE_2D. Just check if the extension is supported then send NPOT textures using glTexImage(GL_TEXTURE_2D, w, h, ...).

Call glGetError() to see if you're getting error. You should, since GL_ARB_...npot is not a valid value as you use it.

GL_ARB_NPOT is also used for 1D and 3D textures.

等风也等你 2024-10-28 18:59:53

除了 ARB_texture_non_power_of_two 之外,还有另一个扩展:GL_ARB_texture_rectangle;很老了,GPU 已经支持它很多年了。使用它,您的代码看起来像

glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glGenTextures( 1, &textures[i] );
glBindTexture( GL_TEXTURE_RECTANGLE_ARB, textures[i] );
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, numColors, images[i]->w, images[i]->h, 0, textureFormat, GL_UNSIGNED_BYTE, images[i]->pixels);

顺便说一句: GL_ARB_texture_non_power_of_two 是扩展名称,而不是用作纹理目标的有效标记; OpenGL 应该发出 GL_INVALID_ENUM 错误。

Additionally to ARB_texture_non_power_of_two there's also another extension: GL_ARB_texture_rectangle; quite old, it's been supported by GPUs for ages. Using that your code would look like

glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glGenTextures( 1, &textures[i] );
glBindTexture( GL_TEXTURE_RECTANGLE_ARB, textures[i] );
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, numColors, images[i]->w, images[i]->h, 0, textureFormat, GL_UNSIGNED_BYTE, images[i]->pixels);

BTW: GL_ARB_texture_non_power_of_two is a extension name, not a valid token to be used as texture target; OpenGL should have issued an GL_INVALID_ENUM error.

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