Yan  Li
Yan Li

Reputation: 431

Hide GLUT window

Is it possible to hide OpenGL window and the rendering are still running? I use glutHideWindow which will never trigger display function.

If that is not possible, is it possible in the program to change the focus of the current window? I want to run opengl program but I don't need that window. In fact, I want to use the framebuffer that opengl updates at each frame in another program. But it's always annoying to toggle between the two programs. (They both have window)

Upvotes: 2

Views: 4722

Answers (2)

diennv
diennv

Reputation: 101

After creating the window, you can use glutHideWindow() to go offscreen. Then you still render as nomal and use glReadPixels to read back and get buffer to use it later.

Upvotes: 1

datenwolf
datenwolf

Reputation: 162164

Is it possible to hide OpenGL window and the rendering are still running?

Yes and No to both parts of the question.

If you hide a window, all the pixels of the window's viewport will fail the pixel ownership test when rendering. So you can't use a hidden window as a drawable for OpenGL to operate on.

What you need is an off-screen drawable to draw to.

The modern variant are Framebuffer Objects (FBOs), which you can create on a regular OpenGL context, that might even work on a hidden window. FBOs take some drawable attachments (render buffers, textures) and allow OpenGL to draw to these instead to the window.

An older method are PBuffers, also widely supported, but not as easy to use as FBOs.

Note that if you want to perform off-screen rendering on Linux/X11 the X server must be active, i.e. owning the VT so that the GPU actually processes the commands. So you can't just start an X server "in the background" but have another X server use the display device.

Upvotes: 5

Related Questions