Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 8918 times)
0 Members and 1 Guest are viewing this topic.
Offline CyanPrime
« Posted 2009-12-24 17: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: 81
Projects: 15


★★★★★


« Reply #1 - Posted 2009-12-24 18: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 Devvie





« Reply #2 - Posted 2009-12-24 18: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 18: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 Devvie





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

that's a non power of two texture i think.
Offline CyanPrime
« Reply #5 - Posted 2009-12-27 22: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 22: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: 847
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-12-29 12: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
Offline Nate

« JGO Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2009-12-29 15: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.

 

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

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (24 views)
2014-12-23 03:34:11

rwatson462 (53 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (85 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (79 views)
2014-12-05 12:39:02

SHC (89 views)
2014-12-03 16:27:13

CopyableCougar4 (96 views)
2014-11-29 21:32:03

toopeicgaming1999 (155 views)
2014-11-26 15:22:04

toopeicgaming1999 (152 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!