OpenGL纹理生成
我目前正在尝试弄清楚如何使用 OpenGL。我想从字节缓冲区创建纹理。
由于某种原因,当我使用 glTexImage2D
执行此操作时,它不起作用(纹理显示为空白):
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
texwidth,
texheight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes
);
当我使用 gluBuild2DMipmaps
时,它不起作用工作:
gluBuild2DMipmaps(GL_TEXTURE_2D,
3,
texwidth,
texheight,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes
);
两者有什么区别,我做错了什么?
I'm currently trying to figure out how to use OpenGL. I want to create a texture from a byte buffer.
For some reason, when I do it with glTexImage2D
, it does not work (the texture comes out blank):
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
texwidth,
texheight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes
);
When I use gluBuild2DMipmaps
it does work:
gluBuild2DMipmaps(GL_TEXTURE_2D,
3,
texwidth,
texheight,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes
);
What is the difference between the two, and what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它与
gluBuild2DMipmaps
一起“工作”,而不是与glTexImage2D
一起“工作”(我猜纹理是黑色的),我猜你有一个基于 mipmap 的纹理纹理过滤器(这是也是默认的)。尝试调用始终记住,
glTexImage2D
仅为选定的 mipmap 级别(在您的情况下为级别 0)设置图像,并且如果您使用基于 mipmap 的缩小过滤器(带有_MIPMAP_
> 在其名称中)仅当您向所有 mipmap 级别提供图像(
gluBuild2DMipmaps
为您做的事情)或使用之前 上传图像或上传后更新的图像。我认为前者需要 OpenGL 1.4,后者需要 FBO 支持,这也是生成 mipmap 的非弃用现代方法。这两种方式(尤其是后者)也优于已弃用的 GLU 功能。
As it "works" with
gluBuild2DMipmaps
and not withglTexImage2D
(texture is black, I guess), I would guess you have a mipmap based texture filter for the texture (which is also the default). Try callingAlways remember that
glTexImage2D
only sets an image for the selected mipmap level (in your case level 0) and if you use a mipmap-based minification filter (a constant with_MIPMAP_
in its name) the results of the texturing are only defined if you supply images to all mipmap levels (whichgluBuild2DMipmaps
does for you) or generate them automatically using eitherbefore uplaoding the image or the newer
once it's uplaoded. The former requires OpenGL 1.4 and the latter requires FBO support, I think, and is also the non-deprectaed modern way to generate mipmaps. These two ways (especially the latter) are also prefered to the deprecated GLU functionality.