Advertisement
Techmo

Java_Sand_v0.12_OpenGL

Jul 6th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package blocks;
  2.  
  3. import org.lwjgl.LWJGLException;
  4. import org.lwjgl.opengl.Display;
  5. import org.lwjgl.opengl.DisplayMode;
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. public class main {
  9.     static int particleSize = 2;
  10.     public void start() {
  11.         try {
  12.         Display.setDisplayMode(new DisplayMode(800,600));
  13.         Display.create();
  14.     } catch (LWJGLException e) {
  15.         e.printStackTrace();
  16.         System.exit(0);
  17.     }
  18.  
  19.     // init OpenGL
  20.     GL11.glMatrixMode(GL11.GL_PROJECTION);
  21.     GL11.glLoadIdentity();
  22.     GL11.glOrtho(0, 800, 0, 600, 1, -1);
  23.     GL11.glMatrixMode(GL11.GL_MODELVIEW);
  24.  
  25.     while (!Display.isCloseRequested()) {
  26.         // Clear the screen and depth buffer
  27.         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); 
  28.        
  29.         // set the color of the quad (R,G,B,A)
  30.        
  31.            
  32.         // draw quad
  33.         for (int i = 0; i <= 200; i += 2 ){
  34.             for (int j = 0; j <= 200; j += 2 ){
  35.                 particle(i, j, 0.5f, 0.0f, 0.5f);
  36.             }
  37.         }
  38.        
  39.         Display.update();
  40.     }
  41.  
  42.     Display.destroy();
  43.     }
  44.     // renders a square or 'particle' of the color specified at the coordinated provided
  45.     public static void particle(int x, int y, float r, float g, float b) {
  46.         GL11.glColor3f(r,g,b);
  47.         GL11.glBegin(GL11.GL_QUADS);
  48.         GL11.glVertex2f(x*particleSize,y*particleSize);
  49.         GL11.glVertex2f(x*particleSize+particleSize,y*particleSize);
  50.         GL11.glVertex2f(x*particleSize+particleSize,y*particleSize+particleSize);
  51.         GL11.glVertex2f(x*particleSize,y*particleSize+particleSize);
  52.         GL11.glEnd();
  53.     }
  54.     public static void main(String[] argv) {
  55.         main quadExample = new main();
  56.         quadExample.start();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement