Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D - Restricted to appying sprite textures to shapes?  (Read 2695 times)
0 Members and 1 Guest are viewing this topic.
Offline Glass

Senior Newbie





« Posted 2012-02-24 04:59:16 »

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.
Offline UprightPath
« Reply #1 - Posted 2012-02-24 05:19:49 »

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.

Offline Glass

Senior Newbie





« Reply #2 - Posted 2012-02-25 23:01:56 »

He's loading the textures with Slick? Isn't there a way to do that with just LWJGL without Slick2D
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline R.D.

Senior Duke


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #3 - Posted 2012-02-25 23:58:07 »

Yes, by implementing your own texture Loader Smiley

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

JGO Kernel


Medals: 202



« Reply #4 - Posted 2012-02-26 01:53:14 »

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/
Offline Matthias

Senior Duke


Medals: 3
Projects: 1


TWL - Themable Widget Library


« Reply #5 - Posted 2012-02-26 08:35:45 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
// before main loop
AsyncExecution async = new AsyncExecution();
TextureManager tm = new TextureManager(async);
...
// main loop
while(!Display.isCloseRequested()) {
   ...
   async.executeQueuedJobs();
   tm.nextFrame();
   ...
   Display.update();
}
Offline Glass

Senior Newbie





« Reply #6 - Posted 2012-02-26 16:43:52 »

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?

Yes, by implementing your own texture Loader Smiley

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?
Offline davedes
« Reply #7 - Posted 2012-02-27 08:45:59 »

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:
http://www.java-gaming.org/topics/painless-way-of-loading-textures/25856/msg/224562/view.html#msg224562

Offline aldacron

Senior Duke


Medals: 9
Exp: 16 years


Java games rock!


« Reply #8 - Posted 2012-02-27 11:44:39 »

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?

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (37 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (43 views)
2014-10-26 19:37:11

Luminem (24 views)
2014-10-26 10:17:50

Luminem (29 views)
2014-10-26 10:14:04

theagentd (35 views)
2014-10-25 15:46:29

Longarmx (63 views)
2014-10-17 03:59:02

Norakomi (61 views)
2014-10-16 15:22:06

Norakomi (50 views)
2014-10-16 15:20:20

lcass (46 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!