Author Topic: DX9 Questions  (Read 20644 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
DX9 Questions
« on: November 15, 2008 »
DX9 - Drawing 2D Text:

Using this framework i have really a problem (even with searching on google and using MSDN), how to Draw 2D Text to the DX screen  ::)

Code: [Select]
void WinMainCRTStartup()
{             
HWND hWnd = ( CreateWindowEx(WS_EX_TOPMOST,"edit",0,0,0,0,0,0,0,0,0,0) );

//DirectX9 Initializations
IDirect3DDevice9* g_pD3DDevice;
IDirect3D9*       g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );

//Create Device
g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                &d3dpp, &g_pD3DDevice );

ShowCursor(FALSE); // g_pD3DDevice->ShowCursor(FALSE);

do
{

g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100,100,100), 1.0f, 0 );
g_pD3DDevice->BeginScene();
// Rendering of scene objects happens here



// End the scene
g_pD3DDevice->EndScene();
g_pD3DDevice->Present( NULL, NULL, NULL, NULL );

} while ( !GetAsyncKeyState(VK_ESCAPE) );
 
}


I have tried some things to print 2D Text like "Hello World" to the DX screen. As far as i have read their are different ways to draw text on a DX screen... There is a GDI (slow?) GDI solution and direct DX solutions. I am a bit confused what way is the best (even for 1k/4k) and how to add it to the source.

ID3DXFont      // The interface for creating our font?
ID3DXFont::DrawText
D3DXCreateFont
D3DXCreateFontIndirect

I have looked to some sources on the web but i dont get managed to draw any 2D text to the screen :(
Btw, where can i find a pack full of 1k and 4k DX9 intros with sources to learn from? Does someone here as the zip with some nice releases and sources available by a forum member here in the past? ^^ thx!

« Last Edit: November 19, 2008 by va!n »
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #1 on: November 16, 2008 »
Ok, after some hours i finally managed it to draw some text to the screen but i think something is somewhere wrong with the code... it compiles without erros but with warnings and crinkler dont like the OBJ file when the "D3DXCreateFont" command is active :P

Code: [Select]
void WinMainCRTStartup()
{             
HWND hWnd = ( CreateWindowEx(WS_EX_TOPMOST,"edit",0,0,0,0,0,0,0,0,0,0) );

//DirectX9 Initializations
IDirect3DDevice9* g_pD3DDevice;
IDirect3D9*       g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    LPD3DXFONT   lpFont;

//Create Device
g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                &d3dpp, &g_pD3DDevice );


D3DXCreateFont( g_pD3DDevice, // D3D device
96, // Height
0, // Width
FW_DONTCARE, // Weight
0, // MipLevels, 0 = autogen mipmaps
FALSE, // Italic
ANSI_CHARSET, // CharSet
OUT_DEFAULT_PRECIS, // OutputPrecision
ANTIALIASED_QUALITY, // Quality == DEFAULT_QUALITY
DEFAULT_PITCH | FF_DONTCARE, // PitchAndFamily
"Arial", // pFaceName
&lpFont); // ppFont */

ShowCursor(FALSE); // g_pD3DDevice->ShowCursor(FALSE);

RECT rt ={0,0,640,480};

do
{

g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,100), 1.0f, 0 );
g_pD3DDevice->BeginScene();
// Rendering of scene objects happens here

lpFont->DrawText(NULL, "Hello World", -1, &rt, DT_WORDBREAK | DT_NOCLIP | DT_CENTER | DT_VCENTER, 0xFFFFFFFF);

// End the scene
g_pD3DDevice->EndScene();
g_pD3DDevice->Present( NULL, NULL, NULL, NULL );

} while ( !GetAsyncKeyState(VK_ESCAPE) );
 
}

