I'm trying to render a simple textured quad on Android 2.2 using GLSurfaceView
. I'm loading a BMP image (128x128) with BitmapFactory.decodeResource()
- this seems to work. But whenever I try to put this bitmap into an OpenGL texture using GLUtils.glTexImage2D
I get an OpenGL error: glGetError()
returns 1280, GL_INVALID_ENUM
. What am I doing wrong?
This is the code for my Renderer:
public class MyRenderer implements GLSurfaceView.Renderer {
Context context;
int texId;
public MyRenderer(Context c) {
this.context = c;
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_TEXTURE_2D);
this.texId = loadTexture(gl);
}
int loadTexture(GL10 gl) {
int[] tmp = new int[1];
gl.glGenTextures(1, tmp, 0);
int id = tmp[0];
Bitmap bmp = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.myimage);
gl.glGetError();
GLUtils.texImage2D(id, 0, bmp, 0);
int err = gl.glGetError();
if (err != 0) {
// err == 1280, prints "invalid enum":
System.err.println(GLU.gluErrorString(err));
}
return id;
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, 0, width, height, 0);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
@Override
public void onDrawFrame(GL10 gl) {
// ...
}
}
It should probably be something like:
gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With