GDI TextOut and Unicode
Blitz3D Forums/Blitz3D Programming/GDI TextOut and Unicode
| ||
Hi I have tried to get the Unicode text in Blitz; I did get the Unicode character, but have a big problem. I write a DLL in C++( I am not good at C++), simply using GDI function ¡°TextOut¡±to display the Unicode character ,the DLL function works fine in Blitz ,and I have seen the Unicode character ,but the text display is flickering ,especially when the frame rate is slow ,I have no idea what¡¯s wrong .If I do not use ¡°Graphic3d¡± ,just Graphic ,it will works fine without any problem. Need help! (Sorry for my poor English) Thanks in advance! ***********Below is the code in C++********* // FireWin32.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "windows.h" #define EXPORT extern "C" __declspec(dllexport) BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } EXPORT VOID __stdcall Display( HWND hWnd,HDC hdc,int pox,int poy,int R,int G,int B,char *text) { SetTextColor(hdc,RGB(R,G,B)); SetBkColor(hdc,RGB(0,0,0)); SetBkMode(hdc,TRANSPARENT); TextOut(hdc,pox,poy,text,strlen(text)); ReleaseDC(hWnd,hdc); } EXPORT HDC __stdcall GetHDC( HWND hWnd ) { HDC hdc=GetDC(hWnd); return hdc; } **********Code in Blitz3d*************** ; ------------------ ; Set 3D graphics mode Graphics3D 640,480,16,0 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() cone=CreateCone( 32 ) PositionEntity cone,0,0,5 hWnd%=GetActiveWindow%() hdc%=GetHDC(hWnd%) FrameRate=CreateTimer (30) While Not KeyDown( 1 ) WaitTimer (FrameRate) RenderWorld Display (hWnd%,hdc%,10,10,255,200,200,"hello,world") ;Here is the function to display the unicode text! Flip Wend |
| ||
Hi! I've waiting for this during very long time... I have not the proper knowledge to help you, but don't worry because some of the masters of Blitz at this forums will help you, sure! To have unicode fonts in Blitz could be great! Go for it Jin! regards |
| ||
Perhaps you are writing to the front buffer? See this is what happens: Graphics x,y: This sets frontbuffer as default. Graphics3D X,y: This sets BackBuffer as default. When you use Graphics3D, perhaps the function is writing to the frontbuffer, and when flip is called, this gets sent to the backbuffer? Thus, you see it for a small period of time and then it dissapears. I could be completely wrong but logically this could be a cause. |
| ||
Bad realization and very slow. I did support a conclusion unicode-text in any buffer with any font (antialised!). Used buffering the font and has got speed-up of the draw in ~80x-100x times faster than in Blitz3D... In Blitz drawing is made similarly, but flash when call of each command "Text" creates font in OS but afterwards deletes and so so slowly! p.s. Use DeviceContex from DX7-surface and do similarly example (PB 4.02): ProcedureDLL TextW_(x.l, y.l, text.l, centre_x.l=0, centre_y.l=0) ;bbText (x, y, text, centre_x, centre_y) CurBuf.l=PeekL(tCurrentBuffer) If CurBuf=0 CurBuf=bbBackBuffer() EndIf CurCol=ColorConvertW( PeekL(tCurrentColor) ) *rc.RECT = CurBuf +$9C *dd7surf.IDirectDrawSurface7=PeekL( CurBuf +12) *dd7surf\GetDC(@hDC) If hDC OldFont = SelectObject_(hDC, *tCurrentFont\font) If centre_x<>0 SetTextAlign_ (hDC,#TA_CENTER) Else SetTextAlign_ (hDC,0) EndIf If centre_y<>0 y-(*tCurrentFont\h / 2) EndIf SetBkMode_ (hDC,#TRANSPARENT) SetTextColor_ (hDC,CurCol) ExtTextOutW (hDC, x, y, #ETO_CLIPPED, *rc, text, LenW(text), 0) SelectObject_ (hDC, OldFont) *dd7surf\ReleaseDC(hDC) EndIf EndProcedure And create font similarly example: ProcedureDLL.l LoadFontW_(fontname.s, height.l=12, bold.l=0, italic.l=0, underline.l=0, angle.f=0) bfnt.l = bbLoadFont (fontname, height, bold, italic, underline) ; -- If AddElement(tFont()) tFont()\blitzID = bfnt fontname=Trim(fontname) ext.s=UCase(Right(fontname,4)) If ext=".FON" Or ext=".FNT" Or ext=".TTF" Or ext=".FOT" If AddFontResource_(@fontname)>0 tFont()\fontres=fontname EndIf fontname=GetFilePart(fontname) fontname=Left(fontname,Len(fontname)-4) EndIf If bold<>0 bold=700 EndIf If italic<>0 italic=1 EndIf If underline<>0 underline=1 EndIf angleL.l=10.0*angle tFont()\font = CreateFont_ (height, 0, 0, angleL, bold, italic, underline, 0, 0, 0, 0, 0, 0, @fontname) GetFontInfo() EndIf ProcedureReturn bfnt EndProcedure |
| ||
Thanks every one above! MixailV is right, but I have no idea how to implement ¡°surface->getDC¡±. I think the code in C++ should be like this: ***************************************** HDC dc; if (SUCCEEDED(surface->GetDC(&dc))) { TextOut( dc , 0 , 0 , "Hello,world!" , 5 ); // release the DC... surface->ReleaseDC(dc); . } ************************************ The problem is that I do not know how to translate "surface" to ¡°backbuffer¡± in blitz. But I found a ¡°stupid¡± way to display the text without flickering, just draw the text after ¡°Flip¡±,but this is not working in fullscreen mode, below is the BB codes. ************************************** ; Graphics3D Example ; ------------------ ; Set 3D graphics mode Graphics3D 640,480,16,0 SetBuffer BackBuffer() hWnd%=GetActiveWindow() hdc%=GetHDC(hWnd%) TimeCouter=CreateTimer(30) While Not KeyDown( 1 ) WaitTimer(TimeCouter) RenderWorld Flip Display(hWnd%,hdc%,20,20,255,200,0,"hello,world,I like unicode!")// draw the text after ¡°Flip¡±!! Wend End *************************** I think this way may cause program slow down ,I tested the program ,it seems not slow down the program very much, but as I said before ,this way is not working in fullscreen mode ,Hmmmmm, If anyone have a good idea that would be great ,thanks!! |
| ||
Attentively study my example and you will caught what draw text in any buffer (dx7-surface) rather then on window dd7surface = PeekInteger ( BackBuffer()+12 ) (Blitz3D 1.98) or dd7surface = PeekInteger ( TextureBuffer(YourTexture) )+12 (Blitz3D 1.98) or dd7surface = PeekInteger ( ImageBuffer(YourImage) )+12 (Blitz3D 1.98) *dd7surf.IDirectDrawSurface7=PeekL( _ANY_BUFFER_HERE_ +12) *dd7surf\GetDC(@hDC) If hDC .... Endif |
| ||
Really hope Blitz3D can support unicode natively, BlitzMax did it very well, but Max3D is no trace yet... Will be great if such a DLL is developed for Blitz3D. |
| ||
I can do support unicode in Blitz3D, this will work quickly and qualitative. But while IDE will not be able to save in unicode format - all this not will have a sense! If creator of the IDEal will do editing and saving in UTF-8, that I build-in unicode support in FastImage library. |
| ||
I saw the IDEal forum and everything seems going great, I hope it can help Blitz3D being accepted by the worldwide developers. BTW, FastImage is a great library, please keep up developing. |
| ||
:) Thx! I have already realized text drawing through GDI, while only Ascii. Development in progress... |
| ||
See new FastText library with support Unicode - http://www.blitzbasic.com/Community/posts.php?topic=68216 |
| ||
Hello, I tried to load some TTF font but it only uses system font, is there some restriction on Font Name/Collection? For Example, try to retrieve same font "MS gothic" UnicodeFont=LoadFont("C:\Windows\Fonts\msgothic.ttc",24) don't work. UnicodeFont=LoadFont("MS Gothic",24) works. By the way, all Chinese Fonts seems not work correctly (only shows default system font, but indeed in Unicode format) Do we need to change to fonr name or modify the font internal code page? |
| ||
File-name of the font must be identical name (internal) of the font. If there is ideas as this realize better, cite an instance, I shall do this in library. |
| ||
I found the problem, it's due to most chinese fonts are not correctly mapped, after some testing I found some working fonts. This should be a system issue. |
| ||
After looking at BMax's LoadImageFont, I know a bit, in BMax, the font drawing is handled by freetype, and it can work with many charset, like Chinese/Japan/Korean ..etc. However Windows itself seems have problem with this, in most Chinese fonts, only English parts was drawn correctly(What I tried, only Arial Unicode MS/MS Gothic works). However the FastText and IDEal Unicode is a pretty powerful set for international spreading of Blitz3D. |