Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Rewrite of glut printing thread

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Rewrite of glut printing thread

    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:

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

    this code calls create bitmap:
    Code :
    [SIZE=2]BYTE* pBitmapBits = (BYTE*)malloc(IMAGE_WIDTH * IMAGE_HEIGHT * 4);
    RenderToBitmap(pBitmapBits, IMAGE_WIDTH, IMAGE_HEIGHT, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] );
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Initialize the bitmap header info.
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]BITMAPINFO bmi;
    memset(&bmi, 0, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](BITMAPINFO));
    bmi.bmiHeader.biSize = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](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, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](BITMAPINFOHEADER), pBitmapBits, IMAGE_WIDTH * IMAGE_HEIGHT * 4);
    free(pBitmapBits);
    [/SIZE]

    And finally this code renders the bitmap
    Code :
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// render to the backbuffer and copy the backbuffer to a bitmap
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// clear buffer
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]glClearColor(1, 1, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT); // for GL_DRAW_BUFFER and GL_READ_BUFFER
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//glDrawBuffer(GL_BACK);
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]glPushMatrix();
    SetSize(width, height, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    glLoadIdentity();
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Draw here
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]( video ) {
    oglDrawVideo();
    } [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
    oglDrawScene(thumbnail, background, orient, zero, window);
    }
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// copy the frame buffer pixels to our bitmap
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]glReadPixels(0, 0, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bits);
    SetSize(m_cx, m_cy, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    glPopMatrix();
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// copy the framebuffer pixels to a texture
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//glPopAttrib(); // GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
    [/COLOR][/SIZE][/COLOR][/SIZE]

    Attached are better pictures of the output.

    Thanks for any help

    -Derrek
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Partview1.jpg 
Views:	54 
Size:	11.3 KB 
ID:	1169   Click image for larger version. 

Name:	PartView2.jpg 
Views:	56 
Size:	11.9 KB 
ID:	1170  

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •