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 ?

\$\endgroup\$
1

2 Answers 2

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.

\$\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.

\$\endgroup\$
5
  • \$\begingroup\$ Why is glTranslatef slow? \$\endgroup\$
    – BWG
    Commented Feb 18, 2015 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
    Commented Feb 19, 2015 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\$ Commented Sep 18, 2015 at 5:14
  • \$\begingroup\$ @immibis Minecraft also runs pretty terrible. \$\endgroup\$
    – rfreytag
    Commented Sep 18, 2015 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\$ Commented Sep 18, 2015 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .