简体   繁体   English

OpenGL中的地形小地图?

[英]Terrain minimap in OpenGL?

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! 随时提出问题...谢谢!

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. 一种方法是创建一个附加了渲染缓冲区的FBO(帧缓冲区对象),向其渲染您的小地图,然后将FBO绑定到纹理。 You can then map the texture to anything you'd like, generally a quad. 然后,您可以将纹理映射到任何想要的东西,通常是四边形。 You can do this for all sorts of HUD objects. 您可以对各种HUD对象执行此操作。 This also means that you don't have to redraw the contents of your HUD/menu objects as often as your main view; 这也意味着您不必像主视图那样频繁地重绘HUD /菜单对象的内容。 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. 在这种情况下,您通常需要对在FBO上渲染的对象/场景进行降采样(从多边形计数的角度而言)。 The functions in the API you'll want to check into are: 您要检查的API中的函数是:

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

There is a write-up on using FBOs on gamedev.net . gamedev.net上有关于使用FBO的文章 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. 仅当您的小地图为正交投影时,此方法才有效。

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. 与动态渲染相比,它至少会降低性能强度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM