Archived

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

Zen and art of D3D. Why do all the examples run slow?!

This topic is 5503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Specifically the one in Chapter 12... All it is is a Single Triangle!!!!! On my Geforce4 its getting no more than 6 FPS!!!!! Unbelievable! Where is the slowdown?

Share this post


Link to post
Share on other sites
I had that problem too... with all the examples in the book. I never examined it, but I think it has to do with his timing function. He tries to adjust the framerate from frame-to-frame somewhere, and that has got to be what''s slowing it down. I imagine the examples were written on an older version of Windows (non XP), and that may be the trouble... though I can''t be sure.

Share this post


Link to post
Share on other sites
I dont think the example in chapter 12 ever makes a call to the timer function.

In fact I commented out everything in the code except the portion that renders the triangle. Still 6 FPS!

There is an example in the DirectX SDK code that is very similar, a single spinning triangle. I converted that example to full screen mode using the exact same present parameters as the Zen example. The SDK code zooooms in full screen mode.

I just dont get it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Inside the InitDirect3D function he uses a parameter D3DBACKBUFFER_COPY or something like that. Change the _COPY to _DISCARD. That took my framerate from 10fps to over 1000fps!! (Infact I had to change the frame rate drawing function to alow 4 digit numbers to prevent a crash.) I will look up the exact line and parameter when I get home and let you know. But that should be enough to get you back on track.

Share this post


Link to post
Share on other sites
Not sure about your slowdown issue, but I''ve got a question about another thing with that book. He''s lumped all of his classes in a single Engine.h file which is annoying for me, and makes it a nightmare if you try to expand on his code to build something larger. The problem is that if you try to move some of those classes out of that file and make them their own .cpp and .h classes, you lose access to some of the rendering functions he has built without adding pointers to whatever you used to have access to.

I don''t have an example in front of me because I''m at work ... but have either of you encountered this design issue? How''d you go about resolving it?

If I recall correctly ... I''m encountering this problem particularly when I''m working with the console ... and the CConsole is works with the CEntry , which in turn calls LoadBitmapToSurface() which needs a reference to the primary rendering device ... etc. Do I just end up passing references to the primary rendering device through every object I instantiate?

If this is confusing or I screwed it up, I''ll get the exact example when I get home ... but I''ve tried reworking the whole basic architecture twice (once, encapsulating the entire Engine.h file as part of a main Engine object, and another ... pulling it back out as a stand-alone common .h file) and things still don''t seem natural. I''m just trying to avoid problems down the road as the engine gets more complex.

Thanks,
Telstar

Share this post


Link to post
Share on other sites
I realised that I had the code on my work PC too. And I also thought it would be nice to register to the forums.

The function that the problem is in is InitDirect3DDevice, which the authour places in the engine.h file. I''m told that its hugly bad practice to have code in header files so I moved it. I guess you may have moved it too.

You''ll need to find his swap effect code:
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;

And change it to:
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

I think that frees DirectX from having to make sure that the backbuffer does not get used to store any data between frames. I assume this is surprisingly inefficient. Strangly this point is made early on in the book, but seems to be forgotten by the time you get to chaper 12.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Inside the InitDirect3D function he uses a parameter D3DBACKBUFFER_COPY or something like that. Change the _COPY to _DISCARD. That took my framerate from 10fps to over 1000fps!! (Infact I had to change the frame rate drawing function to alow 4 digit numbers to prevent a crash.) I will look up the exact line and parameter when I get home and let you know. But that should be enough to get you back on track.



Are you talking about this:

// The swap effect
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;

//So it would look like this?
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD_VSYNC;

Share this post


Link to post
Share on other sites
Hi Telstar, having the source code in the .h file bothered me too. I''m fairly new at this so I don''t know how the pros split their code between .cpp and .h files. However, my solution for the code examples in Zen of D3D was to have a .cpp and .h for each general area of the code. For example a console.cpp and console.h, engine.cpp and engine.h, etc. I have been puting the class definitions and function prototypes into the relavent .h file, and the source code in the .cpp. Any global variables I decalre in the .cpp file that they are first used. Assuming that these globals will be needed in other source files I have them also defined with the extern keyword in a general .h file which I call for every .cpp. That seem to work ok, calling the .h file for any module that a .cpp needs. For instance font.h to use the font engine in the console.cpp.

I hope this isn''t too patronising, or too much of a newbie point to post on these forums. Zen seems like a very good book, but several mistakes have had me stumped and clearly others too.

Share this post


Link to post
Share on other sites
Not patronizing at all. I''m here for help and happy when people are willing to provide it.

