vertex array problems
hi, i've been away and i've finished my raw loader and i got several
aliens to load and move around but i had poor performance problems and
after reading, i realize that using vertex arrays is a good way of
achieving speedup. i'm having problems getting anything to work now,
could you please take a look at the following code:-
private void loadAlien(){
numAliens++;
for (int x = 0;x<coords.size();x+=9)
{
for (x = 0;x<coords.size();x+=9) {
float x1 = Float.parseFloat("" + coords.elementAt(x));
float y1 = Float.parseFloat("" + coords.elementAt(x+1));
float z1 = Float.parseFloat("" + coords.elementAt(x+2));
float x2 = Float.parseFloat("" + coords.elementAt(x+3));
float y2 = Float.parseFloat("" + coords.elementAt(x+4));
float z2 = Float.parseFloat("" + coords.elementAt(x+5));
float x3 = Float.parseFloat("" + coords.elementAt(x+6));
float y3 = Float.parseFloat("" + coords.elementAt(x+7));
float z3 = Float.parseFloat("" + coords.elementAt(x+icon_cool.gif);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
float vertices[] = {x1, y1, z1,
x2, y2, z2,
x3, y3, z3};
FloatBuffer pointer = (new BufferUtils()).createFloatBuffer(coords.size());
pointer.put(vertices);
pointer.flip();
GL11.glVertexPointer(3,0, pointer);
// GL11.glVertex3f(x1-(numAliens*4), y1, z1);
// GL11.glVertex3f(x2-(numAliens*4), y2, z2);
// GL11.glVertex3f(x3-(numAliens*4), y3, z3);
}
}
}
and please tell me why i'm getting the following errors when i'm running my code:-
Exception in thread "main" java.lang.OutOfMemoryError
at java.nio.Bits.reserveMemory(Bits.java:618)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:285)
at org.lwjgl.BufferUtils.createByteBuffer(Unknown Source)
at org.lwjgl.BufferUtils.createFloatBuffer(Unknown Source)
at OpenGLWindow.loadAlien(OpenGLWindow.java:201)
at OpenGLWindow.loadAliens(OpenGLWindow.java:240)
at OpenGLWindow.render(OpenGLWindow.java:118)
at OpenGLWindow.run(OpenGLWindow.java:49)
at OpenGLWindow.main(OpenGLWindow.java:40)
Press any key to continue...
hope no-one minds me asking for help, promise that i have been at this for hours with no success
thanks guys
also is this the best way to do it in your opinion?
As far as i can see you are recreating your "FloatBuffer" at every loop iteration. (Also you are enabling the a gl state and setting the array pointer every loop iteration, which is pointless. You only need to set these once).
You create your Float buffer only once and give it the total size needed for all the verticies. and then you put in all the vertcies into the buffer in your loop. And after you are done, and exit the loop, Set the vertex pointer.
You create your Float buffer only once and give it the total size needed for all the verticies. and then you put in all the vertcies into the buffer in your loop. And after you are done, and exit the loop, Set the vertex pointer.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement