我正在尝试开始一个简单的 2d openGL 游戏。我在旋转时遇到了麻烦。旋转和平移似乎都不起作用。我根本没有得到任何结果。在下面的示例中,我尝试在屏幕中央旋转一个 50x50 的小方块。
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
gl10.glEnable(GL10.GL_TEXTURE_2D);
gl10.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
textures = new int[1];
// LOAD TEXTURE
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.grass);
gl10.glGenTextures(1, textures, 0);
gl10.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl10.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl10.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
mCrop = new int[4];
mCrop[0] = 0;
mCrop[1] = bitmap.getHeight();
mCrop[2] = bitmap.getWidth();
mCrop[3] = -bitmap.getHeight();
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glShadeModel(GL10.GL_FLAT);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0.0f, sWidth, 0.0f, sHeight, 0.0f, 1.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
((GL11)gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCrop, 0);
gl.glPushMatrix();
gl.glRotatef(anglefromcenter, 0, 1, 0);
((GL11Ext)gl).glDrawTexfOES(sWidth/2, sHeight/2, 0, 50, 50);
gl.glPopMatrix();
...
任何帮助将非常感激。谢谢!