PDA

View Full Version : Rewrite of glut printing thread



Digga
10-14-2013, 02:24 PM
Hello,
I am working on a small graphic program that allows user to label measured geometry with GLUT based labels the rest of the program is in MFC/Opengl. The issue is that the labels work great in the normal view but when converted to a bitmap the labels text "flips" itself:


// 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++;
}



this code calls create bitmap:


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);



And finally this code renders 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();
// copy the framebuffer pixels to a texture
//glPopAttrib(); // GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT




Attached are better pictures of the output.

Thanks for any help

-Derrek

tonyo_au
10-16-2013, 10:27 PM
I believe byte 0 of a bmp is top left of the image but byte 0 of an OpenGL is the bottom left. You need to allow for this when loading the image