How to change the atributes in D3DXCreateFont() when wanting the same size like in Office "Arial 48" for example? Heigh and Width to 48 seems not to be the same.
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [VS2008] DX9 Questions
« Reply #2 on: November 16, 2008 »
From the documentation, so untested:
Code: [Select]
height = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)(Yes, that's a negative height!) Set width to 0.
On my PC, GetDeviceCaps(hDC, LOGPIXELSY) returns 96, so for a 48 point font, this would give
-(48 * 96)/72=-64

Not sure if you'll ever be able to use crinkler with d3dx.  What's the error message?

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #3 on: November 16, 2008 »
@Jim:
thanks for the fontsize algo...
crinkler gives me following error message:

Code: [Select]
D:\_Coding_CPP\Crinkler>crinkler /SUBSYSTEM:WINDOWS  /COMPMODE:SLOW /CRINKLER  /
ENTRY:WinMainCRTStartup main.obj d3d9.lib kernel32.lib User32.Lib d3dx9.lib
Crinkler 1.1 (Jan 12 2008) (c) 2005-2008 Aske Simon Christensen & Rune Stubbe

Target: out.exe
Subsystem type: WINDOWS
Compression mode: SLOW
Hash size: 100 MB
Hash tries: 20
Order tries: 0
Report: NONE
Transforms: NONE
Replace DLLs: NONE
Range DLLs: NONE

loading:
  main.obj  d3d9.lib  kernel32.lib  User32.Lib
  d3dx9.lib
 : fatal error: LNK   0: could Not find symbol '_D3DXCreateFontA@48'

i am not sure if its my fault or if there is any other and possible more size-optimized and crinkler-friendly way to draw 2D Text on a DX9 screen. Not sure, if there is something missing like  "something->" in the line where i use D3DXCreateFont()
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [VS2008] DX9 Questions
« Reply #4 on: November 16, 2008 »
Try going to
Project->Properties->Configuration Properties->General
Check that
Character Set=Use Multi-Byte Character Set
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #5 on: November 16, 2008 »
@Jim:
I have tried to change it to unicode... but no way to get it work with crinkler... :(
I am not sure how other ppl are doing 2D text in 1k/4k DX9 prods.
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [VS2008] DX9 Questions
« Reply #6 on: November 16, 2008 »
Why would you change it to unicode?   ???
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: [VS2008] DX9 Questions
« Reply #7 on: November 16, 2008 »
Seems to me that you have an old d3dx9.lib or a broken one  ???

I've successfully compiled it using crinkler, final file size is 728 bytes, using VC2005.

Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #8 on: November 16, 2008 »
@Jim:
ah sorry.. thought its the same as unicode... now tried to set multi-byte char...  still compiles as release version without prob... but when trying to use the created OBJ with crinkler i get always the same error as before...   : fatal error: LNK   0: could Not find symbol '_D3DXCreateFontA@48'
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #9 on: November 16, 2008 »
@rbz:
thanks for the info... btw its still strange... i have installed the latest DX9 SDK (Nov 2008) and using VS2008... i will try to uninstall the SDK package and install it new... maybe it will fix my prob...
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: [VS2008] DX9 Questions
« Reply #10 on: November 16, 2008 »
Btw, make sure you have providing the correct dx9 lib files for crinkler, you can use Libpath argument:

Eg.:
/LIBPATH:"C:\Program Files\Microsoft DirectX SDK (February 2007)\Lib\x86"
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [VS2008] DX9 Questions
« Reply #11 on: November 16, 2008 »
Check your paths in VC++
Go to:
Tools->Options->Projects and Solutions->VC++ Directories
Choose 'Library Files' from the top right drop down list.

Make sure the path to your DirectX SDK install folder
(eg. C:\Program Files\Microsoft DirectX SDK (February 2007)\Include)
 is before any that begin with 'VCInstallDir'.

You can rearrange them using the up and down arrows.

Do the same for 'Include Files'.

Jim


Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #12 on: November 17, 2008 »
Quote
/LIBPATH:"C:\Program Files\Microsoft DirectX SDK (February 2007)\Lib\x86"

@rbz:
thanks for the info, i didnt found out how to get it really work... I added this switch to my *.bat file and deleted all *.lib files i copied by hand into the folder place of my compiled *.obj and crinkler.exe

In the path of SDK are only DX related libs.... but now the system libs like Kernel32 and so on... Is there a way to add two paths for libs? One for the DX libs in the SDK folder and one for the libs comming with VS for win32 system?

Else i just have to copy again all needed libs by hand into an own folder where i use crinkler.
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [VS2008] DX9 Questions
« Reply #13 on: November 17, 2008 »
If you fix it in the UI as I explained, you don't need to fiddle with crinkler options at all.  DON'T copy any SDK libs into your own folder, you'll get in a terrible mess and we won't be able to help!
The problem you have is that the Platform SDK that comes with VS2005/08 has an old version of DirectX SDK in it (with a statically linkable d3dx.lib instead of the new export library).  If you use the static version crinkler won't work and your exe will be 100s Kb.  You need to make VS look at the newly installed SDK first by moving the directory up in the list, above the original ones.

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #14 on: November 17, 2008 »
@Jim:
Thanks! Have not saw your previous posting... i will give it a try... (however i have not added crinkler to VS2008. I just copy the created *.obj to a temp folder and then running crinkler by hand (a batch file i created).

@all:
sorry but i still have one more DX9 related question:

I would like to have a fullscreen background gradient like following picture, which i created with following code. So whats the best (tiny) way to add this? Theoretical i think it should be possible by creating/using "vertices and define for each corner a color" or creating/using a big texture? In praxis i have no idea how to do it atm... i am complete new to DX9 with CPP... thanks in advance

Code: [Select]
     For x = 0 To 640-1
         For y = 0 To 480-1
           SetPixel ( x ,y, RGB( x/3.0, 127, y/2.0 ) )
         Next
     Next


- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [VS2008] DX9 Questions
« Reply #15 on: November 17, 2008 »
Quote
fullscreen background gradient [...] using vertices and define for each corner a color or creating a big texture?
Both ways yield identical results (although textures are more flexible).
If you're heading for a really small filesize you should integrate it with the rest of the code as good as possible
So if you've got texturing enabled anyways and no need for vertex-colour elsewhere, it's probably best to use a texture (and the other way round).
For the moment I would recommend to fuck the filesize and learn the basics first.
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [VS2008] DX9 Questions
« Reply #16 on: November 18, 2008 »
@hellfire:
thanks for your reply... i dont need any textures nor vertices for the rest of the intro... so i will try to use vertices and define a color for each corner... hope google will help me how to use/work with vertices and how to color the corners to get the gradient background fx. (its all like experience coding and trying how things are working)

You are right and i absolutly agree with you, when saying i should learn the basics first! I have a very simple 1k intro idea since a long time and since i am trying to learn CPP/DX9 coding, i am trying to start with very basic stuff (Init/Open Screen, Draw 2D Text, Vertices for GradientBG) and try to fit this into a 1k framework. Btw, do have any good reference (url/book) for easy learning und understanding how to code DX9/CPP stuff like for Intro/DemoScene? Thx




- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [VS2008] DX9 Questions
« Reply #17 on: November 18, 2008 »
Quote
Thanks! Have not saw your previous posting... i will give it a try... (however i have not added crinkler to VS2008. I just copy the created *.obj to a temp folder and then running crinkler by hand (a batch file i created).
The easiest way to use crinkler with VS is to get the crinkler exe, rename it to link.exe and put it in the folder along with your .vcproj file.
Then go in to
Project->Properties->Configuration Properties->Linker->Command Line
and add
/CRINKLER
to the Additional Options box.

You might also need to set
C/C++->Optimization->Whole Program Optimization to 'No'
Linker->Optimization->Link Time Code Generation to 'Default'
otherwise crinkler will barf.
That way, no need for any batch files or anything, crinkler gets run as part of the ordinary build process.  If you remove the /CRINKLER option, the crinkler exe will just call the original Microsoft linker and you get a normal uncrinkled exe.


For drawing gouraud rectangles with the minimum of fuss, I suggest using the DrawPrimitiveUP() function.
You can then do something like
Code: [Select]
MYVERTEX vertices[4];
d3d_device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertices, sizeof(MYVERTEX))
That will draw a quad (two triangles in a fan) from the 4 vertices.
You might define MYVERTEX like this
Code: [Select]
typedef struct
{
  float x,y,z,w;
  D3DCOLOR rgb;
} MYVERTEX;
Then you need to tell Direct3D what your vertex looks like - you've got a post-transformed coordinate (you want to use 2d screen coordinates, and not have d3d do any rotations, right?) and a diffuse colour, so, once, before you draw anything
Code: [Select]
d3d_device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
You probably want to set the z to be in front of your clipping plane, and w to be 1/z.
Your 4 rgb values will be the 4 colours at the corners of your rectangle.  There are some D3D macros you might want to use.

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: DX9 Questions
« Reply #18 on: November 19, 2008 »
sorry guys...
now i have installed VS2005 (without uninstalling the VS2008 and DX9 SDK November version)...
When i try to compile rbz 1k DX9 framework i get following error, that the include file can not be found...

Quote
Befehlszeilen     Die temporäre Datei "d:\_Coding_CPP\1k_DX9_TUM\Debug\RSP00000334282508.rsp" wird erstellt. Inhalt:
[
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fp".\Debug/Tiny_DX9.pch" /Fo".\Debug/" /Fd".\Debug/" /W3 /c /ZI /TP .\Main.cpp
]Erstellen der Befehlszeile "cl.exe @d:\_Coding_CPP\1k_DX9_TUM\Debug\RSP00000334282508.rsp /nologo /errorReport:prompt" Ausgabefenster     Kompilieren...
Main.cpp
d:\_coding_cpp\1k_dx9_TUM\main.cpp(13) : fatal error C1083: Datei (Include) kann nicht geöffnet werden: "windows.h": No such file or directory
 Ergebnisse     Das Buildprotokoll wurde unter "file://d:\_Coding_CPP\1k_DX9_TUM\Debug\BuildLog.htm" gespeichert.
Tiny_DX9 - 1 Fehler, 0 Warnung(en)

So, why does the compiler dont find his own (header) file(s)? Is it just a settings problem in VS2005 or the project file?
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: DX9 Questions
« Reply #19 on: November 19, 2008 »
Have a look at this.
Challenge Trophies Won: