Reputation: 411
I'm looking for a way to create a second view from the top of my current 3D scene. I would like to do this as easy as possible. The basic idea is that you have a subwindow that will display a top view of the setting.
I've looked into subwindows in openGL but the problem is you have to redraw everything (basically ending up with 2 scene's with different angle = not good). Also because this will be used in a 3D game called "tower box stacking" (you have to place boxes on top of each other and make a high tower) its impossible to use the subwindows way to do it (since you would get 2 scenes with different blocks/locations/actions/...)
So how can I add a "second camera" to my current scene and then position it on top.
Upvotes: 1
Views: 2237
Reputation: 162297
I've looked into subwindows in openGL but the problem is you have to redraw everything (basically ending up with 2 scene's with different angle = not good)
This is actually the one and only way to do this with OpenGL.
So how can I add a "second camera" to my current scene and then position it on top.
OpenGL doesn't have cameras. It doesn't even have a scene. OpenGL merely draws very simple shapes: Points, Lines and Triangles. Above that OpenGL has no understanding of geometry or complex scenes.
Scene management is up to you and drawing multiple views of a scene is up to be implemented by you.
draw_scene:
for o in objects:
glPushMatrix()
glMultMatrix(o.transform)
o.draw()
glPopMatrix()
render_main_view:
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum(...)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glMultMatrix(main_camera_transform)
render_secondary_view:
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum(...)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glMultMatrix(secondary_camera_transform)
scissor_viewport(x,y,w,h)
glScissor(x,y,w,h)
glViewport(x,y,w,h)
render:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_SCISSOR_TEST)
scissor_viewport(main_viewport.x,main_viewport.y,main_viewport.w,main_viewport.h)
render_main_view()
glClear(GL_DEPTH_BUFFER_BIT)
scissor_viewport(secondary_viewport.x,secondary_viewport.y,secondary_viewport.w,secondary_viewport.h)
render_secondary_view()
Upvotes: 4
Reputation: 6645
Disclaimer: I haven't tried this and it's a suggestion really.
So you say your game is about stacking boxes and you want an overhead view. Why not 'fake' the overhead view? Basically you create a texture that represents the minimap of your game as an orthogonal view. ONLY when a new block gets stacked, you would need to update the texture. To view it in the current position you would then have to set the appropriate texture-coordinates of the 'sub-window' or viewport.
Upvotes: 0
Reputation: 72299
Draw the scene once using your default settings.
Then apply a different view transformation (corresponding to your second "camera"), use glViewport
to select a sub-rectangle of the screen and draw the scene again. (Don't forget to reset the glViewport
to cover your entire screen again afterwards)
If you want the mini-map to have a different aspect ratio (w/h), then during the second pass you'll need to also change the perspective transformation so that everything looks OK.
Upvotes: 3