Jump to content
  • Advertisement
Sign in to follow this  
Mokkan

OpenGL OpenGL Tilemap Questions

This topic is 4590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I'm pretty new at OpenGL, but I've sort of gotten the basics down, I would say :). I'm trying to write an tilemap engine using SDL and OpenGL, but I'm having a few problems... I was hoping someone here might be able to help. Firstly, are there any easy ways to implement a 'camera' (/viewport?) of sorts? I know OpenGL doesn't really have a camera... but that gluLookAt works like one. I can't seem to get gluLookAt to work with glOrtho... but I think that perhaps it's not supposed to work. Anyways, does anybody have any ideas on this? Second, how do I go about rendering the tilemap? I understand the whole textured quads thing, but I'm kind of confused on how much is safe to render. What I mean is, what if I have a very big tilemap to render? Something like... 500 by 500 tiles. Do I render it only chunks at a time? Or render the whole thing and use the camera/viewport thingy? And this tile engine sort of works using a different tilemap per area... it's not just one big map for the whole world ;P. And I think that's kind of it :). Hopefully I'm not being too n00bie here... and that I explained well enough. Thanks! :)

Share this post


Link to post
Share on other sites
Advertisement
Map the screen space into your virtual world space, and only render tiles from the world that intersect with the screen.

A camera in ortho mode is most easily implemented by just using glTranslatef().

Share this post


Link to post
Share on other sites
Okay, now after some thinking, I completely understand on how to make a camera now :).

I'm still trying to figure out how to go about rendering, though... I understand the concept, but I'm just not sure how to go about it, really :\. Well, perhaps after some more thinking I'll get it...

Thank you for the help :). If anyone's got any more to say about rendering, I'd be glad to hear it...

Share this post


Link to post
Share on other sites
As you've already figured out, the first step is probably to only draw what's onscreen, which should be fairly straightforward in a top-down ortho environment.

The most straightforward way to render the tiles themselves would be to just render a quad (or triangle fan) for each one. If you wanted to optimize a bit you could (as a preprocessing step, or at run time) identify rectangular blocks of tiles that use the same texture and render them as a single quad. You could also sort the visible tiles by texture to minimize texture state changes. If you do this though, you might make it a run-time switchable option so that you can find out if you're losing more time to sorting than you're gaining from minimizing state changes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mokkan
Second, how do I go about rendering the tilemap?


I have an article(includes the link for my GD post) on one way to go about doing this. The general approach is to have your big sprite sheet that you load as a texture, then for each corner of your quad, bind the corner of the chunk you want, then draw the quad. I have an example on there that you can follow to see it in action. I'm not sure this is the best or most efficient way, but I do know it worked great for me, both 2D and 3D. Good luck and don't be afraid to try something new or different! [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!