import static org.lwjgl.opengl.GL11.*; import java.util.ArrayList; import java.util.List; import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; public class Main { private static final String TITLE = "LWJGL program test"; public static final int WIDTH = 600; public static final int HEIGHT = 400; public static boolean running = true; public List<Box> shapes = new ArrayList<Box>(16); public Main() { try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.setTitle(TITLE); Display.setResizable(false); Display.create(); } catch (LWJGLException e) { System.err.println(e); } Start(); running = true; } public void Start() { openGL(); init(); render(); } private void openGL() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, WIDTH, HEIGHT, 0, 1, -1); glMatrixMode(GL_MODELVIEW); } private void init() { shapes.add(new Box (15,15)); shapes.add(new Box (100,100)); } private void keyHandler(){ if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){ Display.destroy(); System.exit(0); } } public void mouseHandler(){ int mouseX = Mouse.getX(); int mouseY = Mouse.getY(); int mouseDX = Mouse.getDX(); int mouseDY = Mouse.getDY(); if(Mouse.isButtonDown(0)){ //left click listener } } private void render() { while (!Display.isCloseRequested()) { for(Box box: shapes){ box.draw(); } keyHandler(); mouseHandler(); Display.update(); Display.sync(60); } if (Display.isCloseRequested()) { Display.destroy(); System.exit(0); } } public static void main(String[] args) { new Main(); } }
import static org.lwjgl.opengl.GL11.*; import java.util.Random; public class Box { private static float R,G,B; private static int x, y; private static Random random = new Random(); public Box(int x, int y){ this.x = x; this.y = y; randomColor(); } public static void randomColor(){ R = random.nextFloat(); G = random.nextFloat(); B = random.nextFloat(); } public void draw(){ glColor3f(R,G,B); glBegin(GL_QUADS); glVertex2i(x,y); glVertex2i(x + 25,y); glVertex2i(x + 25,y + 25); glVertex2i(x,y + 25); glEnd(); } }
basicaly i want to render as many boxes as i can (up to 16 as my array list shows) but every time i add a new box it only renders the last box that i created(the box with the integers 100,100), if you need any more info just post in the coments, thanks.


LinkBack URL
About LinkBacks
Reply With Quote
but this doesnt seem to work :/