Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Offscreen rendering tutorial?

  1. #1
    Member Regular Contributor
    Join Date
    Apr 2007
    Location
    Fairfax, VA
    Posts
    252

    Offscreen rendering tutorial?

    While I'm not new to OpenGL, this is the first time I've wanted to use OpenGL for something other than displaying data on the screen.

    My goal is to generate a profile of 3D terrain-like data from a given position, and then read back the 3D positions of the visible pixels.

    While I'm familiar with CUDA and that approach to GPGPU programming, it seemed to me that OpenGL already did the vast majority of the math for me in this case, so it made sense to use it.

    So, I create a 2-channel float texture which simply ranges between 0 and 1 in both directions; I can map that to a 2D coordinate in the elevation map data to find an XYZ point.

    What I'd *like* to do at a high level is to call glFlush() once all the data is arranged into triangle strips, and then somehow get back a 2D array of 2-channel floats which I can manipulate on the host like any array.

    The "somehow" is the problem. There doesn't seem to be any easy way to do this---unlike the dead-simple cudaMemcpy function which would accomplish the same thing.

    I've been investigating pbuffers and framebufferObjects and whatnot, but none of the classes I've found which claim to make using those easy comes with a function to actually return the contents of the buffer----leading me to believe I'm missing something fundamental.

    This is all in C++, incidentally. Although I'm willing to throw some Cg into the mix if necessary.

    Advice?

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Offscreen rendering tutorial?

    You're looking for glReadPixels?

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2007
    Location
    Fairfax, VA
    Posts
    252

    Re: Offscreen rendering tutorial?

    That was part of it, yes. The other part, naturally, is how to set up an offscreen rendering context. (I've always just used GLUT in the past.)

    It's looking to me like wglCreateContext is the simplest way to go, despite the unfortunate non-cross-platformness of that approach.

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Offscreen rendering tutorial?

    You don't need wgl-functions for frambuffer objects. It's all setup inside your standard OpenGL context.

    I don't know what tutorials you're looking at, but there should be plenty of examples for FBOs in the NVIDIA SDK 10.
    http://developer.nvidia.com/page/home.html

    Just search for "simple framebuffer object" and that'll find this:
    http://download.developer.nvidia.com/dev...fer_object.html
    Even a GLUT thingy, there you go.

    For glReadPixels on that you would just need to pick the correct framebuffer with glReadBuffer.

  5. #5
    Member Regular Contributor
    Join Date
    Apr 2007
    Location
    Fairfax, VA
    Posts
    252

    Re: Offscreen rendering tutorial?

    That example is certainly useful, but it's not the whole story. I've heard OpenGL won't initialize if it doesn't have some render context....in that case, there's still a
    glutCreateWindow("Simple Framebuffer Object");
    call, which creates a render context.

    I'm looking for an example which uses offscreen rendering *without* ever creating a window on-screen. Know any of those?

    Assume I'm a newbie. I'm not, quite, but there are some annoying gaps in my knowledge which crop up at unexpected times.

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Offscreen rendering tutorial?

    You actually need to create a window to get a rendering context before using OpenGL. Then you can create your offscreen framebuffer, and discard the original window.

    Maybe it is too much to ask for GLUT, I found this thread on windowless opengl, it can help you :
    http://www.opengl.org/discussion_boa...c;f=3;t=015141

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Offscreen rendering tutorial?

    Just make the window invisible.

    this is a Windows function :
    ShowWindow(HWND hwnd, SW_HIDE)
    ------------------------------
    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);

  8. #8
    Intern Contributor
    Join Date
    Sep 2004
    Posts
    73

    Re: Offscreen rendering tutorial?

    OpenGL Off-Screen rendering? ... Mesa3D, (if a software implementation has enough performance for your application ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •