在真正的 Android 设备上使用glDrawTexiOES时出现错误代码 1281。我没有收到此错误,并且在 bluestacks(模拟器等)上一切正常。这些是我的选择...:
if ( gl == null ){
Log.e("OpenGL ERROR! ID:0", "gl objects is NULL");return -1;
}
int TexIDStorage[] = new int[1];
lastBitmapsWidth = bitmap.getWidth();
lastBitmapsHeight = bitmap.getHeight();
// Generate ID for texture that will be initialized.
gl.glGenTextures(1, TexIDStorage, 0);
// Next 2 lines are binding generated ID in cache to set and initialize texture.
gl.glBindTexture(GL10.GL_TEXTURE_2D, TexIDStorage[0]);
// Next 7 lines. Decides what to do when image getting smaller or bigger.
if(SmoothVision == true){ //GL_LINEAR - slow but smooth vision
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
}else{ //GL_NEAREST - fast and sharp vision
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);
}
// Next 2 lines. Decides what to do if images are smaller then height or width of drawing area: Repeat them.
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);//GL_CLAMP_TO_EDGE//GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);//GL_REPEAT
// Next line for transparency
gl.glEnable(GL10.GL_BLEND);
// Initialize image to the binded cache ID.(Push bitmap into GPU)
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
// Crop part of image so the device will draw only given pixels and not the whole image.
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES,
new int[] { 0, bitmap.getHeight(), bitmap.getWidth(), -bitmap.getHeight() }, 0);
bitmap.recycle();
gl.glFlush();
if (gl.glGetError() == GL10.GL_NO_ERROR){
varLoadedImageCount++;
arrLastLoadedIDs[varLastLoadedIDc] = TexIDStorage[0];
varLastLoadedIDc++;
}
else
Log.e("OpenGL caching ERROR! ID:1!", "GL Texture Loading Failed ("+ Num +"):" + gl.glGetError());
// Return ID of image in cache so I can call it from cache when I needed.
return TexIDStorage[0];
这是绘图功能...:
gl.glBindTexture(GL10.GL_TEXTURE_2D, testIDs[5]);
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); //GL10.GL_ONE ... No border near resized images.
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropArr, 0);
System.out.println("x:"+infArr[0]+"y:"+infArr[1]+"w:"+infArr[2]+"h:"+infArr[3]);
((GL11Ext) gl).glDrawTexiOES(infArr[0], infArr[1] + infArr[3], 0, infArr[2], -infArr[3]);
System.out.println("GLDraw...:"+gl.glGetError());
问题: ((GL11Ext) gl).glDrawTexiOES(infArr[0], infArr[1] + infArr[3], 0, infArr[2], -infArr[3] );
我的图像是 2 的幂...我知道有些设备无法填补缺失的选项,有些可能可以。我认为我的设备有同样的问题。知道什么会导致这个吗?谢谢你的任何回应...