3
\$\begingroup\$

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

| improve this question | | | | |
\$\endgroup\$
  • \$\begingroup\$ LWJGL has no concept of an "object". \$\endgroup\$ – user253751 Sep 18 '15 at 10:46
1
\$\begingroup\$

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.

| improve this answer | | | | |
\$\endgroup\$
0
\$\begingroup\$

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.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Why is glTranslatef slow? \$\endgroup\$ – BWG Feb 18 '15 at 14:25
  • \$\begingroup\$ @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. \$\endgroup\$ – rfreytag Feb 19 '15 at 19:40
  • \$\begingroup\$ @BWG glTranslatef itself is not slow, but it's part of the older fixed-function pipeline, which doesn't support the newest performance-enhancing features. (Although it might well be good enough if you're not looking for anything fancy - Minecraft uses it, for example) \$\endgroup\$ – user253751 Sep 18 '15 at 5:14
  • \$\begingroup\$ @immibis Minecraft also runs pretty terrible. \$\endgroup\$ – rfreytag Sep 18 '15 at 9:12
  • \$\begingroup\$ @pfannkuchen_gesicht At least old versions (before they started adding layers of abstraction everywhere) ran okay. Not great, not as efficiently as possible, but definitely acceptably. \$\endgroup\$ – user253751 Sep 18 '15 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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