OpenGL set transform matrix

Hi, I am new to bullet and LWJGL, and have boxes that fall down onto the ground.
I am setting the transform for the boxes with:


GL11.glLoadIdentity();
ByteBuffer temp = ByteBuffer.allocateDirect(64);
temp.order(ByteOrder.nativeOrder());       
GL11.glMultMatrix((FloatBuffer)temp.asFloatBuffer().put(m).flip());
DrawBox(1,1,1);

Where m is the 4x4 matrix of a box.

Is there a faster way to do this? or is it fine? I have no idea of any other way to do it.

Thanks,
roland

  1. Don’t allocate the bytebuffer every time. Store the created FloatBuffer after creating it the first time. You will have to put the contents explicitly at the 0th position, or rewind the buffer though.
  2. You can combine glLoadIdentity and glMultMatrix into glLoadMatrix
  3. #1/#2 should be done because they are easy and simple. Otherwise this is unlikely to be a bottleneck and you should worry more about what’s in DrawBox, or the actual physics computations (neither of which are under your control very much).
  4. Premature optimization is the root of all headaches

Thankyou very much lhkbob. You are right :slight_smile: I will fix #1 and #2 and not worry about optimising the difficult stuff until I have a game sort of working that needs to be sped up.