GL rendering without a window

Started by
7 comments, last by nmi 16 years, 3 months ago
I am trying to create an opengl app which renders entirely to offscreen buffers and drops those buffers to textures. This part is easy, however, I can't seem to come up with a way to do this without a window. Does anyone know any way to do this? A second (and worse, IMO) issue, is that I have to do this in java, so I am working with JOGL. Whatever the trick, I need it to work with JOGL. Any thoughts? Thanks in advance.

Stupid details.....always get in the way....it's time to write the dwim(x) function ("do what i mean to")
Advertisement
There is no such thing as GL rendering without a window.
You can however make the window invisible and render to offscreen buffer (FBO)
I don't know how you make a window invisible in Java but I'm sure it's a simple function call.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Or you probably don't even need to create the FBO, just hide the window and read the data from your default framebuffer. :)
Sincerely,Arto RuotsalainenDawn Bringer 3D - Tips & Tricks
Quote:Original post by Arex
Or you probably don't even need to create the FBO, just hide the window and read the data from your default framebuffer. :)


That's called undefined behavior. It may or may not work. Even if a window is visible and a small part is hidden, the GPU might not render to it, so they invented p-buffers which were later superceded by FBO.

The pixel ownership section of the spec explains this.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by V-man
There is no such thing as GL rendering without a window.

There certainly is such a thing. For example, Mesa provides the OSMesa driver which can render to a user defined memory buffer, without a window, or any windowing code at all. Perfect for rendering intended for a purpose other than displaying on the screen in one way or another. For example, I made an experimetal application on my webserver that used Mesa and OSMesa to render an image dynamically with parameters set by submitted data and sent it back to the browser as an encoded image.

However, I doubt the Mesa/OSMesa solution is possible in the environment required by personwholives.
Quote:Original post by Brother Bob
Quote:Original post by V-man
There is no such thing as GL rendering without a window.

There certainly is such a thing. For example, Mesa provides the OSMesa driver which can render to a user defined memory buffer, without a window, or any windowing code at all. Perfect for rendering intended for a purpose other than displaying on the screen in one way or another. For example, I made an experimetal application on my webserver that used Mesa and OSMesa to render an image dynamically with parameters set by submitted data and sent it back to the browser as an encoded image.

However, I doubt the Mesa/OSMesa solution is possible in the environment required by personwholives.


I'm sure he is running Windows but let's consider Linux.
Is OSMesa hw accelerated on Linux?
The only thing I know is that if I install Linux, Mesa comes with it. usually version 1.2. I don't know if it is Mesa 1.2 or GL 1.2 but it runs in software so I have to install drivers.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I may be wrong but my understanding is that JOGL is designed for use with either the AWT or Swing libraries, and both the awt.Frame and swing.JFame are invisible by default unless you call show() or setVisible(true).
Quote:Original post by V-man
I'm sure he is running Windows but let's consider Linux.
Is OSMesa hw accelerated on Linux?

Probably not.
Quote:Original post by V-man
The only thing I know is that if I install Linux, Mesa comes with it. usually version 1.2. I don't know if it is Mesa 1.2 or GL 1.2 but it runs in software so I have to install drivers.

I assume the situation is similat to Windows; if you install specific drives for particular hardware, you're limited by what the driver implementes or what the hardware provides. Mesa itself though, as a software implementation, implements OpenGL 2.1.

Quote:Original post by personwholives
I am trying to create an opengl app which renders entirely to offscreen buffers and drops those buffers to textures. This part is easy, however, I can't seem to come up with a way to do this without a window. Does anyone know any way to do this?

A second (and worse, IMO) issue, is that I have to do this in java, so I am working with JOGL. Whatever the trick, I need it to work with JOGL. Any thoughts?

Thanks in advance.


You mean something like this ?
GLPbuffer pBuffer;if( GLDrawableFactory.getFactory().canCreateGLPbuffer() ) {    pBuffer = GLDrawableFactory.getFactory().createGLPbuffer(glcaps,         null, texWidth, texHeight, null);    pBuffer.addGLEventListener(this);	} else {    System.out.println("The graphics card has no pbuffer support.");}// start rendering into the pBufferpBuffer.display();GL gl = pBuffer.getContext().getGL();gl.glFinish();pBuffer.getContext().destroy();


To obtain the rendered image call this in your display function:
ByteBuffer result = ...;gl.glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, result); 

This topic is closed to new replies.

Advertisement