Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  Easy way to load a texture in LWJGL?  (Read 6687 times)
0 Members and 1 Guest are viewing this topic.
Offline CyanPrime
« Posted 2009-12-24 18:55:23 »

Okay, so now that devIL isn't supported anymore it seems I'm expected create my own texture loader (I didn't have to do this in JOGL!), so I was wondering if there was a easier way to load a texture (.png). Thanks in advance.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 51
Projects: 15


★★★★★


« Reply #1 - Posted 2009-12-24 19:06:26 »

Fmod and Devil were both removed for LWJGL2+, the recommended replacement is a library called slick-util (note different from slick2d). You should be able to load various texture and sound formats with it.

you can get it from http://slick.cokeandcode.com/downloads/util/ and the javadoc is located at http://slick.cokeandcode.com/javadoc-util/

Its pretty easy to use, just download the package and have a look at the examples included in the source code on how to use it.
Offline indexunknown

Junior Member





« Reply #2 - Posted 2009-12-24 19:14:13 »

int textureID = TextureLoader.getTexture(".PNG",this.getClass().getClassLoader().getResourceAsStream("image.png"),true).getTextureID();
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CyanPrime
« Reply #3 - Posted 2009-12-24 19:35:35 »

Thank you very much. I'm now using Slick ^_^
Problem when I use textures though Sad


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
 texture.bind();
       
        GL11.glBegin(GL11.GL_QUADS);
        // Front Face
          GL11.glTexCoord2f(0.0f, 0.0f);
           GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
          GL11.glTexCoord2f(1.0f, 0.0f);
           GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
          GL11.glTexCoord2f(1.0f, 1.0f);
           GL11.glVertex3f(1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
          GL11.glTexCoord2f(0.0f, 1.0f);
           GL11.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
       GL11.glEnd();    
Offline indexunknown

Junior Member





« Reply #4 - Posted 2009-12-24 19:39:41 »

that's a non power of two texture i think.
Offline CyanPrime
« Reply #5 - Posted 2009-12-27 23:35:43 »

So I'm trying to get a tech demo out of Ultra GL as a JWS App, and for some reason the TextureLoader from Slick-Util doesn't want to see my .png from inside the  jar file. Here's the code.

1  
2  
3  
4  
5  
try {
         texture = TextureLoader.getTexture("PNG", new FileInputStream("data/wall.png"));
      } catch (IOException e) {
         e.printStackTrace();
     
Offline lhkbob

JGO Knight


Medals: 32



« Reply #6 - Posted 2009-12-27 23:52:07 »

You need to do:
1  
texture = TextureLoader.getTexture("PNG", this.getClass().getClassLoader().getResource("data/wall.png").openStream());


This should work, or be very close to something that works.  You need to use getResource() to easily fetch resources that are inside jars.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 439
Projects: 4


Hand over your head.


« Reply #7 - Posted 2009-12-29 13:48:32 »

Actually, for (old, bugged versions of?) Java WebStart you need to do:

Thread.currentThread().getContextClassLoader().getResourceAsStream("abc/def/Ghi.jkl");

This works everywhere.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #8 - Posted 2009-12-29 16:58:27 »

If you are using Slick, you can use:
1  
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResource("data/wall.png"));

This will find it both in the classpath and on the filesystem.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (147 views)
2013-05-17 21:29:12

alaslipknot (154 views)
2013-05-16 21:24:48

gouessej (185 views)
2013-05-16 00:53:38

gouessej (179 views)
2013-05-16 00:17:58

theagentd (189 views)
2013-05-15 15:01:13

theagentd (174 views)
2013-05-15 15:00:54

StreetDoggy (217 views)
2013-05-14 15:56:26

kutucuk (242 views)
2013-05-12 17:10:36

kutucuk (240 views)
2013-05-12 15:36:09

UnluckyDevil (246 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.109 seconds with 21 queries.