I am starting out in the gaming world and i have been going at it for a while but i have run into the problem of speed… I am moving to VBO’s in LWJGL, but i have run into the problem of my code wont work(or at least i don’t understand how to use VBO’s.
I Can give my code currently and please help.
public class Sim extends Thread {
public static boolean running;
public static Render renderer;
public Sim() {
super("MYSim Main");
Sim.running = true;
}
public static void startDisplay() {
try {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
System.out.println("Display Created in Thread: " + Thread.currentThread().getName());
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
}
@Override
public void run() {
////////////Must Be FirstThing Run/////////////
Sim.startDisplay();
////////////Must Be FirstThing Run/////////////
this.init();
this.main();
}
public void main() {
Render.Init();
while (running) {
float[] positions = new float[]{0, 0, 0, 1, 1, 0, 1, 0, 0};
float[] colors = new float[]{0, 0, 0, 1, 1, 0, 1, 0, 0};
// Put our data in the proper format: byte buffers
FloatBuffer positionBuffer = BufferUtils.createFloatBuffer(positions.length);
positionBuffer.put(positions);
positionBuffer.flip();
FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(colors.length);
colorBuffer.put(colors);
colorBuffer.flip();
//VertexBufferUtils.vertexBufferData(Render.vertexBufferID, positionBuffer);
//Display.update();
}
}
private void init() {
Sim.renderer = new Render();
}
class Render:
public class Render {
public static int vertexBufferID;
public static int colourBufferID;
private static int numberIndices;
private static int indexBufferID;
private static int maxIndex;
public Render() {
System.out.println("HELLO!!!!");
}
private static void CreateBufferIDs() {
IntBuffer buffer = BufferUtils.createIntBuffer(2);
GL15.glGenBuffers(buffer);
vertexBufferID = buffer.get(0);
colourBufferID = buffer.get(1);
}
public static void Init() {
Render.CreateBufferIDs();
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferID);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colourBufferID);
GL11.glColorPointer(4, GL11.GL_FLOAT, 0, 0);
//If you are not using IBOs:
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, numberIndices);
//If you are using IBOs:
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
GL11.glDrawElements(GL11.GL_TRIANGLES, numberIndices, GL11.GL_UNSIGNED_INT, 0);
//The alternate glDrawElements.
GL12.glDrawRangeElements(GL11.GL_TRIANGLES, 0, maxIndex, numberIndices,
GL11.GL_UNSIGNED_INT, 0);
}
}