-
April 8th, 2007, 04:31 PM
#1
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
-
April 9th, 2007, 07:26 AM
#2
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).
-
April 9th, 2007, 05:36 PM
#3
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.
-
April 9th, 2007, 08:39 PM
#4
Re: Render OpenGL direct to Bitmap
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
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
-
April 9th, 2007, 09:05 PM
#5
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.
-
April 10th, 2007, 07:57 AM
#6
Re: Render OpenGL direct to Bitmap
Try searching the OpenGL site and forums.
Gort...Klaatu, Barada Nikto!
-
April 10th, 2007, 08:01 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|