2D - Restricted to appying sprite textures to shapes?

In LWJGL, the only way to go about getting a sprite on the screen is applying the texture to a shape, then showing the shape on the screen? Is there any way to just cut out the middleman and get the sprite on the screen? Just seems sort of strange, you have to worry about getting the actual proportions of the texture equal to the shape and everything.

Also, since the sprite is usually small(32 by 32 pixels or so), how do you make it so that it doesn’t appear small on the screen? Changing glOrtho wouldn’t change the size of the pixels I don’t think, just make the area you can view the pixels smaller on the screen.

Please correct me if any of the information above is incorrect or strange, I’m not quite familiar with some of these ideas.

Ah look here: http://www.java-gaming.org/topics/how-to-draw-gui/25826/msg/224139/view.html#msg224139

The question isn’t quite the same, but the answer may help you. If you want to just do 2D graphics, you might want to try looking at Slick2D as well.

He’s loading the textures with Slick? Isn’t there a way to do that with just LWJGL without Slick2D

Yes, by implementing your own texture Loader :slight_smile:

There is also a neat Slick-Util jar, which implements various classes to load images and playing music.

MatthiasM has written some extremely awesome texture loaders spun off from TWL that don’t require TWL itself. It supports BMP, JPG, PNG, and TGA (no GIF that I can see). It’s asynchronous, so you get a callback when the texture is loaded and you can keep on doing your own thing in the meantime (like displaying a loading screen or downloading other resources) without having to manage any threads.

http://hg.l33tlabs.org/TextureLoader/

Well - it supports 3 modes of operations:

  • fully managed by using the TextureManager.getTexture() function - this one is asynchronous (eg loads in a background thread)
  • synchronous using Texture.loadTexture() function
  • using the TextureLoader* classes to get the bytes directly

The asynchronous TextureManager method will render a transparent 2x2 pixel texture when the desired texture has not yet (or could not) been loaded.
Textures which are not used for some time are also unloaded.

And there is no need to manage threads - the only thing you need to do in your main loop when you want to use the TextureManager is:

// before main loop
AsyncExecution async = new AsyncExecution();
TextureManager tm = new TextureManager(async);
...
// main loop
while(!Display.isCloseRequested()) {
   ...
   async.executeQueuedJobs();
   tm.nextFrame();
   ...
   Display.update();
}

Thanks, that looks like a good place to start. Do you know where I can find a tutorial on how to add the TextureLoader to my project? Is it like a library?

But how? What would I use to get the PNG file into something I can code with? Wouldn’t using bufferedimage or awt would be kind of counter-intuitive, since I’m using LWJGL anyway? I don’t know what to use to get the image, is there some sort of way to do it in LWJGL or OpenGL?

You can find a ZIP of Matthias’ library here:
http://hg.l33tlabs.org/TextureLoader/archive/tip.zip

Then you can simply import the Texture class and use the static Texture.loadTexture method.

If you are looking to write your own texture handler (say, for practice), look here:

OpenGL does not provide any way of loading image files directly from disk. It knows nothing about image file formats, only pixel data. So no matter what programming language you use, you need to load the image file into memory first yourself, extract the relevant pixel data (dimensions, color depth & format, and the actual pixel values) then pass it all on to OpenGL through its texture creation interface. So, no, in Java, using a BufferedImage is not counter-intuitive.