C++ [Visual][DirectDraw]Text in BackBuffer schreiben und dann Flippen

Registriert
Dez. 2009
Beiträge
213
So, nachdem auf mein Thema "OpenFileDialog während DirectDraw läuft anzeigen" niemand antwortet und ich auch davon ausgehe, dass niemand mehr antworten wird, muss ich mir jetzt eine Eingabezeile programmieren, in die man einen Dateipfad eingaben kann. Dazu brauche ich jetzt folgendes als Basiswissen:

Ich habe in meinem Programm bis jetzt ein Primärsurface und davon ein Backbuffer. Ich lasse immer ein Hintergrundbild in den Backbuffer laden (blitten) und den BackBuffer dann im Surface anzeigen (flippen).

Doch bevor geflippt wird möchte ich noch einen kleinen Text in den BackBuffer blitten, der dann zB. in schwarz über dem Hintergrundbild erscheint.

Habe im Internet da nichts gefunden und brauche eure Hilfe.

Hinweis: Ich arbeite nur mit der Visual C++ Umgebung und ohne .NET Framework!

Danke für eure Antworten im Vorraus...
 
Also schon ewig nimmer rumgespielt mit DirectX, aber einen eigenen Filedialog selber schreiben, da kannst ja gleich ne Fensterverwaltung auf DirectX Basis selber entwickeln.

Eigentlich müßt man des mit FileOpenDialog doch hinkriegen, wenn der z.B. als eigenständiges FrameWindow und nicht dein DirectXWindow als parent hat, oder beim dem DialogWindowden parent auf null, irgendwie so tät ichs mal probieren...

Ansonsten mal bei Opensource wie Sourceforge schauen obs nicht schon ne DirectX Lib gibt, die so ne minimale Fensterverwaltung auf DirectDraw aufbaut...

Probier mal DXUT

http://skyagod.springnote.com/pages/1568686?print=1
http://msdn.microsoft.com/en-us/library/ee417532(VS.85).aspx
 
Zuletzt bearbeitet:
Danke für deine Antwort. Deine Tipps werde ich mal ausprobieren. Das mit dem OpenFileDialog habe ich mir so gedacht, dass ich nur ne Eingabezeile ohne grafische Darstellung habe.
Ergänzung ()

OK, jetzt habe ich rausgefunden, was geht: Ich hatte hwndOwner schon auf NULL, das habe ich nehmlich aus einem Tutorial rauskopiert. Wenn ich stattdessen mein Fensterhandle einsetze, dann kommt nur manchmal (ca. jedes 2. mal) der Dialog, in den anderen Fällen bleibt er hinterm Surface. Eben wie er Lust und Laune hat. Und wenn er kommt, dann verschwindet das Bild und im Hintergrund neben dem Dialog ist jetzt das blanke graue Formular. Wenn ich den Dialog dann schliese, dann kommt auch wieder das ganz normale Hintergrundbild. Also ist das nicht so die ganz tolle Lösung. Mit solchen DirectDrawTextur-Formularen möchte ich aber auch nicht unbedingt arbeiten. Mir wäre es eigentlich am liebsten, wenn mir jemand, wie im 1. Post beschrieben, sagen könnte, wie man Text in den BackBuffer schreibt.
 
mit GDI: Such dir nen Font aus, schreib mit drawText() oder so in eine Bitmap alle benötigten Zeichen rein und mach BlitBitmap ( also rauskopieren aus der "Buchstabentafel" und reinblitten in die Surface). Die "Buchstabentafel"_bitmap am besten mit alpha-Channel, sodaß kein Hintergrund dabei ist, sonst hast halt immer den Hintergrund dabei, wobei des geht ja auch wenn der z.B. weiß ist hast gleich ein Art text window.

Wie genau mit WIN-API und DirectX weiß ich nimmer...
 
Geht das auch etwas schöner? Ich meine, das macht doch sicher keiner, sich so ein temporäres Bitmap zu erstellen. Geht das nicht direkt irgendwie mit DirectDraw, Buchstaben einzufügen?
 
LPD3DXFONT m_font;


// Create a D3DX font object
D3DXCreateFont( gD3dDevice, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_font );

void DisplaySomeText()
{

// Create a colour for the text - in this case blue
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,0,0,255);

// Create a rectangle to indicate where on the screen it should be drawn
RECT rct;
rct.left=2;
rct.right=780;
rct.top=10;
rct.bottom=rct.top+20;

// Draw some text
m_font->DrawText(NULL, "Hello World", -1, &rct, 0, fontColor );

}

The format of the draw call is:

int DrawText( LPD3DXSPRITE pSprite, LPCTSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color );

* pSprite - the first parameter allows a sprite interface to be passed in. Setting this to NULL means Direct3D will use its own internal sprite object to render the text. If you are doing lots of DrawText calls passing your own sprite object can speed up rendering significantly (see font drawing optimisations below).
* pString - this is the string to render. The type of string depends on your projects character set.
* Count - the number of characters in the string. You can set this to the magic number -1 in order to specify that Direct3D should count the characters itself. Note that this only works with null terminated strings.
* pRect - the rectangular area in which the text will be displayed. How the text is justified within this rectangle depends on the next parameter:
* Format - allows you to specify some flags. This allows you to specify the justification of the text within the rectangle plus some other options (see advanced below).
* Color - the final parameter is the colour you want to render the text.

As always you must release the D3DX interface before your program exits or on a device reset:

m_font->Release();

The third parameter to the DrawText function is a flag that allows you to specify justification etc. There is also a very useful flag: DT_CALCRECT that causes DrawText to set the passed rectangle to the size required to display the text. When using this flag DrawText will not actually draw anything, it is purely a way of obtaining the size of the text.
Font Drawing Optimisations

Text drawing can be slow and so there are a couple of optimisations provided by the font interface. Unfortunately these are not very well documented so I decided to carry out some tests of my own to determine some real world values.

I found that passing a sprite object as the first parameter to DrawText improved rendering speeds by up to 4 times - quite a significant improvement.

The sprite interface also provides a function to allow you to preload a text string into video card memory - PreloadText. This should theoretically improve performance as the function would not need to assemble the characters each time and upload them to the graphic card. However from my test results I found little speed improvement.
 
Hey vielen Dank für diesen POST, das wird mir sehr weiterhelfen!!!
 
Zurück
Oben