开发者

OpenGL bitmap text fails after drawing polygon

开发者 https://www.devze.com 2022-12-25 19:50 出处:网络
I\'m using Win32 and OpenGL to to draw text onto a window. I\'m using the bitmap font method, with wglUseFontBi开发者_Python百科tmaps. Here is my main rendering function:

I'm using Win32 and OpenGL to to draw text onto a window. I'm using the bitmap font method, with wglUseFontBi开发者_Python百科tmaps. Here is my main rendering function:

glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix();
    glColor3f(1.0f, 0.0f, 1.0f);
    glBegin(GL_QUADS);
        glVertex2f(0.0f, 0.0f);
        glVertex2f(128.0f, 0.0f);
        glVertex2f(128.0f, 128.0f);
        glVertex2f(0.0f, 128.0f);
    glEnd();
glPopMatrix();

glPushMatrix();
    glColor3f(1.0f, 1.0f, 1.0f);
    glRasterPos2i(200, 200);
    glListBase(fontList);
    glCallLists(5, GL_UNSIGNED_BYTE, "Test.");
glPopMatrix();

SwapBuffers(hDC);

As you can see it's very simple and the only thing that it's supposed to do is draw a quadrilateral and draw the text "Test.". But the problem is that drawing a polygon seems to mess up any text operations I try to do after it. If I place the text drawing functions before the polygon, both the text and the polygon draw fine. Is there something I'm missing here?

Edit: This problem only happens when the window is run in Fullscreen, by ChangeDisplaySettings. Any reason why this would be??


I know this might be a very late reply but I came across this question looking for answers to this exact problem. The way I attempted to draw text over a polygon is slightly different. I have a method that looked like this:

glClear( GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
glRasterPos2f( pX, pY );

glPushAttrib( GL_LIST_BIT );
glListBase( base - 32 );
glCallLists( length( pText ), GL_UNSIGNED_BYTE, PChar( pText ) );
glPopAttrib();

I tried drawing a polygon and text over it like this:

glPushMatrix();
glBegin(GL_QUADS);
  glColor( 1.0, 0.0, 0.0 );
  glVertex2f( fX, fY );
  glVertex2f( fX + fWidth, fY );
  glVertex2f( fX + fWidth, fY + fHeight );
  glVertex2f( fX, fY + fHeight );
glEnd( );
glColor( 0.0, 1.0, 0.0 );
Text( 100, 100, fCaption );
glPopMatrix();

But, similar to your problem, only the text would draw or in some case (after moving the Text method around a bit) nothing would draw at all. I realized that the method had

glClear( GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT );

which OBVIOUSLY cleared the buffer after I drew the polygon and before I drew the text... This was such a silly mistake and although I have failed to recognize any similar code in the code you have provided, it may be somewhere else. Either way this bit of code will help you if you just clear the glClear method from the Text method. Hope this helps or might help other people who are in a similar situation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号