Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.daniel.tests;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import static org.lwjgl.opengl.GL11.*;
- /**
- *
- * @author daniel_j
- *
- */
- public class Main { // class
- public static void main(String[] args) { // main function
- CreateDisplay(); // run our function to create a display
- InitializeOpenGL();
- WindowLoop(); // run our window loop function
- CleanWindowPresence();
- } // main function
- private static void CreateDisplay() { // this function will create our display
- try { // used to catch any errors
- Display.setDisplayMode(new DisplayMode(800, 500)); // set our display resolution
- Display.setTitle("OpenGL Tests"); // set the window title
- Display.create(); // create our display
- } catch (LWJGLException e) { // catch any errors
- e.printStackTrace(); // print the errors
- } // catch
- } // create display function
- private static void WindowLoop() { // this function will run our windows loop
- while(!Display.isCloseRequested()) { // main loop for our window
- glClear(GL_COLOR_BUFFER_BIT); // clear our canvas/frame
- glLoadIdentity(); // clear the matrix
- glColor3f(1.00f, 0.00f, 0.00f); // set our color
- DrawRect(56, 56, 128, 256, 45, 1.00f, 0.00f, 0.00f); // draw a rectangle
- DrawRect(200, 200, 128, 256, 60, 0.00f, 1.00f, 0.00f); // draw a rectangle
- DrawRect(300, 300, 128, 256, 60, 0.00f, 0.00f, 1.00f); // draw a rectangle
- Display.update(); // update our display
- } // end main loop
- } // window loop
- 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
- // now we draw a square
- glPushMatrix(); {// create a new matrix
- glColor3f(Color_R, Color_G, Color_B); // set our color
- glTranslatef(x, y, 0); // where we draw our shape
- glRotatef(Rotation, 0, 0, 1); // rotate our shape around the z axis - angle, x, y, z
- glBegin(GL_QUADS); {// drawing a square
- glVertex2f(0, 0); // point 1
- glVertex2f(0, Height); // point 2
- glVertex2f(Width, Height); // point 3
- glVertex2f(Width, 0); // point 4
- } // drawing a square
- glEnd(); // end
- }
- glPopMatrix(); // finish our matrix
- } // draw rect
- private static void InitializeOpenGL() { // this function will initialize OpenGL stuff
- glMatrixMode(GL_PROJECTION); // select our projection matrix
- glLoadIdentity(); // clear our matrix
- glOrtho(0, Display.getWidth(), 0, Display.getHeight(), -1, 1); // create our display port
- glMatrixMode(GL_MODELVIEW); // select our model view matrix
- glClearColor(0, 0, 0, 1); // set our display clear color - RGBA
- glDisable(GL_DEPTH_TEST); // disable depth test for 2d drawing
- } // Initialize OpenGL
- private static void CleanWindowPresence() { // this function will clean our project out of memory upon closing
- Display.destroy(); // clean up our display
- } // clean project presence
- } // class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement