I’ve got a few textures drawn using glDrawTexfOES which display fine. I want to be able to change the camera view to give the impression of zooming in or out, but that’s where I’m having trouble. I tried making basic vertex arrays and this worked correctly and I could zoom. However, I want to be able to zoom textures using glDrawTexfOES. The relevant code is below:
onSurfaceCreated includes calls to:
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
onSurfaceChanged full implementation (I suspect the issue lies here)
public void onSurfaceChanged(GL10 gl, int width, int height) {
mWidth = width;
mHeight = height;
gl.glViewport(0, 0, mWidth, mHeight);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, mWidth, 0, mHeight, -1, 1);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
And finally, the onDrawFrame implementation:
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
// Set crop area (UVarray are uv co-ords for a texture map, the texture renders fine.)
((GL11) gl).glTexParameterfv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES,UVarray,0);
// Draw texture
((GL11Ext) gl).glDrawTexfOES(32.0f,32.0f,0.0f,64.0f,64.0f);
}
I have tried changing the parameters of glViewport and glOrthof to width*2 and height*2 but the textures still do not scale at all, they remain exactly the same. When I swap to using vertex arrays, these adjustments work.
Any help would be greatly appreciated.
The width and height parameters from
glDrawTextfOES()are in pixels. The modelview and projection matrix does only affect the position, not the scaling itself. Therefore, instead of using 64 pixels for the width and height parameters, you should use variables that scales the width and height globally, and if needed, select a part of the texture using texture cropping.This might be a useful read – OES_draw_texture.