Archived

This topic is now archived and is closed to further replies.

Rendering OpenGL to a bitmap

This topic is 5336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heres some code i''ve picked up:

void CaptureScreen()
{
BITMAPFILEHEADER bf;
BITMAPINFOHEADER bi;
unsigned char *image = (unsigned char*)malloc(sizeof(unsigned char)*640*480*3);
FILE *file = fopen("screenshot.bmp", "wb");
if( image!=NULL )
{
if( file!=NULL )
{
glReadPixels( 0, 0, 640, 480, GL_BGR_EXT, GL_UNSIGNED_BYTE, image );
memset( &bf, 0, sizeof( bf ) );
memset( &bi, 0, sizeof( bi ) );
bf.bfType = ''MB'';
bf.bfSize = sizeof(bf)+sizeof(bi)+640*480*3;
bf.bfOffBits = sizeof(bf)+sizeof(bi);
bi.biSize = sizeof(bi);
bi.biWidth = 640;
bi.biHeight = 480;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biSizeImage = 640*480*3;
fwrite( &bf, sizeof(bf), 1, file );
fwrite( &bi, sizeof(bi), 1, file );
fwrite( image, sizeof(unsigned char), 480*640*3, file );
fclose( file );
}
free( image );
}
}

Share this post


Link to post
Share on other sites
check on NeHe example 36

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=36

look for glCopyTexImage2D() in RenderToTexture()

Cheers

Chris

http://members.iinet.net.au/~cleathley/

Share this post


Link to post
Share on other sites
or you can

http://developer.nvidia.com/view.asp?IO=ogl_rtt

but that relys on extension ''WGL_ARB_render_texture extension''

thankfully a ARB one :D


[url]http://members.iinet.net.au/~cleathley/[/url]

Share this post


Link to post
Share on other sites
Your best bet is to call glReadPixels each frame to system memory.

Jumpmap, Render to texture is different than render to bitmap.

Share this post


Link to post
Share on other sites
I''m sorry; I was unclear about my intentions.

I''m writing a level editor for a game and need basically to render to a child window.

I was told that you can only render to a parent window; so i figured i''d render to a bitmap and BitBlt to the child window.

Is there a better way?

Share this post


Link to post
Share on other sites
quote:
Original post by Jallen
Jumpmap, Render to texture is different than render to bitmap.



sorry I was a but unsure what he was actually meaning.. I just assumed that Bitmap = Texture.





[url]http://members.iinet.net.au/~cleathley/[/url]

Share this post


Link to post
Share on other sites