Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Before using LWJGL, I used the Graphic method, and there I displayed imageicons, and I had the picture file located in the resources. I used:

ImageIcon tcard = new ImageIcon(this.getClass().getResource("RCA.png"));

to load the image.

Now when I load textures in LWJGL, I have to use absolute paths to locate the file:

tcard = TextureLoader.getTexture("PNG",  ResourceLoader.getResourceAsStream("C:/RCA.png"));

I tried Googling, but I didn't find anything helpful. How can I load the image from the local resources like in the first example?

share|improve this question
up vote 3 down vote accepted

You can use the class file you're running your code in as a reference. So if you have the file RCA.png in the root directory you would use:

tcard = TextureLoader.getTexture("PNG", this.getClass().getResourceAsStream("RCA.png"));

Or if you were to have it inside an art directory in the root you would use:

TextureLoader.getTexture("PNG", this.getClass().getResourceAsStream("/art/RCA.png"));
share|improve this answer
It works! Thanks! – DLabinac Aug 28 '12 at 5:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.