I''ve been splitting my classes off as it sounds like you have. The thing I forgot about was the extern keyword. I had a mess of parameters being passed all over the place but extern should solve that. I''ve been away from C++ for a number of years and I think I''m seeing the result.

Thanks again,
Telstar

Share this post


Link to post
Share on other sites
Yep the swap effect was the problem. I was starting to get worried about this book as a good source to learn DirectX8. Ive seen posts on the net saying it teaches bad habits.

Thanks for the help guys!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It''s generally best to avoid books that are the "Zen of...", the "Tao of..." or "... for Dummies". Unless, of course, you are a zen buddhist, a taoist, or a dummy. In all seriousness though, by and large this should be a warning sign.

Share this post


Link to post
Share on other sites
Actually I thought The Zen of Direct3D was quite good. However, you really shouldn''t be trying to just copy and paste his code. If you truly understand what the code is doing then you should have no problem at all seperating them into seperate files and classes.

Share this post


Link to post
Share on other sites
Ok, time for my rant:

Zen of D3D is one of the worst computer books I have ever read, period. His "LaMothe Jr." style of writing is annoying to the point of being distracting (One should not be "getting jiggy" with "bad puppies" that many times. Anywhere. But esp in a PROGRAMMING book.), his code is half-implemented speghetti that''s the usual Premier mish-mash of c and c++, neither language implementation being elegant, and there''s much better books out there to learn D3D under.

If you''re bent on going Premier, go focus on 2D in D3D for straight D3D API, and use gamedev and the SDK docs for whatever else you might need to know. Go for RPG Programming for full game engine stuff w/ D3D. It''s real quality.

Spec FX ain''t too bad either, but you might not really need that if you''re just starting.

Share this post


Link to post
Share on other sites
Yeah I really wasnt too impressed with this book either.

Ive yet to see a book that doesnt waste 500+ pages on Matrix Algebra, begginning Windows programming, C++ primer, etc.

Yeah and the d00d speak is enough to make one puke. It adds nothing and justs wastes trees.



Share this post


Link to post
Share on other sites
I haven't moved into the 3D portion yet, but I can say the 2D portion is only good as a introduction to directx, because the way he does his 2D graphics is sloooooow. If you want to use DX8 for anything 2D, this book isn't good. (but then hey its really about the 3D, i just still wish he hadn't wasted the time with the way he did his 2D graphics)

That and what was with the big engine.h file? I'm not a pro coder, but i wouldn't think it was a great idea to stash everything in there.
That in conjunction with the mysterious absence of any mention of DXTrace has me wondering how good of a coder Peter Walsh really is.

Can anybody recommend a good book as an addition to this one? I know that the RPG book by Premier is supposed to be good, but ive already learned most of basic DX stuff.

-Paul-


[edited by - Dovyman on November 22, 2002 10:02:43 PM]

[edited by - Dovyman on November 22, 2002 10:09:48 PM]

Share this post


Link to post
Share on other sites
I can''t understand why so many people call this the Uber-book of all 3D programming books.
I leafed through a friend''s copy of Zen after reading so many good reviews of it, and was not impressed at all. It was annoying to read, and the examples were downright awful. What is up with that gigantic header file? Besides, the samples ran at horrific rates, so I decided to go for another book to get me into D3D.

I browsed around a bit on amazon and went for the book nobody seems to know: Advanced 3-D Game Programming Using DirectX 8.0, apparently a revison by Peter Walsh of the original 7.0 version by Adrian Perez and Dan Royer. Many reviews slammed this book for the fact that it wasn''t advanced at all, just basic beginner''s stuff. Which was good, because that was what I wanted. Reading through more reviews, I decided that I found all the good points people mentioned more important than the bad points, and bought the book.

This is probably not the greatest or most complete D3D book around, but it taught me basic 3D math and techniques such as quadtrees and such, and introduced me to the API in an understandable way. After having read it, I finally understood what the DX help file was talking about.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Although the zen book helped me in the beginning his extremely poor coding and some non working samples put me off greatly. Many statements in the book are downright wrong and it is a beginners book for more than half the book. If it is a "zen" book it is supposed to be advanced stuff in it but this book is mediocre at best. Many samples were slight variations of the samples found in directx sdk anyway. If you want to learn DirectX then just download the sdk and go through the tutorials there, then use the help docs and go from there you will learn more, better and quicker I can assure you. Besides, his "engine" is a very bad way of tutoring. Code should never be "hidden" like that if you want to learn someone anything.

Share this post


Link to post
Share on other sites