Combining OpenGL rendering into one view

I have a simple solid simulation in which I want to implement several "navigation modes" so that the user can move around the camera through 3D space. One of these is the ubiquitous drag-and-rotate / rotate used in SketchUp, Blender, etc .; I also want to implement something more appropriate for my particular application. In particular, I want to implement a mode in which the camera floats on a "ring" over the object being modeled (building), and always looks at the center of the model; this way the user can easily "walk" around the object, a common operation in my application.

So what I want to do is render the building in my opinion and display the torus in the upper right corner, with a small sphere on the torus to represent the location of the camera. The torus will have a north arrow, and the user will drag the camera around the model object by dragging the sphere; moving the sphere will move the camera and redraw the scene.

It looks like I have to do the following: display the "main view", i.e. building; then render the torus and sphere (with different perspective and lighting settings) in an offscreen buffer and scatter it from there to the main view.

Then, however, I get into hit testing. I want to detect if the user clicks on a sphere or a torus; from what I understand from the OpenGL compilation (it seems like a tough question: /), all selection methods are only applied to selections in one "scene". Also, I still want to detect "normal" selection operations in the building model, obviously.

So my questions are:

  • How do I render the buffer off-screen and enter another OpenGL context (with alpha blending and transparency, for example for the center of a torus)?
  • How do I perform test testing in this scenario?
+1


a source to share


3 answers


I don't think you need to render the screen for this. You should be able to simply re-set the camera and viewport and overlay after the main scene. You may have Z ordering and / or buffering issues, but perhaps the "subrecord" is simple enough that it doesn't matter, or you could just clear the Z buffer before rendering it.



+2


a source


As for drawing a torus / sphere, create a separate class for this and implement a "draw" method. Let the class contain the location of both the sphere and the torus, and draw () do those things on the screen.

Then just call myRing.draw () in your main drawing method and you have a sphere and a torus!



If you want the top right corner of the window to display a circle / ring rendered in 2D (which might be easier) then the same idea would apply as in your hitbox entry (except without that annoying projection calculation!)

Finally, I would consider using a function key in conjunction with mouse drag to implement the required function ... Eg. the user holds "panning" and then drags the mouse across the screen. These mouse events are captured and the x-delta is used to calculate the rotation angle. The camera position is updated as it happens and you get a smooth glide :)

+1


a source


I agree with @unwind; you don't need an offscreen buffer. If you want it anyway, search for "render-to-texture".

As far as impact testing is concerned, the OpenGL FAQ has an entry. He describes several solutions: using the rendering mode GL_SELECTION using gluUnproject () to get a 3D collision and a simple 2D solution using unique colors.

0


a source







All Articles