I have an OpenGL ES 1.0 textured sphere that I can rotate by panning:
As you can see, my viewport is a square of the size of the biggest side of my screen (which is what I want). The sphere has a radius of 1, so it fills the biggest side (again, that's what I want).
Now I want to be able to zoom in / out. I'm doing it by using gl.glScalef(x, y, z). It works but at some point, the sphere becomes too big and is being cut, I guess by the default z near/far planes:
Is it possible to increase these default values, or do I need to use glFrustumf?
When using glFrustumf, the sphere is no longer cut when zooming in/out, but the image is weird:
When zooming out:
Any idea on what's happening?
Here are the relevant part of the code I'm using:
@Override
public void onDrawFrame(GL10 gl) {
if(mTextureToLoad != null) {
mSphere.loadGLTexture(gl, mTextureToLoad);
mTextureToLoad = null;
}
gl.glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glScalef(mScale, mScale, mScale);
gl.glRotatef( (1-mRotationY) * 360, 1, 0, 0);
gl.glRotatef( (1-mRotationX) * 360, 0, 1, 0);
mSphere.draw(gl);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
float side = Math.max(width, height);
int x = (int) (width - side) / 2;
int y = (int) (height - side) / 2;
gl.glViewport(x, y, (int) side, (int) side);
/*
// When using glFrustumf:
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-1, 1, -1, 1, 0.1f, 100);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
*/
}