Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Drawing a tiled map  (Read 5297 times)
0 Members and 1 Guest are viewing this topic.
Offline wmjoers

Senior Newbie




Nobody can be uncheered with a balloon.


« Posted 2005-06-18 21:09:53 »

Hi,
What's the best way of drawing a scrolling tiled map in LWJGL (OpenGL)?

Should I use the bitmap methods?
Should I  use one textured rectangle per tile?
Should I use one large textured rectangle and draw the tiles to its texture?

* The tiled map is going to be scrolled.
* It can be a quite large map.
* Separate tiles can be animated.

Are there any examples?
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2005-06-18 21:42:42 »

- Sprites are best done with textured quads, the bitmap drawing methods are far too slow and unflexible.
- Sprite animation then means just switching which texture you're using
- Sort your drawing by texture to minimise texture binds
- Further improve the above by packing multiple sprites/tiles into one larger texture

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline wmjoers

Senior Newbie




Nobody can be uncheered with a balloon.


« Reply #2 - Posted 2005-06-19 08:32:11 »

- Sprites are best done with textured quads, the bitmap drawing methods are far too slow and unflexible.
- Sprite animation then means just switching which texture you're using
- Sort your drawing by texture to minimise texture binds
- Further improve the above by packing multiple sprites/tiles into one larger texture

Thanks for you answer.

But my question wasn't really about sprites. It was about using a tiled map as a background.
I want to build up my level backgrounds using tiles.

Any ideas of that issue?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2005-06-19 16:05:34 »

Tiles are sprites, just a somewhat special case as they don't usually move and are the same dimensions.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline wmjoers

Senior Newbie




Nobody can be uncheered with a balloon.


« Reply #4 - Posted 2005-06-19 20:17:58 »

Tiles are sprites, just a somewhat special case as they don't usually move and are the same dimensions.

You are, of course correct. Tiles are in most ways identical to sprites.   Smiley
And when I re-read your tips with that in mind it all made sense.
I'm just sort of stuck in the Java2D thinking. *sorry*

I also found a nice little example on how to make <a href="http://www.gamedev.net/reference/articles/article1256.asp">tiled maps in OpenGL</a> which made it even more clear.

A question though: How expensive is a texture binding? Do I save a lot of time by trying to minimize the number of bindings?

Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2005-06-19 21:52:51 »

Texture binding is the most expensive operation in OpenGL. Always sort where possible. Tilemaps are great though because lots of little tiles fit on one big texture.

Cas Smiley

Offline wmjoers

Senior Newbie




Nobody can be uncheered with a balloon.


« Reply #6 - Posted 2005-06-19 22:21:09 »

Texture binding is the most expensive operation in OpenGL. Always sort where possible. Tilemaps are great though because lots of little tiles fit on one big texture.

What do you mean by "...lots of little tiles fit on one big texture..."?
Should I load one texture that contains all tiles?
... or should I draw the level map to a texture and then just draw one rectangle which is bind to that texture?

Sorry if the questions are rather stupid but I'm just starting to dig in to OpenGL .

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #7 - Posted 2005-06-19 22:47:17 »


I also found a nice little example on how to make <a href="http://www.gamedev.net/reference/articles/article1256.asp">tiled maps in OpenGL</a> which made it even more clear.
Wow, thats about the most inefficient way of doing a tile map in OpenGL ever. Shocked

- Always try and avoid immediate mode (glBegin(*) etc.) unless you're doing really simple stuff.
- It uses glBegin/end in a really tight loop, which is horrible. At the very least you could move the glBegin outside the loop (except that this breaks its method of texturing)
- It doesn't sort by texture, so you get a bind per tile (ouch!).
- One texture which contains all tiles is the way to go. Then just tinker with the texture coords to get the correct tile out of it.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline wmjoers

Senior Newbie




Nobody can be uncheered with a balloon.


« Reply #8 - Posted 2005-06-19 23:01:21 »

- One texture which contains all tiles is the way to go. Then just tinker with the texture coords to get the correct tile out of it.

Allright, this I can understand (I think).   Wink

So what you do is this...
1. bind your one-large-texture-containing-all-tiles
2. draw all visible tiles but change the texture coords for each tile so that the correct tile is drawn.

Do I need to sort the drawing order when using this tech as well or is the tinkering with texture coords unexpensive?

Are there any examples out there using this technique?
Offline tom
« Reply #9 - Posted 2005-06-20 00:05:19 »

- One texture which contains all tiles is the way to go. Then just tinker with the texture coords to get the correct tile out of it.
Do I need to sort the drawing order when using this tech as well or is the tinkering with texture coords unexpensive?
Only if you can't fit all tiles on one texture. Then you still need to sort or you might end up switching between two textures wich is just as bad.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2005-06-20 09:31:57 »

These days you can aim for a 1024x1024 tile texture, and if your tiles are, say, 32x32, that's a total of 1024 different tiles just in one texture! Even in the rare occasion you need to swap textures, your tile textures only take up 3MB of VRAM, so you're likely to be able to fit at least 2 in VRAM at a time (that's the main cost - uploading a texture if it isn't in the VRAM cache). So if you had, say, 2048 different tiles in your game (I'd be impressed if you did!), you'd have at most just two texture binds per frame to draw the lot if you sorted them correctly.

Cas Smiley

Offline wmjoers

Senior Newbie




Nobody can be uncheered with a balloon.


« Reply #11 - Posted 2005-06-20 18:03:01 »

Thanks for all you help!

Next thing I must learn i how to configure the viewport and other things to get the graphics pixel aligned.

But I think I did see some thread about this matter? Or maybe you guys have a good snipplet just waiting to get posted as a response to this question?  Wink


Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #12 - Posted 2005-06-20 19:10:54 »

The default LWJGL display is already setup with opengl units corresponding to pixels. If you need to do it manually you need a glOrtho call, IIRC: glOrtho(0, 0, width, height, -z, +z);

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline DanDanger

Innocent Bystander




Java games rock!


« Reply #13 - Posted 2005-07-22 20:17:26 »


Hello,

Here is some code for drawing a scrolling tiled map. I used it in my "Keith Goes Painting" game, I hope you find it usefull.

I found that using a single texture, with all your tiles on, led to some texel bleeding from neighbouring tiles.
I fixed that problem by reducing the floating point resolution that the map could be drawn at, using this code:

            displayPosX -= displayPosX%0.1f;
            displayPosY -= displayPosY%0.1f;

I then called the map drawer stuff in the attached file.


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.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (56 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (46 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!