Tested on CS1.6 8)
Modified for CS 1.6 BY: (+)
Credits :
http://www.daniweb.com/forums/thread165645.html
Modified for CS 1.6 BY: (+)
Credits :
http://www.daniweb.com/forums/thread165645.html
Code:
bool btoggle = false;
struct ScreenShot_Data {
GLint x;
GLint y;
GLsizei width;
GLsizei height;
GLenum format;
GLenum type;
GLvoid *pixels;};
ScreenShot_Data ScreenData;
short BM = 0x4d42;
struct bmp_header
{
long size_of_file;
long reserve;
long offset_of_pixle_data;
long size_of_header;
long width;
long hight;
short num_of_colour_plane;
short num_of_bit_per_pix;
long compression;
long size_of_pix_data;
long h_resolution;
long v_resolution;
long num_of_colour_in_palette;
long important_colours;
} HEADER;
void __stdcall ScreenShot( void )
{
UINT AllocSize = Viewport[2]*Viewport[3]*3;
ScreenData.pixels = (GLvoid*)malloc(AllocSize);
ScreenData.type = GL_UNSIGNED_BYTE;
ScreenData.format = GL_RGB;
ScreenData.height = Viewport[3];
ScreenData.width = Viewport[2];
ScreenData.x = 0;
ScreenData.y = 0;
glReadPixels( ScreenData.x, ScreenData.y, ScreenData.width,
ScreenData.height, ScreenData.format, ScreenData.type,ScreenData.pixels);
HEADER.size_of_file = sizeof(HEADER) + AllocSize * Viewport[3] + 2;
HEADER.reserve = 0000;
HEADER.offset_of_pixle_data = 54;
HEADER.size_of_header = 40;
HEADER.width = Viewport[2];
HEADER.hight = Viewport[3];
HEADER.num_of_colour_plane = 1;
HEADER.num_of_bit_per_pix = 24;
HEADER.compression = 0;
HEADER.size_of_pix_data = AllocSize * Viewport[3];
HEADER.h_resolution = 2835;
HEADER.v_resolution = 2835;
HEADER.num_of_colour_in_palette = 0;
HEADER.important_colours = 0;
ofstream file;
file.open ("c:\\ScreenShot.bmp", ios::out | ios::trunc | ios::binary);
file.write ((char*)(&BM), 2);
file.write ((char*)(&HEADER), sizeof(HEADER));
BYTE* Data = (BYTE*)ScreenData.pixels;
for (int n = 0; (UINT)n < AllocSize; n+=3)
{
file.write ((char*)(&Data[n+2]), 1);
file.write ((char*)(&Data[n+1]), 1);
file.write ((char*)(&Data[n]), 1);
}
file.close();
VirtualFree(ScreenData.pixels, AllocSize, MEM_RELEASE | MEM_FREE );
}
void APIENTRY h_wglSwapBuffers (HDC hDC)
{
if(!GetAsyncKeyState( VK_NUMPAD1 ))
btoggle = false;
else
{ if(!btoggle) {ScreenShot( ); btoggle = true;} }
d_wglSwapBuffers(hDC);
}