Advertisement
Guest User

OpenGLRender

a guest
Jun 15th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package com.game.cube;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.nio.ByteOrder;
  5.  
  6. import Objects.Player;
  7. import android.content.Context;
  8. import android.opengl.GLSurfaceView.Renderer;
  9. import android.util.Log;
  10.  
  11. import javax.microedition.khronos.egl.EGLConfig;
  12. import javax.microedition.khronos.opengles.GL10;
  13.  
  14.  
  15. public class OpenGLRenderer implements Renderer
  16. {
  17.     Player user = new Player();
  18.     public OpenGLRenderer(Player p)
  19.     {
  20.         user = p;
  21.     }
  22.     public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig)
  23.     {
  24.         // DISABLE 3D FETURES //
  25.        
  26.         gl10.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
  27.     // Set the background color to black ( rgba ).
  28.     gl10.glClearColor(0.0f, 0.0f, 0.0f, 1);
  29.     //gl10.glClearColor(0.0f, 1.0f, 0.0f, 0.5f);
  30.     // Enable Flat Shading.
  31.     gl10.glShadeModel(GL10.GL_FLAT);
  32.         // We don't need to worry about depth testing!
  33.         gl10.glDisable(GL10.GL_DEPTH_TEST);
  34.         // Set OpenGL to optimise for 2D Textures
  35.         gl10.glEnable(GL10.GL_TEXTURE_2D);
  36.         // Disable 3D specific features. (You could possible use this for some special effects
  37.         // but you'll have to figure that out for yourself.
  38.         gl10.glDisable(GL10.GL_DITHER);
  39.         gl10.glDisable(GL10.GL_LIGHTING);
  40.  
  41.         gl10.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
  42.         // Initial clear of the screen.
  43.        
  44.         //gl10.glTranslatef(400f, 800f, 0.0f);
  45.        
  46.        
  47.         gl10.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  48.        
  49.        
  50.     }
  51.  
  52.     public void onSurfaceChanged(GL10 gl10, int i, int i1) {
  53.  
  54.         gl10.glViewport(0, 0, i, i1);
  55.         /*
  56.          * Set our projection matrix. This doesn't have to be done each time we
  57.          * draw, but usually a new projection needs to be set when the viewport
  58.          * is resized.
  59.          */
  60.         float ratio = (float) i / i1;
  61.         gl10.glMatrixMode(GL10.GL_PROJECTION);
  62.         gl10.glLoadIdentity();
  63.         gl10.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
  64.     }
  65.  
  66.     public void onDrawFrame(GL10 gl)
  67.     {
  68.         // Just clear the screen and depth buffer.
  69.         Log.i("DRAWING", "AT DRAW FRAME");
  70.         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  71.        
  72.         //String t = user.toString();
  73.         //Log.i("DRAWING", "USER NOT VOID");
  74.         //user.draw(gl10);
  75.        
  76.         gl.glLoadIdentity();
  77.        
  78.         gl.glTranslatef(0.0f, 0.0f, -5.0f);
  79.        
  80.         user.draw(gl);
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement