Rendering OpenGL to a bitmap
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 );
}
}
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 );
}
}
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/
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/
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.
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?
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?
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/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement