Advertisement
BeamNG_IRC

Untitled

Mar 4th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package com.daniel.tests;
  2.  
  3. import org.lwjgl.LWJGLException;
  4. import org.lwjgl.opengl.Display;
  5. import org.lwjgl.opengl.DisplayMode;
  6. import static org.lwjgl.opengl.GL11.*;
  7.  
  8. /**
  9.  *
  10.  * @author daniel_j
  11.  *
  12.  */
  13.  
  14. public class Main { // class
  15.  
  16.     public static void main(String[] args) { // main function          
  17.         CreateDisplay(); // run our function to create a display
  18.         InitializeOpenGL();
  19.         WindowLoop(); // run our window loop function  
  20.         CleanWindowPresence();
  21.     } // main function
  22.  
  23.  
  24.  
  25.     private static void CreateDisplay() { // this function will create our display
  26.         try { // used to catch any errors
  27.             Display.setDisplayMode(new DisplayMode(800, 500)); // set our display resolution
  28.             Display.setTitle("OpenGL Tests"); // set the window title
  29.             Display.create(); // create our display
  30.         } catch (LWJGLException e) { // catch any errors
  31.             e.printStackTrace(); // print the errors
  32.         } // catch
  33.     } // create display function
  34.  
  35.    
  36.     private static void WindowLoop() { // this function will run our windows loop
  37.         while(!Display.isCloseRequested()) { // main loop for our window
  38.             glClear(GL_COLOR_BUFFER_BIT); // clear our canvas/frame
  39.             glLoadIdentity(); // clear the matrix
  40.             glColor3f(1.00f, 0.00f, 0.00f); // set our color
  41.             DrawRect(56, 56, 128, 256, 45, 1.00f, 0.00f, 0.00f); // draw a rectangle
  42.             DrawRect(200, 200, 128, 256, 60, 0.00f, 1.00f, 0.00f); // draw a rectangle
  43.             DrawRect(300, 300, 128, 256, 60, 0.00f, 0.00f, 1.00f); // draw a rectangle
  44.             Display.update(); // update our display            
  45.         } // end main loop     
  46.     } // window loop
  47.  
  48.  
  49.     private static void DrawRect(float x, float y, float Width, float Height, float Rotation, float Color_R, float Color_G, float Color_B) { // this function will draw a rectangle
  50.         // now we draw a square
  51.         glPushMatrix(); {// create a new matrix
  52.             glColor3f(Color_R, Color_G, Color_B); // set our color
  53.             glTranslatef(x, y, 0); // where we draw our shape
  54.             glRotatef(Rotation, 0, 0, 1); // rotate our shape around the z axis - angle, x, y, z
  55.            
  56.             glBegin(GL_QUADS); {// drawing a square
  57.                 glVertex2f(0, 0); // point 1
  58.                 glVertex2f(0, Height); // point 2
  59.                 glVertex2f(Width, Height); // point 3
  60.                 glVertex2f(Width, 0); // point 4                               
  61.             } // drawing a square
  62.             glEnd(); // end
  63.         }
  64.         glPopMatrix(); // finish our matrix
  65.  
  66.     } // draw rect
  67.    
  68.    
  69.     private static void InitializeOpenGL() { // this function will initialize OpenGL stuff
  70.         glMatrixMode(GL_PROJECTION); // select our projection matrix
  71.         glLoadIdentity(); // clear our matrix
  72.         glOrtho(0, Display.getWidth(), 0, Display.getHeight(), -1, 1); // create our display port
  73.         glMatrixMode(GL_MODELVIEW); // select our model view matrix
  74.         glClearColor(0, 0, 0, 1); // set our display clear color - RGBA
  75.         glDisable(GL_DEPTH_TEST); // disable depth test for 2d drawing
  76.     } // Initialize OpenGL
  77.    
  78.    
  79.  
  80.     private static void CleanWindowPresence() { // this function will clean our project out of memory upon closing
  81.         Display.destroy(); // clean up our display
  82.    
  83.     } // clean project presence
  84. } // class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement