Android Open Source - opengl Open G L Renderer






From Project

Back to project page opengl.

License

The source code is released under:

Apache License

If you think the Android project opengl listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.cs4730.OpenGlDemo;
/*from w  ww .j a va  2  s . c  o  m*/
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;


import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;

public class OpenGLRenderer implements Renderer {

  // Initialize our square.
  Square square = new Square();

  /*
   * (non-Javadoc)
   *
   * @see
   * android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.
         * microedition.khronos.opengles.GL10, javax.microedition.khronos.
         * egl.EGLConfig)
   */
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // Set the background color to black ( rgba ).
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);  // OpenGL docs.
    // Enable Smooth Shading, default not really needed.
    gl.glShadeModel(GL10.GL_SMOOTH);// OpenGL docs.
    // Depth buffer setup.
    gl.glClearDepthf(1.0f);// OpenGL docs.
    // Enables depth testing.
    gl.glEnable(GL10.GL_DEPTH_TEST);// OpenGL docs.
    // The type of depth testing to do.
    gl.glDepthFunc(GL10.GL_LEQUAL);// OpenGL docs.
    // Really nice perspective calculations.
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, // OpenGL docs.
                          GL10.GL_NICEST);
  }

  /*
   * (non-Javadoc)
   *
   * @see
   * android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.
         * microedition.khronos.opengles.GL10)
   */
  public void onDrawFrame(GL10 gl) {
    // Clears the screen and depth buffer.
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | // OpenGL docs.
                           GL10.GL_DEPTH_BUFFER_BIT);
    // Replace the current matrix with the identity matrix
    gl.glLoadIdentity(); // OpenGL docs

    // Translates 4 units into the screen.
    gl.glTranslatef(0, 0, -4); // OpenGL docs

    // Draw our square.
    square.draw(gl); // ( NEW )
    

  }

  /*
   * (non-Javadoc)
   *
   * @see
   * android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.
         * microedition.khronos.opengles.GL10, int, int)
   */
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    // Sets the current view port to the new size.
    gl.glViewport(0, 0, width, height);// OpenGL docs.
    // Select the projection matrix
    gl.glMatrixMode(GL10.GL_PROJECTION);// OpenGL docs.
    // Reset the projection matrix
    gl.glLoadIdentity();// OpenGL docs.
    // Calculate the aspect ratio of the window
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height,
        0.1f, 100.0f);
    // Select the modelview matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);// OpenGL docs.
    // Reset the modelview matrix
    gl.glLoadIdentity();// OpenGL docs.
  }
}




Java Source Code List

book.BouncyCube.BouncyCubeActivity.java
book.BouncyCube.BouncyCubeActivity.java
book.BouncyCube.BouncyCubeRenderer.java
book.BouncyCube.BouncyCubeRenderer.java
book.BouncyCube.Cube.java
book.BouncyCube.Cube.java
book.SolarSystem.Cube.java
book.SolarSystem.Cube.java
book.SolarSystem.Planet.java
book.SolarSystem.Planet.java
book.SolarSystem.SolarSystemActivity.java
book.SolarSystem.SolarSystemActivity.java
book.SolarSystem.SolarSystemRenderer.java
book.SolarSystem.SolarSystemRenderer.java
com.androidbook.opengl.AndroidOpenGL.java
com.androidbook.opengl.AndroidOpenGL.java
com.androidbook.opengl.BasicGLCube.java
com.androidbook.opengl.BasicGLCube.java
com.androidbook.opengl.BasicGL.java
com.androidbook.opengl.BasicGL.java
com.androidbook.opengl.CubeSmallGLUT.java
com.androidbook.opengl.CubeSmallGLUT.java
com.androidbook.opengl.Menu.java
com.androidbook.opengl.Menu.java
com.androidbook.opengl.OpenGLPlay.java
com.androidbook.opengl.OpenGLPlay.java
com.androidbook.opengl.SimpleFPSDisplay.java
com.androidbook.opengl.SimpleFPSDisplay.java
com.androidbook.opengl.SimpleLitGLCube.java
com.androidbook.opengl.SimpleLitGLCube.java
com.androidbook.opengl.SmallGLUT.java
com.androidbook.opengl.SmallGLUT.java
com.androidbook.opengl.TexCubeSmallGLUT.java
com.androidbook.opengl.TexCubeSmallGLUT.java
com.androidbook.opengl.TextureGL.java
com.androidbook.opengl.TextureGL.java
com.androidbook.opengl.TriangleSmallGLUT.java
com.androidbook.opengl.TriangleSmallGLUT.java
com.droidnova.android.games.vortex.VortexRenderer.java
com.droidnova.android.games.vortex.VortexRenderer.java
com.droidnova.android.games.vortex.VortexView.java
com.droidnova.android.games.vortex.VortexView.java
com.droidnova.android.games.vortex.Vortex.java
com.droidnova.android.games.vortex.Vortex.java
com.example.android.opengl.MyGLRenderer.java
com.example.android.opengl.MyGLRenderer.java
com.example.android.opengl.MyGLSurfaceView.java
com.example.android.opengl.MyGLSurfaceView.java
com.example.android.opengl.OpenGLES20Activity.java
com.example.android.opengl.OpenGLES20Activity.java
com.example.android.opengl.Square.java
com.example.android.opengl.Square.java
com.example.android.opengl.Triangle.java
com.example.android.opengl.Triangle.java
edu.cs4730.OpenGlDemo1.OpenGlDemo1Activity.java
edu.cs4730.OpenGlDemo1.OpenGlDemo1Activity.java
edu.cs4730.OpenGlDemo1.SquareRenderer.java
edu.cs4730.OpenGlDemo1.SquareRenderer.java
edu.cs4730.OpenGlDemo1.Square.java
edu.cs4730.OpenGlDemo1.Square.java
edu.cs4730.OpenGlDemo.OpenGLRenderer.java
edu.cs4730.OpenGlDemo.OpenGLRenderer.java
edu.cs4730.OpenGlDemo.OpenGlDemo.java
edu.cs4730.OpenGlDemo.OpenGlDemo.java
edu.cs4730.OpenGlDemo.Square.java
edu.cs4730.OpenGlDemo.Square.java
edu.cs4730.opengl2ex1.LessonOneRenderer.java
edu.cs4730.opengl2ex1.LessonOneRenderer.java
edu.cs4730.opengl2ex1.MainActivity.java
edu.cs4730.opengl2ex1.MainActivity.java
edu.cs4730.opengl2ex2.LessonOneRenderer.java
edu.cs4730.opengl2ex2.LessonOneRenderer.java
edu.cs4730.opengl2ex2.MainActivity.java
edu.cs4730.opengl2ex2.MainActivity.java
edu.cs4730.opengl2ex2.myGlSurfaceView.java
edu.cs4730.opengl2ex2.myGlSurfaceView.java