Advertisement
loloof64

simple opengl test gleventlistener

Mar 8th, 2012
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.26 KB | None | 0 0
  1. package com.gmail.bernabe.laurent.jogl.simple_test;
  2.  
  3. import javax.media.opengl.GL2;
  4. import javax.media.opengl.GLAutoDrawable;
  5. import javax.media.opengl.GLEventListener;
  6. import javax.media.opengl.glu.GLU;
  7.  
  8. public class MyGLEventListener implements GLEventListener {
  9.  
  10.     @Override
  11.     public void init(GLAutoDrawable drawable) {
  12.         // TODO Auto-generated method stub
  13.     }
  14.  
  15.     @Override
  16.     public void dispose(GLAutoDrawable drawable) {
  17.         // TODO Auto-generated method stub
  18.  
  19.     }
  20.  
  21.     @Override
  22.     public void display(GLAutoDrawable drawable) {
  23.         GL2 gl = drawable.getGL().getGL2();
  24.         gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
  25.         gl.glLoadIdentity();
  26.         glu.gluLookAt(0f, 0f, 5f,
  27.                 0f, 0f, 0f,
  28.                 0f, 1f, 0f);
  29.        
  30.         gl.glColor3f(1.0f, 0f, 0f);
  31.         gl.glBegin(GL2.GL_TRIANGLES);
  32.             gl.glVertex2f(0f, 1f);
  33.             gl.glVertex2f(-1f, 0f);
  34.             gl.glVertex2f(+1f, 0f);
  35.         gl.glEnd();
  36.     }
  37.  
  38.     @Override
  39.     public void reshape(GLAutoDrawable drawable, int x, int y, int width,
  40.             int height) {
  41.         GL2 gl = drawable.getGL().getGL2();
  42.         gl.glViewport(x, y, width, height);
  43.         gl.glMatrixMode(GL2.GL_PROJECTION);
  44.         gl.glLoadIdentity();
  45.         glu.gluPerspective(60f, (float) width / height, 0.1f, 10f);
  46.         gl.glMatrixMode(GL2.GL_MODELVIEW);
  47.     }
  48.  
  49.     private GLU glu = new GLU();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement