|
发表于 2003-12-4 20:12:00
|
显示全部楼层
Re:怎样在OpenGL中使用中文(采用utf8编码)?
其实OpenGL显示一些平面中文 基本都用纹理来实现这样很方便而且实际
不过这样做也可以(速度很慢):(
procedure TForm1.glDrawString(str: string {一个中文串});
var
fGlyphMetricsFloat: TGlyphMetricsFloat;
fChar: DWord;
i, j, ListNum: integer;
DC: HDC;
begin
DC := wglGetCurrentDC;
FillChar(fGlyphMetricsFloat, SizeOf(TGlyphMetricsFloat), 0);
j := 0;
for i := 0 to Length(str) - 1 do
begin
if IsDBCSLeadByte(Byte(str[j])) then
begin
fChar := DWORD((Byte(str[j]) shl 8) or Byte(str[j + 1]));
j := j + 1;
end
else fChar := DWORD(Byte(str[j]));
j := j + 1;
if fChar = 0 then continue;
ListNum := glGenLists(1);
wglUseFontOutlines(DC, fChar, 1, ListNum, 0.0, 0.1, WGL_FONT_POLYGONS, @fGlyphMetricsFloat);
glCallList(ListNum);
glDeleteLists(ListNum, 1);
end;
end;
[em7] |
|