怎么在用opengl画的背景上输出文字?有没有函数?用textout函数在上面输出的时候只闪了一下就消失了请帮忙!

解决方案 »

  1.   

    怎么能用TextOut呢??
    在OpenGL中显示文字,如果简单的话一般使用自定义的图片,转换成Texture,然后贴出来。或者使用Windows内带的TrueType字体。
    1. 首先要建立需要调用的Font 
    Function CreateFont( fontname : PChar, int Size): Shortint;
    var hFont : THFONT;
        base  : integer;
    begin  
       base := glGenLists(255);  // 能接受的最大值   if stricmp( fontName, 'symbol') =0 then
       begin
           hFont := CreateFont( Size, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
                                SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                                ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);
       end
       else begin
           hFont := CreateFont(Size, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
                                ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                                ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);
       end;   if not hFont then result :=0
       else begin
          SelectObject(g_HDC, hFont);
          wglUseFontBitmaps(g_HDC, 32, 96, base);
          result := base;
       end;
    end;在建立的时候调用 -> listBase = CreateFont("Arial", 24);2. 在DrawFrame 的时候调用, 记得Text不要太长了。
    procedure PrintText( base : ShortInt, str : PChar);
    begin
       if base = 0 then exit;   glPushAttrib( GL_LIST_BIT );
          glListBase( base - 32 );
          glCallLists( strlen(str), GL_UNSIGNED_BYTE, str );
       glPopAttrib();
    end;3. 最后退出时记得删除建立的东东.
    procedure ClearGLFont( base : shortint);
    begin
       if base <> 0 then  glDeleteLists( base, 255 );  // 最大值必须和建立时一样.
    end;
      

  2.   

    上的代码是没有经过测试,不过应该问题不大. 自己调试一下吧。不要再尝试使用Textout了。^_^
      

  3.   

    procedure DrawNormalText;
    var
      str:PChar;
    begin
      str:='OpenGL Test!';
      glRasterPos2f(-0.3, 0.3);
      wglUseFontBitmaps(h_DC,0,256,1000);
      glListBase(1000);
      glCallLists(strLen(str),GL_UNSIGNED_BYTE,str);
    end;procedure Draw3DText;
    var
      str:PChar;
      base:GLuint;
      x:array[0..255] of GLYPHMETRICSFLOAT;
      len:integer;
    begin
      str:='ABCD';
      len:=strlen(str);
      base:=glGenLists(len);
      glRasterPos2f(-5, -8);
      glTranslatef(-1.0,0.0,-2.0);
      wglUseFontOutlines(h_DC,0,255,base,0.8,0.1,WGL_FONT_POLYGONS,@x);
      glListBase(base);
      glCallLists(strlen(str),GL_UNSIGNED_BYTE,str);
    end;
    delphi6+win2000调试通过,注释每写了,自己去查资料吧,中国游戏开发资源网上有