#### Archived

This topic is now archived and is closed to further replies.

# DX8 (very) newbie problem

## Recommended Posts

olemann    122
I''ve just started looking at DX8 programming (and DX-programming in general). I have worked through Andre LaMothe''s books (WinGame Progr. For Dummies and Tricks of the WinGame progr.gurus...) Recently I bought Peter Walsh''s book on advanced 3-d game programming DX8, and felt quite confident that I would do some simple D3D-programming in a short time. But my problem is that all the programs on the CD that came with the book, runs badly on my computer. Every program that goes fullscreen, just seems to set screen resolution, go fullscreen but then gets transparent. The result is that I only se my Windows Desktop / Visual C++ blown up to the resolution the D3D program is running in, and can''t see the actual program''s window. The program does not crash (I can close it with ESC or alt-f4), just runs like a "see-trough" window on top of my other programs. I''ve both tried to recompile the programs with the source and run the exe-files on the cd. Both give same result. I''ve tried to reinstall DX8.1/DX8 SDK. All other DX-programs are running fine. Is this a ''standard'' problem that someone knows a solution too, or do I just have to live with this. It kinda sucks as I''m not able to program any fullscreen programs and test them (at least with the techniques outlined in Walsh''s book). Maybe this is to vague/newbie, but I try anyway, hoping someone says "All you have to do is...[fill in something]"

##### Share on other sites
stefandxm    122

it sounds like bad graphics card and/or bad drivers
shouldnt have to do with dx at all

##### Share on other sites
russian-bear    122
The examples from that book preforms very bad on my own comp as well, its a dual AMD MP 1.2g and a GF4 Ti4400 ! He is using a totaly screwed up technique for rendering 2d in d3d 8. The book is great for an introduction to windows programming / and an overview of D3D8 but don try to learn his ways to draw things its just not a good practice to blit to backbuffer in D3D8 !

You can actualy try DEFAULT values for refresh rate and presentation interval it might increase the performance in fullscreen..

##### Share on other sites
olemann    122
I thought of that too (beeing a hardware/driver problem), but isn''t it strange that all other games/progs (including MS direct3D test prog) is running smooth?

Anyway, here''s my specs:

Win XP
Athlon 1.1
Geforce2 GTS (w/ 21.83 WHQL) (running this because of Infinite Loop problem in XP)
256 Mb ram
VIA syschip (flashed to newest)

Maybe the somewhat dated nvidia drivers is the problem? Problem is all the newer drivers makes XP crash (the infamous infinite loop)

Thanks for taking your time! :o)

##### Share on other sites
olemann    122
quote:
Original post by russian-bear
The examples from that book preforms very bad on my own comp as well, its a dual AMD MP 1.2g and a GF4 Ti4400 ! He is using a totaly screwed up technique for rendering 2d in d3d 8. The book is great for an introduction to windows programming / and an overview of D3D8 but don try to learn his ways to draw things its just not a good practice to blit to backbuffer in D3D8 !

You can actualy try DEFAULT values for refresh rate and presentation interval it might increase the performance in fullscreen..

OK. So his code isn''t exactly something I should try to incorporate as my own way of coding DX? :-) Good to hear that it''s not only me having problems with that code. It would still be nice to find out what causes this problem, though.

Any other books you would recommend that covers the same topics, but with nicer code?

Thanks!

##### Share on other sites
core    106
quote:
Original post by olemann
Every program that goes fullscreen, just seems to set screen resolution, go fullscreen but then gets transparent. The result is that I only se my Windows Desktop / Visual C++ blown up to the resolution the D3D program is running in, and can't see the actual program's window. The program does not crash (I can close it with ESC or alt-f4), just runs like a "see-trough" window on top of my other programs.

You might try looking the code over really well. Find where the members of the window class structure (WNDCLASS or WNDCLASSEX) are filled out. In his code the hbrBackground member of the WNDCLASSEX structure is probably set to fill the window with the 'hollow' or transparent look you've seen. Try setting the hbrBackground member to (HBRUSH)GetStockObject(BLACK_BRUSH). That'll change it to black (other colors are possible). Hope this helps.

"If people are good only because they fear punishment and hope for reward, then we are a sorry lot indeed." - Albert Einstein

[edited by - core on May 2, 2002 11:41:27 AM]

##### Share on other sites
Guest Anonymous Poster
Um. Shouldn''t the HBRUSH be set to NULL? And fill the background with directX instead?

##### Share on other sites
olemann    122
Now I''ve tried setting the hbrBackground to black. That didn''t make any difference at all, the window is still transparent.

The original code from the cd reads:

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = GlobalWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = AppInstance();
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszClassName = m_name.c_str();
wcex.hIconSm = 0;

I tried with
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

But as I said, it didn''t mean any difference.

How do I fill the background with DirectX, like one of you said? Could that be the solution to this?

I really appreciate your effort in trying to helping me here. I''ve been tempted to just lay off this whole DX8 programming as I never even got an empty black fullscreen working.. :-)

##### Share on other sites
a person    118
my suggestion is to get another book. make sure its a basic book since you dont seem to know the win32 api yet. learn the win32 api correctly. also, i would ask ppl a good book to use, as well as read user reviews at sites like amazon. this will ensure you get a great book for your level and not something that teaches things wrong to make it "easier". ANY book where the examples dont work would go back to the store if i bought it. worst case is that they dont take it back, but more then likly you can get store credit (dont ask for money, less chance they will consider that). you can then put that towards a better book. amke sure the book is in good condition, cd is in the sleeve, and you do it soon. the longer you wait the harder it becomes. just tell them that the cd is not working and that you think it might be because the stuff is too advanced for your computer. most books dont give system requirements on the cover so you are lucky in that respect.

