Bobby Anguelov's Blog

A day in the life of a wannabe game developer

Multiple High Resolution Timer Class for Windows – C++

Earlier i had posted a tutorial on doing high resolution timing on windows and i’d given a very basic class to act as a timer, now i found when doing my graphics work i often needed multiple timers and so i just extended my baby timer class a little to support multiple timers.

So you can create as many timers as you need on the fly (the controller class acts as a big timer vector) and also get a pointer back for each timer if you wish to create a easily readable shortcut ie.

HRTimer* animationTimer = timers[5];

hope you find it useful: MHRTimer.h

31 August 2008 Posted by Bobby | Programming, Windows, Windows Programming | , , , | 1 Comment

Beginning DirectX 10 Game Programming By Wendy Jones – Review

A search of amazon.com in regards to directx10 books yields only three entries: wendy jones’ book, a book by peter walsh which by all account is just a basic update of his previous directx9 book and recently a new book by frank luna which also seems just like an update of a previous book.

I purchased Wendy Jones’ book: Beginning DirectX 10 Game Programming in january of this year and have only recently had the time to sit and go through it. In brief I wasnt very impressed. This book is nothing more than a rehash of the tutorials available in the DX10 sdk, and to make matters worse you would think that she’d make an effort to improve upon the tutorials, that there would perhaps be more depth and clarity,  unfortuneatly she doesn’t.

What she’s done is taken clear concise tutorials and made them overly long, convoluted and tedious. All the problems in regards to explanation and presentation that are present in the SDK tutorial are present in her book. For example in one tutorial, they just show the instantiation of an object but never specify the object type name, so you have to dig around a little bit to get it, in her book the exact same thing occurs for the exact same section.

The only unique section she has is a chapter dealing with sprites which is not covered in the sdk tutorials and that could have been the only redeeming feature of the book but even that is written badly. What should be a short simple chapter gets dragged out, that chapter is nearly the length of the entire 3d section of the book.

Moving onto the 3D chapters, apart from the generic 3D primer and the cut and paste sections from the tutorials, there is practically no in depth information about what makes directx 10 different from directx 9 or even openGL. Lets not even get started on the quality of code present in the tutorials, i dont understand why she even attempted to rewrite the tutorials, she may as well have included the sdk examples. She does created a “modelObject” structure but this is not exactly a major change.

Also this book is entitled “beginning directx10 game programming” but should rather have been called “rendering 2 cubes and a basic mesh in directx10″ as this is the depth in which the text goes into. I’m not sure what the target audience is but having less than a 100 pages of a 350 page book dedicated to 3D graphics is plain unacceptable. The rest of the chapters cover directinput, and xinput.

Her explanations in these 100 pages are unclear, and the only depth covered is an explanation of input parameters which any beginner can get from the sdk docs anyways, there is absolutely no explanation of what functions actually do, why they do them and give the reader a basic intro into the dx10 pipeline and API. Alot of important information is missing and i had to end up digging up myself, especially in regards to displaying multiple objects.

Let me try explain how bad the source code examples are: in the triangle example she calls an initTriangle function to initialize the triangle, this now goes and creates an input layout. Now for a beginner, they might assume that for every object you make you need to create an input layout, seeing as the modelObject structure has that as a member. When in reality you only need to create one input layout for a specific vertex type, and only swap it if you pass through different types of vertices. The same goes for effects and techniques. Also she never really mentions how you would handle multiple objects properly, especially with the lack of a fixed function pipeline.

The just for a low blow, in the example where she renders a 3d cube, the initialization function is called and wait for it: initTriangle… You can see a lot of effort went into this book. (sarcasm!)

I feel the author herself doesnt have a solid grasp of DX10 and has ended up just writing a book for the hell of it, her tutorials dont convey any level of understanding but rather just say: want a vertex run this function call.

UPDATE: I’m now sure the author has very little understanding of dx10, in her book she implies that you need to create a vertex buffer for every object you wish to draw! This is a bad practice especially in regards to perforamnce. The vertexbuffer is a block of memory which you fill prior with vertices prior to sending it to IA. You’ll have a list of vertices stored in an object container, and you would load up the vertex buffer with the vertices from the object and then draw it. Seeing as there is no way to change the size of the buffer once created nor is there a way to delete it, all you can do is update the data stored within the buffer. That is the reason the draw call takes the number of vertices and the offset as a parameters.

