Andy Robertson
01-11-2006, 12:57 PM
Folks,
I am using glReadPixels to grab the screen buffer and dump to a bmp file. I am not getting the desired results so I simplified my code to simply generate a cvs file with ones and zeros to check my understanding of how this works. Clearly I am not doing something correct. have I completely misunderstood how this command pushes data into the assigned memory buffer. Are my indices wrong? Is my sizing wrong?
It appears that the data being generated is a 32 bit unsigned integer. Could there be a size conflict with GL_UNSIGNED_INT and unsigned int?
I am using mingw with g++/fltk on a pc.
Any help is greatly apprecieated. A cleaned up snippet follows....
// Declare a pointer to an unsigned int
unsigned int *ImageBuff = NULL;
.
.
.
// Allocate memory for w by h pixels by 3 values
ImageBuff = (unsigned int*) malloc(sizeof(GL_UNSIGNED_INT) * w() * h() * 3);
.
.
// now read the pixels into the buffer in RGB
glReadPixels(x(), y(), w(), h(), GL_RGB, GL_UNSIGNED_INT, ImageBuff);
.
.
.
// Now write out the data in CVS format for review
int imax = w();
int jmax = h();
ofstream BitMapFile("BitMap.cvs", ios::trunc | ios::out);
for(i = 0; i < imax; i++)
{
for (j = 0; j < jmax; j ++)
{
index = j * i * 3;
if(ImageBuff[index + 0] >> 0&& ImageBuff[index + 1] >> 0 && ImageBuff[index + 2] >> 0 )
{
cerr << i << " " << j
<< " " << ImageBuff[index + 0]
<< " " << ImageBuff[index + 1]
<< " " << ImageBuff[index + 2] << "\n";
}
BitMapFlag = 0;
if(ImageBuff[index + 0] >> 0&& ImageBuff[index + 1] >> 0 && ImageBuff[index + 2] >> 0 )BitMapFlag = 1;
BitMapFile << BitMapFlag;
if(j < (jmax - 1))
{
BitMapFile << ",";
}
else
{
BitMapFile << "\n";
}
}
}What am I missing here?
Thanks
- Andy
I am using glReadPixels to grab the screen buffer and dump to a bmp file. I am not getting the desired results so I simplified my code to simply generate a cvs file with ones and zeros to check my understanding of how this works. Clearly I am not doing something correct. have I completely misunderstood how this command pushes data into the assigned memory buffer. Are my indices wrong? Is my sizing wrong?
It appears that the data being generated is a 32 bit unsigned integer. Could there be a size conflict with GL_UNSIGNED_INT and unsigned int?
I am using mingw with g++/fltk on a pc.
Any help is greatly apprecieated. A cleaned up snippet follows....
// Declare a pointer to an unsigned int
unsigned int *ImageBuff = NULL;
.
.
.
// Allocate memory for w by h pixels by 3 values
ImageBuff = (unsigned int*) malloc(sizeof(GL_UNSIGNED_INT) * w() * h() * 3);
.
.
// now read the pixels into the buffer in RGB
glReadPixels(x(), y(), w(), h(), GL_RGB, GL_UNSIGNED_INT, ImageBuff);
.
.
.
// Now write out the data in CVS format for review
int imax = w();
int jmax = h();
ofstream BitMapFile("BitMap.cvs", ios::trunc | ios::out);
for(i = 0; i < imax; i++)
{
for (j = 0; j < jmax; j ++)
{
index = j * i * 3;
if(ImageBuff[index + 0] >> 0&& ImageBuff[index + 1] >> 0 && ImageBuff[index + 2] >> 0 )
{
cerr << i << " " << j
<< " " << ImageBuff[index + 0]
<< " " << ImageBuff[index + 1]
<< " " << ImageBuff[index + 2] << "\n";
}
BitMapFlag = 0;
if(ImageBuff[index + 0] >> 0&& ImageBuff[index + 1] >> 0 && ImageBuff[index + 2] >> 0 )BitMapFlag = 1;
BitMapFile << BitMapFlag;
if(j < (jmax - 1))
{
BitMapFile << ",";
}
else
{
BitMapFile << "\n";
}
}
}What am I missing here?
Thanks
- Andy