Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 8:42 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Combining images
PostPosted: Mon Mar 19, 2012 7:43 pm 
Offline

Joined: Sun Oct 16, 2011 8:31 pm
Posts: 50
How do I go about combining roughly 3000-9000 small (32*32) small images together, into one image?
The source is an Image[w][h];
It's much appreciated!


Top
 Profile  
 
 Post subject: Re: Combining images
PostPosted: Mon Mar 19, 2012 8:33 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
You shouldn't combine them into a single texture/image for it would be too large for the driver. 2048x2048 should be a maximum single texture size to aim for, or lower for older systems (512x512 is safest). You can query the driver's max texture size with BigImage.getMaxSingleImageSize().

It's not hard to combine images into a single question, but there is most likely a better way of doing whatever you're attempting.

Why do you need to combine that many small images together? Why do they need to be in a single image (i.e. instead of rendered as tiles)? Do you actually have 3000-9000 different images, or are you simply repeating them (thus wasting memory and texture space)? Do you plan to save/export this image or are you simply using it for rendering in-game?


Top
 Profile  
 
 Post subject: Re: Combining images
PostPosted: Mon Mar 19, 2012 9:01 pm 
Offline

Joined: Sun Oct 16, 2011 8:31 pm
Posts: 50
Well it's too costly to render all of these tiles at once, and I'm honestly unsure how to render just the tiles around the player, that would probably a better alternative actually. Well there's usually 3000-9000 tiles (since I have a reasonably large randomly generated map). There's only going to be roughly 10 different tile images, but these will be repeated lots of time etc.

I'm just looking for a faster alternative to render the tiles :)
Thanks, Harry.


Top
 Profile  
 
 Post subject: Re: Combining images
PostPosted: Mon Mar 19, 2012 10:24 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
  • Use a texture atlas -- this is the first thing every sprite-based game should do -- then startUse to "begin" rendering and endUse to "end" rendering. In between, call drawEmbedded (or renderInUse if you're using the SpriteSheet class)
  • Don't draw images if they are not within the bounds of the display.
  • If you really need to push more performance into your game (which should be unnecessary since it's just a simple tile map) you can look here for starters. But honestly your problem can be easily solved with texture atlases and careful rendering. ;)


Top
 Profile  
 
 Post subject: Re: Combining images
PostPosted: Tue Mar 20, 2012 7:55 am 
Offline

Joined: Sun Oct 16, 2011 8:31 pm
Posts: 50
What exactly is a texture atlas? Is it just an image/spritesheet of lots of iamges? Why do you begin/end with it?

I need to figure out how to do that, because I have an offsetX and an offsetY and no real way of knowing which tile I'm on, unless I do a loop through every tile checking for a hitbox, since mathematically it doesn't seem very easy/possible.


Top
 Profile  
 
 Post subject: Re: Combining images
PostPosted: Tue Mar 20, 2012 9:05 am 
Offline
Regular
User avatar

Joined: Thu May 05, 2011 8:35 pm
Posts: 231
Location: Somewhere between the bits and bytes
Harry wrote:
What exactly is a texture atlas? Is it just an image/spritesheet of lots of images? Why do you begin/end with it?

That is exactly what it is.

The begin/end stuff is needed due to the way openGL works, normally you need to tell it when to start a task and when to end it, these operations is a bit expensive and a waste if you are drawing the same image many times, such as when drawing the sub-Images of a texture atlas, where you draw the parts of an image.

When you draw your image with the normal draw method, it tells openGL to start and end the task of drawing the image every time its drawn.

drawEmbedded doesn't call the begin and end methods, so when you beginUse/drawEmbedded/endUse you control yourself when to tell openGL to start and end the task.

Here's an example of what happens.
This code:
Code:
image.draw(x, y);
image.draw(x, y);
image.draw(x, y);

Is the same as this:
Code:
image.beginUse()
image.drawEmbedded(x, y)
image.endUse()
image.beginUse()
image.drawEmbedded(x, y)
image.endUse()
image.beginUse()
image.drawEmbedded(x, y)
image.endUse()

But if you control it yourself, it could look like this:
Code:
image.beginUse()
image.drawEmbedded(x, y)
image.drawEmbedded(x, y)
image.drawEmbedded(x, y)
image.endUse()

This way is faster, especially if you are drawing the image alot of times.

_________________
For every new problem, a new source of solutions has come to exist.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group