So why cant we just create a buffer for each object, imagine we have a scene with 1000 objects, each object has 1000 vertices, so now we have 1 000 000 vertices stored in memory, the swapping of vertex buffers is a slow operation and having to swap out the vertex buffer 100 times each frame has a major performance impact.

I’ve gone through her book thoroughly and then started to do a very basic b-spline demo in dx10 and quickly realised how much information i was missing, how badly things were explained and how she’d simply ripped off the sdk tutorials. I also ran into a major problem trying to organise and store my object never mind draw them, i’ve spent two weeks messing around until i finally ended up slapping together a very basic DX manager class with a polymorphic object container hierarchy.

My advice is avoid this book,  dont waste your money, rather download the dx10 sdk and go through their tutorials, you’ll find them more useful and better explained.

Oh and speaking of ripping off tutorials: there is this jackass ( http://www.kevindonde.com/ ) that is ripping off her tutorials and putting them up on the net as his own.

I’ve spent the better part of two weeks now digging in the SDK docs and browsing the web for solutions to my very basic problems and so forgive my frustration. I will hopefully write my own tutorials on directx 10 in the upcoming weeks and i do hope that they might actually be more useful than hers. I’ll also try and get hold of frank luna’s book and see if that is any better.

23 August 2008 Posted by Bobby | DirectX 10, Graphics Programming, Windows | , , , | 20 Comments

FPT Toolkit and my first steps into win32

 The screenshot above is my latest little project, a windows based tool for the decomposition of image using my fast pulse transform (FPT) technique. It needed to have a few features like file IO, pulse selections and highlighting of pulses. I’ve never done any sort of c++ winapi programming before apart from some windows forms stuff in c#. I figured since i’m busy messing around with win32 in my openGL and directX adventures, i might as well just use that. :/

Probably not the smartest decision, since the bare win api is c based and not c++ based and so the way the api is structured is based on c techniques. I’ll be honest and it took me a day or two to get used to it and to figure out how most things occurs and now i’ve pretty much got the gist of it. Now it comes down to using the msdn docs to find out what the flag values i need are, and trying to figure out when specific messages are sent. I’ve got a very basic grasp of it at the moment. I wish i could spend more time messing around with it but i need to focus on this semester and finish learning directx 10. And even so once that is done, i think i’m gonna focus on learning MFC or windows forms even as it seems the bulk of development is done using these APIs. From what i can see most window game dev toolsets are developed in MFC.

So some last words about my app… i couldn’t for the life of me figure out how the fuck DIBs and HBITMAPS work (creating DIBs programmatically at least – the conversion from DIB to HBITMAP was simple enough) so i had to use openGL to display my 2D images (haha, oh well its not like people don’t have openGL videos cards these days). I just got the pulse selection and reconstruction saving working, just need to finish the highlighting section and its done (for now). I need to sit and think logically about what i want for the highlighting interface and then code it.

I have struggled these last few days trying to learn winapi programming from scratch using nothing more than google and the MSDN docs but at the same time I’ve learnt a lot and so its been worth it! OH and for a development environment: visual studio 2008 + vista 64 is a dream come true :P

21 July 2008 Posted by Bobby | Computer Vision, Image Processing, Programming, Windows, Windows Programming | , , | No Comments Yet

High Resolution C++ Timing on Windows

Accurate Timing is something that seems simple until you actually try it, at first people would be like just get two timestamps and minus them, sure that works for per second timing but what about millisecond or even microsecond timing?

Just get 2 millisecond timestamps and minus them, right? No, the problem comes into that when the CPU is heavily loaded, often the timestamps will be significantly off, i noticed this in my surveillance project, where a specified time of 10seconds ended up being between 5 to 15 real seconds depending on the load on the processor.

So how do you do accurate high resolution timing in windows? Before people made use of the now antiquated Multimedia timers, these days you simple use the Windows API QueryPerformanceCounter and QueryPerformanceFrequency functions.

 The QueryPerformanceCounter function call returns the value of the performance counter (in counts) at that point and the QueryPerformanceFrequency returns the amount of counts per second for that processor… You can see where i’m going with this, Simple huh? :P

The only other thing you need to take into account is that you need to make use of the LARGE_INTEGER union type for the count storage, since the count is a 64bit int you need to make use of the QuadPart (LongLong) of the union for storage.

here’s a very basic c++ timing class: HRTimer.h

4 January 2008 Posted by Bobby | General, Programming, Windows, Windows Programming | , , , | 4 Comments