Question

I am making simple GUI for my not-so-simple OpenGL game. Since there is a big menu with a lot of control count, I grouped the controls and put them into different windows that could be accessed via buttons in the main menu. So now I would like to replace the buttons with clickable thumbnails of each window and that is why I need to render the GUI to texture.

Currently I have computer with Windows 7 with Geforce 210 video card that supports OpenGL up to 3.3.0 version (but I don't care what version I will use). I have 'dglOpenGL.pas' library for Delphi. I would like to render those windows with controls to textures but because I am n00b at such things, I can't do it (I tried tutorials for C#, but with no working results so far). Any help would be appreciated.

Was it helpful?

Solution

Render-to-texture in OpenGL involves creating a framebuffer object (FBO) and attaching it to a texture. Have a look at the documentation for framebuffer objects for a basic overview.

The general workflow is like this:

  • Create a framebuffer object with glGenFramebuffers
  • Activate the framebuffer with glBindFramebuffer
  • Attach the framebuffer to the texture you want to render to with glFramebufferTexture
  • Call glCheckFramebufferStatus to ensure that it worked.
  • Set the viewport to match the dimensions of the texture you're rendering to. (This generally involves calling glViewport and glOrtho, which I'm sure you're already familiar with so I won't link them here.)
  • Do your rendering.
  • When you're done, deactivate the FBO (call glBindFramebuffer again and pass 0 as the FBO ID value) and reset your viewport.
  • Whatever you've rendered should now be there in the texture.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top