Archived

This topic is now archived and is closed to further replies.

eldee

2D Tile engine and OpenGL

Recommended Posts

eldee    122
hey guys, im planning on writing somewhat of a 2d tiling engine in OpenGL, and i was wondering about some of the concepts.. so far, this is what i''ve got: am i correct to assume that i should make a quad for each tile (including ones on other layers)? also- lets say my tileset is 256x1024.. since it is much larger than 256x256, i''d need to split it up somehow.. would an efficient way to do this be to create a new 256x256 quad offscreen for each block of the tileset? or is there a better way? the other method i thought of: i suppose at runtime i could initiallize it into an array.. ie.. 256x1024 would be 256 tiles.. so i could do texture[(width * height) / 32] whats the best way to go about doing this? i checked out nehe''s tuts and 21 was the most helpful.. but it didnt have anything about textures.. -eldee ;another space monkey;

Share this post


Link to post
Share on other sites
ATronic    122
I''m not too good with this stuff, but I''d use triangle strips instead of quads for each tile. That''s all I got.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
eldee    122
are triangles faster?
how would i go about rendering 1/2 of a texture on one side and the other half on the other?
heh.. i got some more reading to do

-eldee
;another space monkey;

Share this post


Link to post
Share on other sites
merlin9x9    174
Well, quads are broken into triangles by the driver or hardware which can have a performance hit, but so do the extra function calls to draw quads with triangles explicitly. ATronic is right about triangle strips, though, since they require lots less data to be sent, which means less function calls, less memory, and easier processing in the hardware. But they can be tricky to set up. But for a tile-based game, quads are fine.

Share this post


Link to post
Share on other sites
merlin9x9    174
I'd probably store as many tiles as you can in 256x256 images, each of which will get loaded to its own texture. This is less than ideal since most hardware these days can handle larger than that and it's best to have bigger images than lots of tiny ones, but this saves you lots of headache. You'll, of course, need to store information about all of your tiles such as which texture they're on and at which position. If you're really brave, though, the best thing might be to load as many images as you can into as many large textures as you need (use glGetIntegerv with GL_MAX_TEXTURE_SIZE ), but that's probably overkill, so just use 256x256 textures.

Edited by - merlin9x9 on January 9, 2002 12:51:15 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If each tile is 256x256, then you could string them all together in one big bitmap, and then use gltexcoord2d() to split it up.

Quads are fine, and if you do not have allot of triangles that use the same texture, then you can end up with a mess

Check out one of the font tutorials on NEHE, as you can see, all the fonts are in 1 bitmap, and.. well, you will get the picture.

Share this post


Link to post
Share on other sites
eldee    122
yeah, i dont think quads will slow the game down at all
you figure a screen w/ 32x32 tiles on a 640x480 resolution
will only have 300 quads (per layer) drawn at a time...
assuming i dont have a buffer layer... add 70 more quads for a 1
tile buffer layer around the edge of the screen...
dont think that''ll decrease performance...

-eldee
;another space monkey;

Share this post


Link to post
Share on other sites
iplayfast    122
I''m the developer of Jedi-IsoAx (currently in revision for Version 2). You can use that as a basis for yours if need be or join JEDI-IsoAx at sourceforge to contribute to this project. For a quick download you can get the engine and a small test file at http://groups.yahoo.com/group/JEDI-IsoAxEE/files/
file is called isoengine2.zip


Share this post


Link to post
Share on other sites