OpenGL GLU.gluLookAt() makes blank screen??


Last Updated: 2011-08-28 11:04:54
  1. AndroidJobo

    AndroidJobo New Member

    Why isn't my camera moving at all???
    I want my camera to move along the x-axis, but it doesn't move along any axis. Not even when I set cameraX,Y,Z to different values manually!

    Please help me.. all code below!

    Code (Text):
    1.     public boolean OnTouchEvent(final MotionEvent event) {
    2.         cameraX += 0.2f;
    3.         cameraY += 0.2f;
    4.         cameraZ += 0.2f;
    5.         return true;
    6.     }
    Code (Text):
    1.     @Override
    2.     public void onSurfaceChanged(GL10 gl, int width, int height) {
    3.         if (height == 0) height = 1;   // To prevent divide by zero
    4.           float aspect = (float)width / height;
    5.        
    6.           // Set the view port (display area) to cover the entire window
    7.           gl.glViewport(0, 0, width, height);
    8.      
    9.           // Setup perspective projection, with aspect ratio matches view port
    10.           gl.glMatrixMode(GL10.GL_PROJECTION); // Select projection matrix
    11.           gl.glLoadIdentity();                 // Reset projection matrix
    12.           // Use perspective projection
    13.           GLU.gluPerspective(gl, 45.0f, aspect, 0.1f, 100.0f);
    14.  
    15.           gl.glMatrixMode(GL10.GL_MODELVIEW);  // Select model-view matrix
    16.           gl.glLoadIdentity();    
    17.           // Reset
    18.      
    19.           // Your OpenGL|ES display re-sizing code here
    20.           // ......
    21.     }
    Code (Text):
    1.     @Override
    2.     public void onDrawFrame(GL10 gl) {
    3.         // Clear color and depth buffers using clear-value set earlier
    4.         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    5.        
    6.         //gl.glLoadIdentity();  // Reset model-view matrix
    7.         //gl.glTranslatef(0.0f, 0.0f, -6.0f);   // Translate into the screen
    8.         //quad.draw(gl);
    9.        
    10.         GLU.gluLookAt(gl, cameraX, cameraY, cameraZ, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    11.        
    12.         for(int i = 0; i < quadAmount; i++) {
    13.            
    14.             gl.glLoadIdentity();
    15.             gl.glTranslatef(quadx[i], 0.0f, quadz[i]);
    16.             quad.draw(gl);
    17.        
    18.             if(quadz[i] > 2.0f) {
    19.                 quadz[i] = (float) (-20 - rand.nextInt(10));
    20.                 if(rand.nextBoolean())
    21.                     quadx[i] = (float) (Math.random() * 15);
    22.                 else
    23.                     quadx[i] = (float) (Math.random() * -15);
    24.             }
    25.        
    26.             quadz[i] += 0.2f;
    27.         }
    28.        
    29.         cameraX += 1.0f;
    30.    
    31.         // Your OpenGL|ES rendering code here
    32.         // ......
    33.     }
    EDIT: Now I've tried setting gluLookAt() in the bottom of the draw class, which is after gl.LoadIdentity() has been called, but no changes.

    Advertisement

Share This Page