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.

  • \$\begingroup\$ I'm trying to use or make the exact same thing ! Did you make it ? Is there a github or some other resource that you can share ? Thanks :-) \$\endgroup\$
    – xurei
    Commented Jan 19, 2022 at 14:24

1 Answer 1


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

  • \$\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\$ Commented Aug 18, 2018 at 11:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .