0
\$\begingroup\$

I'm working on a project for the game and i have been trying to draw a second smaller "window" that would act like a second camera, independent from the player.

I have looked into glViewport however i keep running into issues where the second viewport is the only one being drawn (the first one gets covered by the second and has a blank screen where the first viewport should be:enter image description here

So i guess the question is: How can i have multiple windows on screen and make it so it plays nice with the game's default rendering system? I know it is possible since the game uses OpenGL, and maybe its just a simple case of putting the code in the right class.

\$\endgroup\$
1
\$\begingroup\$

Create Multiple viewports

You don't "create" viewports, because viewport is not an object. When you set a viewport you are setting the left, top, right bottom region that the GL context will use to render in the framebuffer.

It looks like what you want is render to framebuffer, that will act like a camera, and then render the content of this framebuffer on the screen.

  1. Create a framebuffer with 2 textures attached to it (one texture is the color attachment, and the other texture is the depth attachment)
  2. Bind to the framebuffer.
  3. Render to the framebuffer.
  4. Bind to the screen framebuffer (glBindFramebuffer(0))
  5. Render the texture that is the color attachment of the framebuffer you created into the screen framebuffer.

There are plenty of sources that explain this process with details, they are often referred as "render to texture", like this one: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture

\$\endgroup\$
  • \$\begingroup\$ so the game has its own class to create a framebuffer object but im not sure whether it would work for my purpose (creating a second "camera" inside the main game window) pastebin.com/4ePD05WN - Framebuffer.java \$\endgroup\$ – TypicalUser Aug 18 '18 at 11:41

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.