Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

It is possible to add an object in LWJGL without using translation function (glTranslatef) ? and if it is possible does this improve somehow performance ?

share|improve this question

2 Answers 2

glTranslate is deprecated and slow, so you shouldn't use that function anyway and rather use the matrix operations, like Matrix4f.translate(modelPos, modelMatrix, modelMatrix); to transform your models. see: http://lwjgl.org/wiki/index.php?title=The_Quad_with_Projection,_View_and_Model_matrices

and feed a complete Model-View-Projection matrix to the shader as described in the link above. Another way to gain a little more performance would also be to use Uniform Buffers instead, but I'm not sure if lwjgl does support that, yet.

share|improve this answer
    
Why is glTranslatef slow? –  BWG Feb 18 at 14:25
    
@BWG because it uses the immediate mode, that means the command is executed on the GPU when the CPU calls it or even a little later due to command buffering. Also the transformation data has to be pushed all the time, where as with matrices you can push it once and the shader uses it all the time. Also a big factor is driver overhead, for each transformation you have to go through the driver which costs quite some time. –  pfannkuchen_gesicht Feb 19 at 19:40

glTranslatef doesn't add objects in LWJGL but translates OpenGL's built-in modelViewProjection matrix. Based on the fact that you're using glTranslatef I would say that you're using legacy OpenGL where this is the only way of matrix translations and these calls are not hardware accelerated.

Possibly the best way to improve your performance is to switch to modern OpenGL, bring your own math library with your own matrices (LWJGL's utility library provides you with these but you can look for other libraries if you want to) and start using shaders.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.