views:

227

answers:

2

Hello,

So I have what is essentially a game... There is terrain in this game. I'd like to be able to create a top-down view minimap so that the "player" can see where they are going. I'm doing some shading etc on the terrain so I'd like that to show up in the minimap as well. It seems like I just need to create a second camera and somehow get that camera's display to show up in a specific box. I'm also thinking something like a mirror would work.

I'm looking for approaches that I could take that would essentially give me the same view I currently have, just top down... Does this seem feasible? Feel free to ask questions... Thanks!

+1  A: 

Well, I don't have an answer to your specific question, but it's common in games to render the world to an image using an orthogonal perspective from above, and use that for the minimap. It would at least be less performance intensive than rendering it on the fly.

Nali4Freedom
+3  A: 

One way to do this is to create an FBO (frame buffer object) with a render buffer attached, render your minimap to it, and then bind the FBO to a texture. You can then map the texture to anything you'd like, generally a quad. You can do this for all sorts of HUD objects. This also means that you don't have to redraw the contents of your HUD/menu objects as often as your main view; update the the associated buffer only as often as you require. You will often want to downsample (in the polygon count sense) the objects/scene you are rendering to the FBO for this case. The functions in the API you'll want to check into are:

  • glGenFramebuffersEXT
  • glBindFramebufferEXT
  • glGenRenderbuffersEXT
  • glBindRenderbufferEXT
  • glRenderbufferStorageEXT
  • glFrambufferRenderbufferEXT
  • glFrambufferTexture2DEXT
  • glGenerateMipmapEXT

There is a write-up on using FBOs on gamedev.net. Another potential optimization is that if the contents of the minimap are static and you are simply moving a camera over this static view (truly just a map). You can render a portion of the map that is much larger than what you actually want to display to the player and fake a camera by adjusting the texture coordinates of the object it's mapped onto. This only works if your minimap is in orthographic projection.

charstar
Would using multiple viewports also work? Can I render polygons to the frame buffer? Obviously I'm pretty noob to graphics programming haha.
Polaris878
Yes, you can draw to an FBO in exactly the same way that you draw normally in your window's frame buffer (the same as rendering to the back buffer before swapping with the front buffer). You can use different gluPerspective/gluLookAt's in each FBO. The benefit is that you don't have to redraw in the FBO if you don't need to for the current frame, the FBO can be of any dimensions, and it's very fast when used for textures as you don't need to use a glCopyTexImage. You can create many FBOs and switch between them with glBindFramebufferEXT (0 binds the window's framebuffer that your used to).
charstar