##### Share on other sites
russian-bear    122
No its nothing like that ithink...
There is some things that have great impact on performance (atleast for my system) i have marked them with *** :

    	d3dpp.BackBufferWidth = bWindowed ? 0 : SCREEN_WIDTH;		d3dpp.BackBufferHeight = bWindowed ? 0 : SCREEN_HEIGHT;	d3dpp.BackBufferFormat = bWindowed ? d3ddm.Format : D3DFMT_A8R8G8B8;		d3dpp.BackBufferCount = 1;	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;		d3dpp.hDeviceWindow = hWnd;		d3dpp.Windowed = bWindowed;		d3dpp.EnableAutoDepthStencil = TRUE;	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;	***d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;	***d3dpp.FullScreen_PresentationInterval = bWindowed ? 0 : D3DPRESENT_INTERVAL_DEFAULT;	***d3dpp.Flags = 0;

You should learn about all those parameters and how they work.
No if you notice the parameter 'd3dpp.Flags = 0' because i dont use the lockable backbuffer. You should avoid that at all costs cause nowdays graphic cards is more optimal for 3D primitives and math than for blitting to backbuffer like the old days.

Now you should realy learn how to use D3D8 for 2D graphics..
If you can aford to by another book you should defenatly go for "Programming Role Playing Games with DX8". This book is so damn great it will blow your mind ! A realy good friend to that book is "Special FX Game Programming With DX8" its great too. And when you realy getting advanced you should aim for "Realtime Rendering Tips And Trics With DX8". If your realy wanna go for hardcore 2D programming in D3D you should get the book "2D in Direct3D". Havent read that one but i have looked inside in the bookstore and it was great.

But start with "Programming RPG with DX" its realy good, thrust me!

If you have any questions just dump them here in the forum. I got alot of help in here since i started with DirectX about five weeks ago!

[edited by - russian-bear on May 2, 2002 1:54:34 PM]

##### Share on other sites
olemann    122
quote:
Original post by a person
my suggestion is to get another book. make sure its a basic book since you dont seem to know the win32 api yet. learn the win32 api correctly. also, i would ask ppl a good book to use, as well as read user reviews at sites like amazon. this will ensure you get a great book for your level and not something that teaches things wrong to make it "easier". ANY book where the examples dont work would go back to the store if i bought it. worst case is that they dont take it back, but more then likly you can get store credit (dont ask for money, less chance they will consider that). you can then put that towards a better book. amke sure the book is in good condition, cd is in the sleeve, and you do it soon. the longer you wait the harder it becomes. just tell them that the cd is not working and that you think it might be because the stuff is too advanced for your computer. most books dont give system requirements on the cover so you are lucky in that respect.

Well, I think Andre LaMothe''s books covered the basic Win32 API stuff that I needed to know. As far as I can see, this problem is not a WinAPI problem, but more of a DirectX one. And even though this book by Peter Walsh is called "Advanced 3-D game programming" I am really not too intimidated by the level of difficulty. It''s just that i can''t seem to get the code from _that_ book to work on my computer. Other DirectX applications I have compiled, work like a dream. Would just be nice to make his examples work, too.

(I bought the book on Amazon.co.uk a month ago, and I live in Norway, so I guess I won''t bother to try to return it).

Thanks, anyway! :-)

##### Share on other sites
olemann    122
russian-bear: Thank you for an informative answer. I''ll take a look at the code you pointed out could make a performance hit, and see if I can do some changes there.

Guess I will get out and buy "Programming Role Playing Games with DX8", and have a look at that. :-)

Guess I won''t give up on Walsh''s code, since I have no problem getting other DX8 2D/3D programs compiling and running.

Thanks for all your help, and I''m sure this won''t be the last time I''m posting here. You guys answered pretty fast and friendly, compared to other boards I''ve been to.

##### Share on other sites
russian-bear    122
Try to search books at ''www.Pricerunner.com'' i found books there much cheaper than at ''Amazon'' !

##### Share on other sites
Your problem is actualy in the quality of your hardwar combined with the non-quality of walshes code you have a geforce 2 so to run these samples you must use ref rast and wash does not provide the correct code to do that job.

##### Share on other sites
Guest Anonymous Poster
I have Peter Walsh''s The Zen of Direct3D. I had problems with most (if not all) the source code on the CD when starting to render full-screen 3D scenes. I went to the Primier Press website, found his book (and downloads, etc.) at http://www.premierpressbooks.com/searchdetail.asp?ID=53429

He mentions this for *GeForce users*:
"New GeForce cards do not like using the alpha channel, particularly on XP. Use of the alpha channel causes the frame rate to drop to very low levels and sometimes appears to stall the machine. To disable the alpha channel change the flag, in the setup code, from D3DFMT_A8R8G8B8 to D3DFMT_X8R8G8B8, which does the trick."

I did this and it did the trick (as I have a GeForce3 Ti-500). Thought it might help with your problem.

##### Share on other sites
russian-bear    122
But if you turn off alphablending how are you supose to make semitransparent objects or textures?

##### Share on other sites
olemann    122
quote:
Original post by Anonymous Poster
...

He mentions this for *GeForce users*:
"New GeForce cards do not like using the alpha channel, particularly on XP. Use of the alpha channel causes the frame rate to drop to very low levels and sometimes appears to stall the machine. To disable the alpha channel change the flag, in the setup code, from D3DFMT_A8R8G8B8 to D3DFMT_X8R8G8B8, which does the trick."

...

I tried this, and now every bit of code I''ve tried to compile with Walsh''s methods, so far, works smooth! Thanks a lot for this tip, now I can finally see the code in action. Even though, as ''russian-bear'' says, it can get me in trouble when I try to make semi-transparent objects/textures.. :-)

Thanks a lot.