Hi,
I'm trying to get two viewports setup on the screen of the Android
Emulator (I have no real Android device as my University only gave me
a tablet pc with Windows 7 for development).
The FIRST VIEWPORT (orthographic projection) fills the emulators
screen and displays a white, screen filling polygon. The SECOND
VIEWPORT (perspective projection) is only a square inside the screen
and should appear above the other viewport showing a cube. Now, when i
have both viewports active I cannot see the white polygon but the
smaller viewport with the cube. In case I have the second viewports
code in block comments it again apears. I don't get where I have to
modify the code that both viewports appear correctly on the emulator.
Here are some code snippets:
--CODE--------------
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Set the background color to red ( rgba ).
gl.glClearColor(1.0f, 0.0f, 0.0f, 0.5f);
// Enable Smooth Shading, default not really needed.
gl.glShadeModel(GL10.GL_SMOOTH);
// Depth buffer setup.
gl.glClearDepthf(1.0f);
// Enables depth testing.
gl.glEnable(GL10.GL_DEPTH_TEST);
// The type of depth testing to do.
gl.glDepthFunc(GL10.GL_LEQUAL);
// Really nice perspective calculations.
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
GL10.GL_NICEST);
}
public void onDrawFrame(GL10 gl) {
// Clears the screen and depth buffer.
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
// Modelview Matrix selektieren
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Replace the current Matrix with the identity matrix
gl.glLoadIdentity();
// Translates 6 units into the screen
gl.glTranslatef(0, 0, -10);
// Draw RECTANGLE
square.draw(gl);
// CUBE
// Save the current matrix
gl.glPushMatrix();
gl.glTranslatef(0, 0, -5);
// Draw the cube
root.draw(gl);
// Restore the last matrix
gl.glPopMatrix();
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
for(int i = 0; i < 2; i++) {
if(i==0) {
// Main Viewport
gl.glViewport(0, 0, width, height);
// Select the projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
// Reset the projection matrix
gl.glLoadIdentity();
// Setup orthographic projection.
Consider aspect ratio to avoid distortion.
if(width < height) {
gl.glOrthof(-1.0f, 1.0f, -1.0f
* height / width, 1.0f * height / width, -2.0f, 10.0f);
} else {
gl.glOrthof(-1.0f * width /
height, 1.0f * width / height, -1.0f, 1.0f, -2.0f, 10.0f);
}
GLU.gluLookAt(gl, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
}
if(i==1) {
// Sets the cube's viewport.
gl.glViewport(width/2, height/3, width/
2, height/3);
// Select the projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
// Reset the projection matrix
gl.glLoadIdentity();
// Calculate the aspect ratio of the
window
GLU.gluPerspective(gl, 45.0f, (float)
width / (float) height, -2.0f, 10.0f);
GLU.gluLookAt(gl, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
}
// Select the modelview matrix
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Reset the modelview matrix
gl.glLoadIdentity();
// Clear Depth Buffer
gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);
}
}
--CODE--------------
Here is a screenshot how it looks in the emulator when I have both
viewports active:
http://userpages.uni-koblenz.de/~saditanis/picture.jpg
Maybe somebody can tell me if I have an errror in reasoning!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en