PDA

View Full Version : Render to bitmap trouble with Glut



Digga
10-11-2013, 01:35 PM
Hello,
I have a small graphics program the allows the user to label their measured geometry with Glut based labels, everything work great until I render to bitmap them the text only gets " reversed"

Code the generates the label:

// draw the callout text
glColor3ub(0, 0, 0);
unsigned int i;
// the name
if( feature->label_name ) {
glRasterPos2d(x_callout_location + (char_offset * 0.5), y_callout_location - (line_offset * max_lines));
for( i = 0; i < strlen(feature->name); i++ )
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, feature->name[i]);
if( i > max_x ) {
max_x = i;
}
}
max_lines++;
}

code that generates the bitmap:


// render to the backbuffer and copy the backbuffer to a bitmap
// clear buffer
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT); // for GL_DRAW_BUFFER and GL_READ_BUFFER
//glDrawBuffer(GL_BACK);
glPushMatrix();
SetSize(width, height, true);
glLoadIdentity();
// Draw here
if( video ) {
oglDrawVideo();
} else {
oglDrawScene(thumbnail, background, orient, zero, window);
}
// copy the frame buffer pixels to our bitmap
glReadPixels(0, 0, width, -height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bits);
SetSize(m_cx, m_cy, false);
glPopMatrix();

I have attached pics of the resulting screens

Any suggestions?

Thanks
-Derrek

GClements
10-11-2013, 06:08 PM
Any suggestions?

Use [ CODE ] tags for code so that indentation is preserved.
Post legible images.
Post the code which uses the data returned by glReadPixels()

Digga
10-14-2013, 08:42 AM
{
BYTE* pBitmapBits = (BYTE*)malloc(IMAGE_WIDTH * IMAGE_HEIGHT * 4);
RenderToBitmap(pBitmapBits, IMAGE_WIDTH, IMAGE_HEIGHT, false, true, false, false, false, false );
// Initialize the bitmap header info.
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = IMAGE_WIDTH;
bmi.bmiHeader.biHeight = -IMAGE_HEIGHT;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = IMAGE_WIDTH * IMAGE_HEIGHT * 4;
WriteBitmap(filename, &bmi.bmiHeader, sizeof(BITMAPINFOHEADER), pBitmapBits, IMAGE_WIDTH * IMAGE_HEIGHT * 4);
free(pBitmapBits);
}


Im having trouble with posting better images They appear to be too big.

-Derrek