[英]Android OpenGL ES 1.1 white box textures
I am having an issue where textures from the resources become just white. 我遇到一个问题,即资源中的纹理变成白色。 The issue only seems to occur on phones (Droid-X for sure), but it works just fine on the emulator. 这个问题似乎只发生在手机上(肯定是Droid-X),但在模拟器上也可以正常工作。 I have researched this issue for days and tried so many things. 我已经研究了这个问题几天,并尝试了很多事情。
Textures are POT ranging from 8x8 to 128x128 贴图的POT范围从8x8到128x128
Textures have been in res/drawable, res/drawable-nodpi and res/raw 纹理采用res / drawable,res / drawable-nodpi和res / raw
Tried with and without this in the manifest file: 在清单文件中尝试使用此方法:
<supports-screens android:anyDensity="true" />
I am at a complete loss on this. 我对此完全不知所措。
Here is the code I am using 这是我正在使用的代码
gl is GL10 and gl11 is GL11 gl是GL10,gl11是GL11
During onSurfaceCreated
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_BLEND);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glDisable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_LIGHTING);
gl.glShadeModel(GL10.GL_FLAT);
gl.glClearColor(0.00f, 0.00f, 0.00f, 1.00f);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA);
gl.glOrthof(-1, 1, -1, 1, -1, 1);
gl.glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
gl.glFrontFace(GL10.GL_CCW);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
During onSurfaceChanged 在onSurfaceChanged期间
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, width, height);
Generating the VBO: 生成VBO:
public final float vertices[] = {
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f
};
public float textureCoord[] = {
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f
};
public final byte indices[] = {
0, 1, 3,
0, 3, 2
};
verticesBuffer = ByteBuffer.allocateDirect(vertices.length *
Constants.FLOAT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
textureCoordBuffer = ByteBuffer.allocateDirect(textureCoord.length *
Constants.FLOAT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
indicesBuffer = ByteBuffer.allocateDirect(indices.length).order(ByteOrder.nativeOrder());
// fill buffers
verticesBuffer.put(vertices);
textureCoordBuffer.put(textureCoord);
indicesBuffer.put(indices);
// set pointer positions
verticesBuffer.position(0);
textureCoordBuffer.position(0);
indicesBuffer.position(0);
// temp buffer array
int[] buffer = new int[1];
// VERTICES BUFFER.
gl11.glGenBuffers(1, buffer, 0);
verticesBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, verticesBufferIndex);
final int vertexSize = verticesBuffer.capacity() * Constants.FLOAT_SIZE;
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertexSize, verticesBuffer, GL11.GL_STATIC_DRAW);
// TEXTURE COORD BUUFER
gl11.glGenBuffers(1, buffer, 0);
textureCoordBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureCoordBufferIndex);
final int texCoordSize = textureCoordBuffer.capacity() * Constants.FLOAT_SIZE;
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoordSize, textureCoordBuffer, GL11.GL_STATIC_DRAW);
// clear buffer id
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
// Unbind the array buffer.
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
gl11.glGenBuffers(1, buffer, 0);
// INDICES BUFFER
indicesBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indicesBufferIndex);
final int indexSize = indicesBuffer.capacity();
gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, indexSize, indicesBuffer, GL11.GL_STATIC_DRAW);
// Unbind the element array buffer.
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, verticesBufferIndex);
gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureCoordBufferIndex);
gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indicesBufferIndex);
BitmapFactory.Options sBitmapOptions = new BitmapFactory.Options();
sBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_4444;
// many of these calls :
Bitmap bitmap = BitmapFactory.decodeStream(resources.openRawResource(resourceID), null, sBitmapOptions);
int[] textures = new int[1];
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
mCropWorkspace[0] = 0;
mCropWorkspace[1] = bitmap.getHeight();
mCropWorkspace[2] = bitmap.getWidth();
mCropWorkspace[3] = -bitmap.getHeight();
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D,
GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCropWorkspace, 0);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
return texture[0]; // which gets stored into textureID for later
During onDrawFrame 在onDrawFrame期间
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
// and many of these
gl11.glPushMatrix();
// transfomations
gl11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
gl11.glDrawElements(GL10.GL_TRIANGLES, indicesCount, GL10.GL_UNSIGNED_BYTE, 0);
gl11.glPopMatrix();
Sorry for all the code but I think everything is there. 对不起所有代码,但我认为一切都在那里。
Thank you, 谢谢,
Will 将
You must enable vertex array and texture coords array and bind your buffer indexes before making any calls to your glDraw...()
function. 在调用glDraw...()
函数之前,必须启用顶点数组和纹理坐标数组并绑定缓冲区索引。
After glBindTexture()
in onDrawFrame()
, put this: 在onDrawFrame()
glBindTexture()
之后,放置以下内容:
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
GL11 gl11 = (GL11) gl;
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, verticesBufferIndex);
gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, textureCoordBufferIndex);
gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indicesBufferIndex);
// Draw...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.