i used the code from MauMan, without using the structs that vbtest gave me( i just included windows.h) and everything seems fine except the colors are messing up in the screenshot.
i have some terrain colored by height, deep blues all the way to light blues for shallow areas and up to green for land. all those colors are now light orange to a very deep orange, but the white text to display on the screen is white as it should be. have any ideas?? i am running in 32-bit mode but doesnt glReadPixels convert it to whatever you ask for? i dont have a server or i would post a screenshot. thanks mauman and vbtest for your help so far...thanks all in advance for any ideas of what might be going on..
i want to PrintScreen - then name the image..
Bitmaps are stored in BGR format.
If at first you don't succeed, redefine success.
ok??? heres my function,...
void zone::printScreen(const char* bmpFILE)
{
cout << "printing screenshot" << endl;
if (0 == bmpFILE)
return;
int nWidth = glutGet( GLUT_WINDOW_WIDTH );
int nHeight = glutGet( GLUT_WINDOW_HEIGHT );
char *pixelBuffer = new char[nWidth * nHeight * 3];
glReadBuffer( GL_BACK );
glReadPixels(0, 0,
nWidth, nHeight,
GL_RGB,
GL_UNSIGNED_BYTE,
(GLvoid*)pixelBuffer);
//unlink(bmpFILE);
FILE* pf = fopen(bmpFILE, "wb" );
cout << "opening file...." << endl;
if ( pf )
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
RGBQUAD pal[1];
memset( &bfh, 0 , sizeof( BITMAPFILEHEADER ) );
memset( &bih, 0 , sizeof( BITMAPINFOHEADER ) );
bfh.bfType = 0x4d42; // ascii "BM"
bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( RGBTRIPLE[1] );
bih.biSize = sizeof( BITMAPINFOHEADER );
bih.biWidth = nWidth;
bih.biHeight = nHeight;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = BI_RGB; //uncompressed format *see msdn.microsoft.com
bih.biSizeImage = 0; // autocalced for RGB images
bih.biXPelsPerMeter = 1000;
bih.biYPelsPerMeter = 1000;
bih.biClrUsed = 1;
bih.biClrImportant = 0;
int nScanLineSize = nWidth * 3;
int nScanLinePad = nScanLineSize % 4;
cout << nScanLineSize << " " << nScanLinePad << endl;
char szPad[] = {0, 0, 0};
bfh.bfSize =
sizeof( BITMAPFILEHEADER ) +
sizeof( BITMAPINFOHEADER ) +
sizeof( RGBQUAD[1] ) +
(nScanLineSize + nScanLinePad) * nHeight;
cout << "bfh.bfSize: " << bfh.bfSize << endl;
fwrite( &bfh, sizeof( BITMAPFILEHEADER ), 1, pf );
fwrite( &bih, sizeof( BITMAPINFOHEADER ), 1, pf );
fwrite( &pal, sizeof( RGBQUAD[1] ), 1, pf );
int nOffset = 0;
for ( int i = 0; i < nHeight; i++, nOffset += nScanLineSize )
{
fwrite( &(pixelBuffer[nOffset]), nScanLineSize, 1, pf );
if ( nScanLinePad )
{
fwrite( szPad, nScanLinePad, 1, pf );
cout << "szPad" << szPad[0] << " " << szPad[1] << " " << szPad[2] << endl;
}
}
fclose( pf ); pf = 0;
cout << "closing file" << endl;
}
delete [] pixelBuffer, pixelBuffer = 0;
}
void zone::printScreen(const char* bmpFILE)
{
cout << "printing screenshot" << endl;
if (0 == bmpFILE)
return;
int nWidth = glutGet( GLUT_WINDOW_WIDTH );
int nHeight = glutGet( GLUT_WINDOW_HEIGHT );
char *pixelBuffer = new char[nWidth * nHeight * 3];
glReadBuffer( GL_BACK );
glReadPixels(0, 0,
nWidth, nHeight,
GL_RGB,
GL_UNSIGNED_BYTE,
(GLvoid*)pixelBuffer);
//unlink(bmpFILE);
FILE* pf = fopen(bmpFILE, "wb" );
cout << "opening file...." << endl;
if ( pf )
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
RGBQUAD pal[1];
memset( &bfh, 0 , sizeof( BITMAPFILEHEADER ) );
memset( &bih, 0 , sizeof( BITMAPINFOHEADER ) );
bfh.bfType = 0x4d42; // ascii "BM"
bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( RGBTRIPLE[1] );
bih.biSize = sizeof( BITMAPINFOHEADER );
bih.biWidth = nWidth;
bih.biHeight = nHeight;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = BI_RGB; //uncompressed format *see msdn.microsoft.com
bih.biSizeImage = 0; // autocalced for RGB images
bih.biXPelsPerMeter = 1000;
bih.biYPelsPerMeter = 1000;
bih.biClrUsed = 1;
bih.biClrImportant = 0;
int nScanLineSize = nWidth * 3;
int nScanLinePad = nScanLineSize % 4;
cout << nScanLineSize << " " << nScanLinePad << endl;
char szPad[] = {0, 0, 0};
bfh.bfSize =
sizeof( BITMAPFILEHEADER ) +
sizeof( BITMAPINFOHEADER ) +
sizeof( RGBQUAD[1] ) +
(nScanLineSize + nScanLinePad) * nHeight;
cout << "bfh.bfSize: " << bfh.bfSize << endl;
fwrite( &bfh, sizeof( BITMAPFILEHEADER ), 1, pf );
fwrite( &bih, sizeof( BITMAPINFOHEADER ), 1, pf );
fwrite( &pal, sizeof( RGBQUAD[1] ), 1, pf );
int nOffset = 0;
for ( int i = 0; i < nHeight; i++, nOffset += nScanLineSize )
{
fwrite( &(pixelBuffer[nOffset]), nScanLineSize, 1, pf );
if ( nScanLinePad )
{
fwrite( szPad, nScanLinePad, 1, pf );
cout << "szPad" << szPad[0] << " " << szPad[1] << " " << szPad[2] << endl;
}
}
fclose( pf ); pf = 0;
cout << "closing file" << endl;
}
delete [] pixelBuffer, pixelBuffer = 0;
}
heh
So... Make pixelBuffer BGR instead of RGB, it's very easy to do.
If at first you don't succeed, redefine success.
thanks for your help python but i guess its only easy if you know how to do it. i know somehow you have to swap the bytes but dunno how or where i should do this....
heh
ok i got it fixed.. it was easy haha
in my glReadPixels call i changed GL_RGB to GL_BGR_EXT and it worked great.. case closed.. thanks for all your help!
in my glReadPixels call i changed GL_RGB to GL_BGR_EXT and it worked great.. case closed.. thanks for all your help!
heh
actually i have one more concern...
windows.h (in order to get the BITMAP header stuff isnt going to work cross platform is it? ... err like in linix or irix OS's
windows.h (in order to get the BITMAP header stuff isnt going to work cross platform is it? ... err like in linix or irix OS's
heh
Quote: Original post by OpenGL_Guru
actually i have one more concern...
windows.h (in order to get the BITMAP header stuff isnt going to work cross platform is it? ... err like in linix or irix OS's
Declare the bitmap header structures yourself.
If at first you don't succeed, redefine success.
ok i declared the stuff that vbtest suggested..look at the code above and just put tag in front of every BITMAP* reference as well as RGBQUAD and RGBTRIPLE. all the structs are defined in my class with the same variables, bfh, bif and pal[1]. the local declarations in the code above were commented out b/c obviously i declared them in my class.
when i try to open up the bitmap it says that there is no preview available..
i didnt declare them as typedefs, just as a regular C++ struct..
struct
{
...
..
...
};
i dont think that this would be causing the problem..
when i try to open up the bitmap it says that there is no preview available..
i didnt declare them as typedefs, just as a regular C++ struct..
struct
{
...
..
...
};
i dont think that this would be causing the problem..
heh
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement