CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2007
    Posts
    6

    Render OpenGL direct to Bitmap

    As the title suggests, I am looking for a way to render OpenGL output directly to a bitmap that can be accessed by another procedure.

    I have found very few examples or tutorials on this, and the ones I have found use MFC, which I would like to avoid at all costs.

    For a test, I want this code Rendered as a bitmap:

    Code:
    	glBegin(GL_TRIANGLES);
    		glVertex3f(-0.5,-0.5,0.0);
    		glVertex3f(0.5,0.0,0.0);
    		glVertex3f(0.0,0.5,0.0);
    	glEnd();
    	glutSwapBuffers();
    Also, would I still need to use Glut to initialise and loop through the rendering process?

    Regards, Ben

  2. #2
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: Render OpenGL direct to Bitmap

    The easiest way is to simply draw as usual, then use glReadPixels to get the screen image. Or, if you want only part of the screen, you can use one of glCopyTex* functions to copy part of the rendered screen into texture and then use glGetTexImage to read it into your application.
    Code:
    begin loop
      gl... //draw what you need
      glReadPixels // get the result as image
      glClear // clear the buffer
      ... // repeat as many times you need
      
      gl.. // now render what you want to appear on screen
      glutSwapBuffers // blit it onto screen
    end loop
    Also, if you want to simply use the resulting image as a texture, it is much faster to use direct rendering to texture (which can be done in multiple ways, depending on architectur eand hardware support).

  3. #3
    Join Date
    May 2003
    Posts
    424

    Re: Render OpenGL direct to Bitmap

    Be careful, glReadPixels is very slow most of the time.
    The code you posted is decieving. Just take the loop stuff out and it'll be better. He won't be doing any looping, apart from the standard application message loop.

  4. #4
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: Render OpenGL direct to Bitmap

    Quote Originally Posted by aewarnick
    Be careful, glReadPixels is very slow most of the time.
    So is every function that transfers data from hardware buffer (GPU onboard RAM) to system RAM. But that is exactly what he needs to do, slow or not
    Quote Originally Posted by aewarnick
    The code you posted is decieving. Just take the loop stuff out and it'll be better. He won't be doing any looping, apart from the standard application message loop.
    Depends on what he is trying to do. If my post is really deceiving, i offer my deepest apologies

  5. #5
    Join Date
    May 2003
    Posts
    424

    Re: Render OpenGL direct to Bitmap

    He made this comment, "Also, would I still need to use Glut to initialise and loop through the rendering process?"

    I just didn't want him to think he had to use a "game loop" to render to his bitmap.

  6. #6
    Join Date
    Apr 1999
    Posts
    3,585

    Re: Render OpenGL direct to Bitmap

    Try searching the OpenGL site and forums.
    Gort...Klaatu, Barada Nikto!

  7. #7
    Join Date
    May 2003
    Posts
    424

    Re: Render OpenGL direct to Bitmap

    nehe.gamedev.net is great too. Although I was looking for an example of rendering to a bitmap and couldn't find anything for him.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured