2
\$\begingroup\$

I am currently trying to make a game with pixelated graphics. The game is supposed to run with as few textures as possible. Instead of this it is supposed to generate the levels randomly, and fill in the pixels accordingly.

I would like to change pixels individually, since this way, I only can change the pixels that have to be changed, which seems to me to be the most efficient way.

What would be the fastest way in which I could achieve individual pixel updating/changing?

I have tried Pixmaps but they seem to be very slow and in order to draw them as far as I could find you have to create a new texture from the pixmap for every frame.

Drawing each 'pixel' as a square texture also seems to be a very inefficient way.

Does java/Libgdx have a 'fast' way of doing this?

I also saw a lot of people in other Posts recommending to use bufferedimage from the Java2D library. However, I am not sure if this can be combined with Libgdx functions and textures, which I will need for some entities. As far as I could see it requires you to use a Java2D graphics window.

Can you still use some textures in java2D?

\$\endgroup\$
  • \$\begingroup\$ this approach doesn't scale well, because there are high-DPI displays nowadays and they are getting increasingly more dense \$\endgroup\$ – Sarge Borsch Oct 17 '16 at 6:53
1
\$\begingroup\$

I just post this here as i don't have enough reputation to comment; maybe you could use GL_POINTS when doing a

glBegin(GL_POINTS);

if you use Libgdx (which is more or less based on OpenGL) ? Note this is just an hypothesis here.

Hope it helped :)

EDIT : Sarge Borsch who commented under is right. You shouldn't use the fixed function pipeline technique I suggested above, but, when rendering with VBOs and VAOs, you should do something like this :

glDrawArrays(GL_POINTS, 0, size);

with size being the number of vertices you draw (36 in the case of a cube without using indices).

\$\endgroup\$
  • \$\begingroup\$ I'll have a look into it \$\endgroup\$ – dragonfly Oct 16 '16 at 20:10
  • \$\begingroup\$ This seems to be vector based though. It may work, but I'm not sure how well optimised it is. \$\endgroup\$ – dragonfly Oct 16 '16 at 20:12
  • \$\begingroup\$ Well, it should be the fastest way to render anything to your screen (except if you use VBOs) with LWJGL, though I have never made a speed test with both techniques :) \$\endgroup\$ – cocosushi Oct 16 '16 at 20:14
  • 1
    \$\begingroup\$ please do not suggest using fixed function pipeline to people. it's deprecated (even removed from OpenGL ES 2+) and inefficient. \$\endgroup\$ – Sarge Borsch Oct 17 '16 at 6:56
  • 1
    \$\begingroup\$ Java isn't slow. \$\endgroup\$ – Jacob Nov 26 '16 at 8:01

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.