Advertisement

Rendering OpenGL to a bitmap

Started by May 07, 2003 03:26 PM
6 comments, last by MikeJr 21 years, 9 months ago
Could anybody point me to a SIMPLE NON-MFC c++ tutorial on rendering OpenGL to a bitmap rather than the screen?
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 );
}
}
Advertisement
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/
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


http://members.iinet.net.au/~cleathley/
Your best bet is to call glReadPixels each frame to system memory.

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

---I write code.DelphiGL (http://delphigl.cfxweb.net)
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?
Advertisement
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.





http://members.iinet.net.au/~cleathley/
Mike - you can render to a child window. Don''t know where you heard you couldn''t ...

This topic is closed to new replies.

Advertisement