Loading Images with slick.util

Started by PinkieSwirl, February 10, 2012, 22:46:13

Previous topic - Next topic

PinkieSwirl

When i call Display.update() it needs somthing about 17 milliseconds (more specific the swapBuffer method), so my game runs hardly at 60 frames/sec (the rest of the gameloop just needs max 2 milliseconds). That seems a bit slow?

Second question: I use the slick.utils for png loading.

TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(ref), false, GL_LINEAR);


but it does not seem to save the textures? The loading time for a small png is about 13 ms. So i saved them myself in an array and preload every texture, so the loading time is about 0 ms.

Did i something wrong?

EDIT:
For the first question: I found out, when i disable vsync, the Display.update() call needs about 1 ms, but the movement looks laggy then (ervery second is a short lag).
So, is my videocard broken? Or is this a bug?

EDIT2:
Ah, my display runs at 60 Hz, so thats why vsync cuts it to 60 fps xD
But question 2 is still there :D

CodeBunny

I'm a little confused by how you load your images - can you show your code, please?

PinkieSwirl

public Sprite(String ref) {
		try {
			texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(ref), false, GL_LINEAR);
			width = texture.getImageWidth();
			height = texture.getImageHeight();
		} catch (IOException ex) {
			Logger.getLogger(Sprite.class.getName()).log(Level.SEVERE, null, ex);
		}
	}


The TextureLoader, RescourceLoader and Texture class are from slick.util

CodeBunny

What happens when you try to render with the texture?

PinkieSwirl

The same xD

It looks like this:
Resources/Images/black.png 12
Resources/Images/b_up_left.png 10
Resources/Images/b_up.png 9
Resources/Images/b_up_right.png 10
Resources/Images/b_left.png 10
Resources/Images/b_right.png 10
Resources/Images/b_down_left.png 10
Resources/Images/b_down.png 10
Resources/Images/b_down_right.png 9
Resources/Images/b_up_left.png 10
Resources/Images/b_up.png 11
Resources/Images/b_up_right.png 12
Resources/Images/b_left.png 10
Resources/Images/b_right.png 13
Resources/Images/b_down_left.png 10
Resources/Images/b_down.png 10
Resources/Images/b_down_right.png 10
Resources/Images/b_up_left.png 13
Resources/Images/b_up.png 12
Resources/Images/b_up_right.png 10
Resources/Images/b_left.png 11
Resources/Images/b_right.png 10
Resources/Images/b_down_left.png 11
Resources/Images/b_down.png 18
Resources/Images/b_down_right.png 10

First comes the images which gets loaded then the time it needed in ms. As you can see, all b_... are used more than once, but every time it needs about 10 ms to load the image. (i dont know how to implement something like spritebatches yet, thats why there are so much b_... images).

EDIT:
I hope i understood you right ~

CodeBunny

I was mainly asking if anything showed up when you attempted to use the images; it seemed like you were saying that loading failed.

However, I think what you're doing is creating a new texture instance every time you create a sprite. Since you have the texture loading call in your constructor, every instance will have to load the entire texture from memory.

If that's the case, you're going to want to initially load all used textures into a data structure at program startup, and then have the Sprites access the texture cache to find the textures they'll use.

PinkieSwirl

mh, i thought the TextureLoader class should handle this ~~

and some times the loading time for a image is 0/1 ms, but for 6 images only, then back to ~10 or more. Thats why i was wondering... ^^

But thank you for your help :)