将新纹理加载到已定义的纹理名称中 [英] Loading new texture into already defined texture name

查看:55
本文介绍了将新纹理加载到已定义的纹理名称中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 OpenGl 程序,我在其中使用纹理显示图像.我希望能够加载要显示的新图像.

I have an OpenGl program in which I am displaying an image using textures. I want to be able to load a new image to be displayed.

在我的 Init 函数中,我调用:

In my Init function I call:

Gl.glGenTextures(1, mTextures);

由于一次只显示一张图片,我对每张图片使用相同的纹理名称.

Since only one image will be displayed at time, I am using the same texture name for each image.

每次加载新图像时,我都会调用以下内容:

Each time a new image is loaded I call the following:

Gl.glBindTexture(Gl.GL_TEXTURE_2D, mTexture[0]);

Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_LUMINANCE, mTexSizeX, mTexSizeY, 0, Gl.GL_LUMINANCE, Gl.GL_UNSIGNED_SHORT, mTexBuffer);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);   
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);

第一张图片将按预期显示.但是,所有图像在第一个之后加载,显示为全黑.

The first image will display as expected. However, all images load after the first, display as all black.

我做错了什么?

推荐答案

你在绘制后是否glDisable GL_TEXTURE_2D ?放置一个 glColor4f(1,1,1,1); 如果禁用 2d 纹理,您应该至少看到白色矩形.它将帮助您在这里找到问题所在.

Did you glDisable GL_TEXTURE_2D after drawing ? Put an glColor4f(1,1,1,1); you should see at least white rectangle if 2d texture is disabled. It will help you find here the problem is.

这篇关于将新纹理加载到已定义的纹理名称中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