Guest User

Untitled

a guest
May 21st, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. public class GLRenderer implements GLEventListener
  2. {
  3.     public void init(GLAutoDrawable drawable)
  4.     {
  5.         GL gl = drawable.getGL();
  6.         gl.glClearColor(0f,0f,1f,1f);
  7.     }
  8.     public void display(GLAutoDrawable drawable)
  9.     {
  10.         GL gl = drawable.getGL();
  11.         gl.glClear(GL.GL_COLOR_BUFFER_BIT);
  12.         gl.glColor3f(1f, 0f, 0f);
  13.         gl.glRectf(-25f,25f,25f,-25f);
  14.         gl.glFlush();
  15.     }
  16.     public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
  17.     {
  18.         GL gl = drawable.getGL();
  19.         float aspectRatio;
  20.         if(height == 0)
  21.             height = 1;
  22.         gl.glViewport(0,0,width,height);
  23.         gl.glMatrixMode(GL.GL_PROJECTION);
  24.         gl.glLoadIdentity();
  25.         aspectRatio=(float) width/ (float) height;
  26.         if(width<height)
  27.             gl.glOrtho(-100,100,-100/aspectRatio,100/aspectRatio,1,-1);
  28.         else
  29.             gl.glOrtho(-100*aspectRatio,100*aspectRatio,-100,100,1,-1);
  30.         gl.glMatrixMode(GL.GL_MODELVIEW);
  31.         gl.glLoadIdentity();
  32.     }
  33.     public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
  34.     {
  35.     }
  36. }
Add Comment
Please, Sign In to add comment