Fast Tile Map Rendering in Slick

(1/3) > >>

Miltage:
Hi guys, what's the fastest way to render a large amount of tiles onto the screen using Slick?
In my game I have huge worlds which, when zoomed out, means that there are hundreds of tiles on screen at any given time.

At first, I drew every tile at its location on every frame, and my frame rate dropped to 1 - 2 fps.
So I tried drawing only the tiles that are on the screen, and the game would only drop to 30fps when viewed on the furthest zoom level.

Lastly, I tried drawing all the tiles onto a buffer image, then drawing that buffer image to the screen every frame, however, the world size is too big to incorporate into a single image.
So I tried creating a buffer image for just the tiles on the screen, and I'd get a wait time of about 2 seconds at the beginning, but then everything ran smoothly.
What use will this be though, if I have to update the buffer image every time the player scrolls and more of the world is revealed? I was hoping to create just one big image of the world that I can move on the x/y axis when the player moves.

In the future, I plan to include a line of sight method to only draw the tiles in the player's line of sight, so that will probably fix my problem, but does anyone have any tips on drawing many things on the screen at once?

Thanks for your help!

theagentd:
A simple way to give you faster culling is to divide the world into sections (maybe 8x8 to 32x32), checking the visibility of the sections and drawing the whole section with a single command as a display list or using glDrawArrays or something. This should give you good enough performance.

If you want to use more advanced OpenGL 3 commands, you can use a 2D texture array for the tiles and a shader to do a dependent texture lookup per fragment to place tiles. This allows you to draw a single gigantic quad over the whole map (or at least a very very large section of the map) and the tiles will be placed automatically. Only 4 vertices to process, cull and clip for the GPU and only a single draw command (or at least very few) for the CPU.

Miltage:
Thanks for the tips. Unfortunately, I am unfamiliar with OpenGL, which is why I am using Slick2D to draw my images. I guess I better learn how to do it the proper way if I want to optimize the performance of my game though.

theagentd:
I have almost no knowledge at all about Slick2D. However, the problem is the same no matter what library you use to render tiles: When zooming out, you will need to draw lots of small tiles, maybe even pixel-sized. This is very tough on both the CPU and GPU, as the CPU has to instruct the GPU to draw all the small tiles, and GPU has to render lots of very small quads. I don't know exactly how Slick draws tiles under the hood, but maybe you could just wrap the drawing in a display list and call it later, but that might break functionality...

Anyway, if you're ready to experiment with display lists:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
//When starting the game (run once)

int displayList = GL11.glGenLists(1); //Save this int so you can access it later
GL11.glNewList(displayList, GL11.GL_COMPILE);
//Draw the tiles using Slick
GL11.glEndList();


//When rendering, instead of drawing things with SLick

GL11.glCallList(displayList);

Cero:
Slick renders each single tiny images/sprite/tile as one quad, texture binds it, draw a quad, unbinds it - and stuff
way to slow for tilemaps
so you pretty much have to use something like vertex arrays, vbos, display lists - whatever

I guess there is also a slick.tiled.TiledMap in Slick, which I have never used - but its for use with a map created with the "TilED" map editor

so even rendering spritesheet.renderInUse or something, its still the same deal

you gotta write it yourself in Slick pretty much - this is why I often said Slick is nice, but if you wanna do bigger stuff, it will also frustrate you

fortunately my guys know their OpenGL and after a couple of weeks or trying different methods we are now using the VBO extension which works with GL1.2 I believe

again, you pretty much need to do some OpenGL at least
its really not all that difficult, or much lines of code - since you can still use everything else Slick is offering, and only change your TileMap
and you will get a speed boost by at least a factor of 10.

Navigation

[0] Message Index

[#] Next page