OpenGL ES的质地问题,4重复列和水平线(Android版) [英] OpenGL ES texture problem, 4 duplicate columns and horizontal lines (Android)
问题描述
我有RGB(或者RGBA)纹理图像的缓冲区,我想它显示我与下面code Android设备上。我使用OpenGL从NDK。
I have a buffer of RGB (or RGBA) texture image, and I want to display it on my Android device with the following code. I use OpenGL from NDK.
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
256,
256,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
this->pBuffer);
我还设置的PixelFormat从Java侧:
I have also set the PixelFormat from the Java side with:
this.getHolder().setFormat(PixelFormat.RGBA_8888);
this.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
setRenderer(new MyRenderer());
显示图像,但也有四列(相同的,并且包含了原始图像的识别份)和有水平的线遍布图像
The image is displayed but there are four columns (identical and contains recognizable parts of the original image) and there are horizontal lines all over the image.
可以是什么问题?
原始图像:
如何它看起来与我的code:
How it looks with my code:
推荐答案
这看起来就像图像大小不是256×256,但也许宽约150像素。你的纹理必须是2个大的力量,但如果你需要上传一个较小的纹理可以使用的 glTexSubImage2D :
This looks like the image size is not 256 by 256, but maybe about 150 pixels wide. Your texture has to be a power of 2 big, but if you need to upload a smaller texture you can use glTexSubImage2D:
glTexSubImage2D(GL_TEXTURE_2D, /* target */
0, /* level */
0, /* xoffset */
0, /* yoffset */
150, /* width */
256, /* height */
GL_RGBA, /* format */
GL_UNSIGNED_BYTE, /* type */
this->pBuffer); /* data */
在最初的glTexImage2D呼叫,只是传递NULL,而不是像素缓冲区。尝试这样的事情,看它是否有差别。
In the initial glTexImage2D call, just pass NULL instead of the pixel buffer. Try something like this, see if it makes a difference.
如果你使用glDrawTexiOES绘制纹理,然后裁剪较小的质地使用GL_TEXTURE_CROP_RECT_OES:
If you're using glDrawTexiOES to draw the texture, then to crop the smaller texture use GL_TEXTURE_CROP_RECT_OES:
int rect[4] = {0, imageHeight, imageWidth, -imageHeight};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
glDrawTexiOES(0, 0, 0, windowWidth, windowHeight);
这篇关于OpenGL ES的质地问题,4重复列和水平线(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!