I have a lot of respect for the folks at Wolfire, they’re working on what looks to be quite a cool game with some innovative concepts and their regular blog updates detailing the various element of their engine is always inciteful and interesting.

However a post by David titled ‘Why you should use OpenGL and not DirectX‘ bugged me for a few reasons, it read like a fanboy post and didn’t give any actual reason as to why one should use OpenGL instead of DirectX but instead about Microsoft using hyperbole in marketing and that it has created a ‘vicious cycle’ of developer feedback.

David structured his post by putting his reasons and explaining his rationale behind them and as such this post is similarly structured as his blog post. Of course this is simply a rebuttal article, I’m not trying to sell DirectX but rather highlight in what ways Davids arguments effectively fail by either being irrelevant or misleading.

Why does everyone use DirectX?, actually, not everyone uses DirectX

To answer this we have to acknowledge the question has a major flaw in it: Not everyone uses DirectX, in fact you would be hard pressed to find DirectX to be used in a Computer Aided Design (CAD) field. The ARB, which is the group that defines OpenGL specifications has very little game development influence, it is mostly controlled by companies interested in developing CAD software.

Network effects and vicious cycles, or why DirectX is such a better alternative to OpenGL for games development

So the reason DirectX is so much more popular than OpenGL is because DirectX caught early on and as such has created a ‘vicious cycle’ between vendors and developers where DirectX is continually improved while OpenGL lags behind. This a moot point, I would like to know in what ways, if any, DirectX has held game development back. Microsoft has spent more on developing DirectX as the premier graphics solution for game development than any OpenGL developer has ever, of course the biggest OpenGL developers are not in the games industry. Microsoft has lost money in this area and regardless of what any fanboy would like you to believe most of that money did not go into marketing DirectX but R&D.

FUD about OpenGL and Vista So what?

David claimed that Microsoft spent a lot of time spreading fear and doubt as to the future of OpenGL during its marketing for Windows Vista and DirectX 10. Whether Microsoft correctly or incorrectly spread malicious rumours about OpenGL is debatable, whether OpenGL has given game developers the cold shoulder with a botched 3.0 specification is not as the thread comments indicate. Whatever damage Microsoft may have done to OpenGLs reputation through deceptive advertising could not damage OpenGL as much as when it shot itself in the foot with the 3.0 specifications.

Misleading marketing campaigns ^ as above

The other points brought up are about Microsofts shady marketing tactics, however shady or not does not actually affect the API itself and regardless of what Microsoft says DirectX can do as a developer I would rather concentrate on seeing whether DirectX or OpenGL is more suited towards what I want to do. Let’s face it, if we’re going to avoid products which were backed by marketing using hyperbole we’d still be using the abacus.

While David is happy quoting people like John Carmack saying he doesn’t see a need to jump straight into DirectX 10, a valid argument by all accounts given most highend games released these days are multi-platform console titles he doesn’t say what Carmack thinks of DirectX in general, “Microsoft has done a great job with all this stuff. I mean, I honestly think that DX9 with how it’s implemented on the 360 is a clearer and more open API than OpenGL is.”

In other words: Just because we’re not using DirectX does not mean we don’t think it’s a great API, and when we have to use it we don’t mind it too much. More to the point it highlights the deceptions David uses, he attempts to inflate Carmacks hesitation to move into DirectX 10 as a general dissatisfaction with DirectX as a whole.

OpenGL is more powerful than DirectX, are you a software engineer or an OpenGL fanboy?

This is where I start doubting David is coming up with these opinions because he actually believes DirectX is a weaker API or because he simply dislikes Microsoft. First of all, what is power? OpenGL and DirectX are both specifications, in terms of power they’re little more than ideas with a software layer backing them up. The question is, which API has better support in consumer hardware and therefore will run better. Regardless of the power OpenGL may have, buggy drivers and a poorly conceived API will still bring it down. I don’t know about David but I would gladly lose 20% performance for 30% more clarity.

Now here comes the hypocrisy, while David is happy to attack Microsoft for FUD he does the same thing throughout his post but here in particular: he claims the tessellation feature in DirectX 11 has been an OpenGL extension for three years. I think he will be very, very shocked to find out that the Xbox 360s DirectX based GPU has a tessellation unit built in, something which the Playstation 3 RSX lacks. An OpenGL extension is only as good as the hardware and developer support behind it, ATi put tessellation support into their first batch of DirectX10 graphics cards (the ATI2900’s) as well as the Xbox 360 giving developers these capabilities almost five years ago, two more than OpenGLs 3. Of course who put what feature into graphics technology first doesn’t really matter, I’m merely highlighting the flawed argument David is using when he refers to OpenGL extensions, anyone can extend on specifications.

Now for the final nail to shut this debating point down, since David is so fond of mis-quoting Carmack to sell his own point let’s see why Carmack doesn’t like the idea of ‘power’ saying in 1997: “In any case, the D3D/OpenGL argument hasn’t been about speed, but about usability, robustness, and portability”. He was right back then and he is right today, of course those of you who have been reading rather than skimming up to this point will know Carmack believes DirectX has evolved into a much better API than it was back in 1997.

OpenGL is cross-platform +1 OpenGL

A key advantage OpenGL has over DirectX, however hardly a reason in on itself to use OpenGL over DirectX, especially if you’re fine with developing exclusively for Windows (which a lot of people are). However to add to it, just because OpenGL is cross-platform does not mean you can’t make a cross-platform engine which uses DirectX on one platform and a different API on another. CryEngine 3 and UE3 are two good examples of this.

OpenGL is better for the future of games, actually not really, not at all in fact

As I have stated many times previously, core OpenGL specifications are controlled by the ARB which is made up of a consortium of various developers and hardware manufacturers. While both AMD and nVidia are on the board they are far outnumbered by various groups interested in CAD development. The OpenGL 3.0 spec’s were met with a lot of criticism (even by the fuhrer) by game developers for compromising too much for the benefit of CAD developers afraid of losing backwards compatibility on five year old hardware.

Finally David concludes by saying we need competition and freedom to ‘drive down prices and drive up quality’. Honestly that is little more than rhetoric you’ll hear at a Republican national convention, if Sarah Palin was a programmer she’d argue her point like that. Rhetoric is just that, the truth is however that DirectX is free, it is really easy to use and tuned for game developers.

So can OpenGL recover? Yes, of course it can, but to do that it must break off from the main OpenGL branch. OpenGL ES is a good thing, a separate set of standards meant to benefit game developers. However it has a long way to go and won’t be fully mature until it has re-invented itself as a graphics API for game developers, not a graphics API for CAD developers modified to be more tolerable for game development.

There I said it, this game is just awesome. I’d talk more about its gameplay and story but all I have time for is uploading the opening cutscene (with boobies, NSFW, etc). It’s Pandemics best game yet and while a sad end to the studio at least one which doesn’t ruin its legacy. Unfortunately after massive profit losses constrasted with Activisions successes we’re probably not going to see games of this sort being released anymore as EA seems to be shifting focus back to what made it big.

Sad ‘gaming is dead’ stories aside I’ve uploaded a bit of the options menu and the opening cutscene for the game, it’s currently a low res (480×320) vid, I’m going to upload a 1280×720 version later on and its broken into two parts, because apparently 4.5gb is the maximum file size for a single uncompressed video (recorded at 1680×1050). Below the two videos is another two of the opening mission in the game where you blow something up.
Part 1:

Part 2:

Mission part 1:

Mission part 2:

Usually companies use fine print to obscure hidden charges from view, Valve seems to put the real price of the game in the fine print while the big ’sticker price’ is double that,

offer

I remember reading this alongside ‘and I put on my Wizards hat’, it comes from the days when CD Burners were high tech,

* bitchchecker (~java@euirc-a97f9137.dip.t-dialin.net) Quit (Ping timeout#)
* bitchchecker (~java@euirc-61a2169c.dip.t-dialin.net) has joined #stopHipHop
why do you kick me
can’t you discus normally
answer!
we didn’t kick you
you had a ping timeout: * bitchchecker (~java@euirc-a97f9137.dip.t-dialin.net) Quit (Ping timeout#)
what ping man
the timing of my pc is right
i even have dst
you banned me
amit it you son of a bitch
LOL
shit you’re stupid, DST^^
shut your mouth WE HAVE DST!
for two weaks already
when you start your pc there is a message from windows that DST is applied.
You’re a real computer expert
shut up i hack you
ok, i’m quiet, hope you don’t show us how good a hacker you are ^^
tell me your network number man then you’re dead
Eh, it’s 129.0.0.1
or maybe 127.0.0.1
yes exactly that’s it: 127.0.0.1 I’m waiting for you great attack
in five minutes your hard drive is deleted
Now I’m frightened
shut up you’ll be gone
i have a program where i enter your ip and you’re dead
say goodbye
to whom?
to you man
buy buy
I’m shivering thinking about such great Hack0rs like you
* bitchchecker (~java@euirc-61a2169c.dip.t-dialin.net) Quit (Ping timeout#)


What happened is clear: That guy entered his own IP-Adress in his mighty Hack-Tool and crashed his own PC. This way, the attack on my PC was a failure. I was already starting to think that I did not have to worry, but a good hacker never calls it a day. Two minutes later he returned.


* bitchchecker (~java@euirc-b5cd558e.dip.t-dialin.net) has joined #stopHipHop
dude be happy my pc crashed otherwise you’d be gone
lol
bitchchecker: Then try hacking me again… I still have the same IP: 127.0.0.1
you’re so stupid man
say buy buy
ah, [Please control your cussing] off
buy buy elch
* bitchchecker (~java@euirc-b5cd558e.dip.t-dialin.net) Quit (Ping timeout#)


There was a tension in the room… Would he manage, after these two failures, to crash my PC? I waited. Nothing happened. I felt relieve… Six minutes passed by until he prepared the next wave of attack. Being a Hacker, who usually cracks whole data centers, he knew what his problem was now.


* bitchchecker (~java@euirc-9ff3c180.dip.t-dialin.net) has joined #stopHipHop
elch you son of a bitch
bitchchecker how old are you?
What’s up bitchchecker?
you have a frie wal
fire wall
maybe, i don’t know
i’m 26
such behaviour with 26?
how did you find out that I have a firewall?
tststs this is not very nice missy
because your gay fire wall directed my turn off signal back to me
be a man turn that shit off
cool, didn’t know this was possible.
thn my virus destroys your pc man
are you hacking yourselves?
yes bitchchecker is trying to hack me
he bitchchecker if you’re a hacker you have to get around a firewall even i can do that
yes man i hack the elch but the sucker has a fire wall the
what firewall do you have?
like a girl
firewall is normal a normal hacker has to be able to get past it…you girl^^
Bitch give yourself a jackson and chill you’re letting them provoce you and give those little girls new material all the time
turn the firewall off then i send you a virus [Please control your cussing]er
Noo
he bitchchecker why turn it off, you should turn it off
you’re afraid
i don’t wanna hack like this if he hides like a girl behind a fire wall
elch turn off your shit wall!
i wanted to say something about this, do you know the definition of hacking??? if he turns of the firewall that’s an invitation and that has nothing to do with hacking
shut up
lol
my grandma surfs with fire wall
and you suckers think you’re cool and don’t dare going into the internet without a fire wall


He calls me girly and says only his grandma would use a firewall. I know that elder people are much more intelligent then younger, but I couldn’t let that rest. To see whether he really is a good hacker I lie and let everything as it is. I don’t have a firewall at all, only my router.


bitchchecker, a collegue showed me how to turn the firewall off. Now you can try again
bitchhacker can’t hack
> nice play on words ^^
wort man
bitchchecker: I’m still waiting for your attack!
how many times again he is no hacker
man do you want a virus
tell me your ip and it deletes your hard drive
lol ne give it up i’m a hacker myself and i know how hackers behave and i can tell you 100.00% you’re no hacker..^^
127.0.0.1
it’s easy
lolololol you so stupid man you’ll be gone
and are the first files being deleted
mom…
i’ll take a look


In panic I started the Windows Explorer, my heart beating faster. Had I under-estimated him?


don’t need to rescue you can’t son of a bitch
that’s bad
elch you idiout your hard drive g: is deleted
yes, there’s nothing i can do about it
and in 20 seconds f: is gone


Yes, true, G: and F: were gone. Did I ever have them? Doesn’t matter, I did not have time to think, I was scared. bitchchecker was comforting me with a music tip.


tupac rules
elch you son of a bitch your f: is gone and e: too


Drive EConfused Oh my god… All the games are there! And the vacation pictures! I instantly take a look. Everything still there. But the hacker said it was deleted….

Or isn’t it happening on my computer?


and d: is at 45% you idiot lolololol
why doesn’t meta say anything
he’s probably rolling on the floor laughing
> ^^
your d: is gone
go on BITCH


The guy is good: My CD-drive is allegedly deleted! Bitchchecker turned my ancient disk sucker into a burner! But how did he do this? I’ll have to ask him. Some encourage him. He himself is giving advice how to avoid the disaster on my hard drives.


elch man you’re so stupid never give your ip on the internet
i’m already at c: 30 percent


Should I tell him he’s not attacking my computer?


* bitchchecker (~java@euirc-9ff3c180.dip.t-dialin.net) Quit (Ping timeout#)


Too late… It’s 20:22 when we get the last message of our hacker with the alias “bitchchecker”. We see that he has a “Ping timeout”. We haven’t seen him since then… must be the Daylight Saving Time.


The best way to solve the browser wars..

The video was taken from the Silverlight 3 Presentation at Mix 09 and as was promised the code was released.

Thanks to adolfojp from Reddit for the links =)


The C++ Switch statement doesn’t actually work on strings, for example the following code would generate a compiler error (VC++ C2450):

std::string s = "bleh";

switch( s )
{
case "dude":
	(...);
	break;
case "hello":
	(...);
	break;
case: "bleh":
	(...);
	break;
}

Well I say, that’s a bit of a sticky wicket. So why not just resort to an if/then/else stream? Because I wanted to use the switch statement damnit! As always it was the STL to the rescue with the always lovely map class. Unlike vectors and arrays maps let you define how to access different index locations, for example you could use floats rather than integers or even strings (which is what I wanted).

To make it work with strings here’s what I did:

//quick'n'dirty hack to make C++ switch function work more
//like C#'s The following instance of the map class (switcheroo)
//holds the enum 'Vals' and uses strings to identify index locations 

enum Vals{val1,val2,val3,val4};
static map<string, Vals> switcheroo; 

switcheroo[ "string1" ] = val1;
switcheroo[ "string2" ]= val2;
switcheroo[ "string3" ] = val3;
switcheroo[ "string4" ] = val4;

Now to actually use it we simply substitute switcheroo into the switch statement and use the enum values as the cases

switch ( switcheroo[ "string3" ] )
{
case val1:
	(...);
	break;
case val2:
	(...);
	break;
case val3:
	(...);
	break;
case val4:
	(...);
	break;
}

This is obviously a little more hands on than the C# version. Perhaps a class which takes in a string and returns a unique integer value would work better, still, I’ll leave that for another day.

Yes I do realize this trick has been used by many people before me. In hindsight I should have Googled the idea of using the map class to get around the int-only limitation in C++, would have saved me a lot of time.



Having used PhysX for so long I wanted to spread my wings and take a look at the littler physics engines out there. But why stop at one physics engine? Why not a whole bunch of them? Wouldn’t it be awesome to have a set of classes setup which abstractificate the various elements of a physics engine and provide the programmer with the ability to simply choose whatever physics engine they want and run it.

Well I give you the answer to that dream, or at least the not-so-finished header file of said dream,

#include "../d3dutil.h"
#include "../math/emmath.h"
class EmGeom;

class EmPhysicsShell
{
	friend class EmGeom;
public:
	virtual void updatephysics(crfloat timeDelta) = 0;
	virtual void initalizephysics() = 0;

	virtual EmGeom *CreateConvexActor(	const std::vector<D3DXVECTOR3>& vertices,
									const std::vector<short>& indices
									) = 0;

	virtual EmGeom* CreateBox(const Vec3& boxDim, const Vec3& boxPos, bool dynamic = true) = 0;
	virtual EmGeom* CreateSphere(crfloat radius, const Vec3& boxPos, bool dynamic = true) = 0;
};

//An EmGeom is an actor in the physics sim, it can be a primitive type such as a box or sphere
//or a more complex type such as a convex or triangle mesh. In any case it MUST fill out the basic
//aspects of a geom which are the purely virtual functions you see before you
class EmGeom
{
public:
	virtual D3DXVECTOR3 getGlobalPosition() = 0;
	virtual D3DXMATRIX	getGlobalPose() = 0;
	virtual Vec3 getLinearVelocity(){Vec3 v; return v;}

	//must return true if the geometric object is valid, otherwise false. kthxbye
	virtual bool isValid() = 0;
};

Yes I know, I’m missing like a bajillion features here and the function names ‘getGlobalPosition()’ and ‘getGlobalPose()’ sound PhysX-ee.

Well for the time being it will have to do, I plan on learning how to fully develop this by implementing the Newton physics engine.

I wrote the matrix class a while ago, it really simplifies a lot of the generic coding you’d have to otherwise do to convert the matrix classes between PhysX and DirectX.

The basic idea is to inherit from the PhysX matrix/vector classes (NxMat34/NxVec3) and add a few constructors and overloaded operators to make it play nice with its DirectX counterparts.

Header file for EmMatrix:

#pragma once

#ifndef NX_CALL_CONV
#define WIN32
#endif

#define NOMINMAX

#include "NxMat34.h"
#include <d3dx9.h>
#include "NxPhysics.h"
class EmMatrix : public NxMat34
{
public:
	EmMatrix();
	EmMatrix(const D3DXMATRIX& m);
	EmMatrix(const NxMat34& m);

        /*takes in an actor and gets the globalPose*/
	EmMatrix(const NxActor& act);
	D3DXMATRIX D3DMat() const;

	//operator overloads
	D3DXMATRIX operator*(const EmMatrix& m);
	D3DXMATRIX operator*(const D3DXMATRIX& m);

	EmMatrix operator*=(const EmMatrix& m);
	D3DXMATRIX operator*=(const D3DXMATRIX& m);
};

The implementation is fairly straight forward,

#include "EmMatrix.h"

EmMatrix::EmMatrix()
{
	t.zero();
	M.id();
}

EmMatrix::EmMatrix(const D3DXMATRIX& m)
{
	//D3DXMATRIX is a struct with some functions, it has an overloaded typecast
	//operator which returns the matrix in a float array of size 16. PhysX's NxMat34 can be
	//set through an NxReal array of size 16, float typecasts to NxReal and there we go.
	NxMat34::setColumnMajor44((const float*)m);
}

EmMatrix::EmMatrix(const NxActor& act)
{
	//This function is a little wierd, it takes in an NxActor and gets it's matrix (through
	//NxActor::getGlobalPose)
	*this = act.getGlobalPose();

	//One generic unit in DirectX is 0.5 units in PhysX, to compensate for this we multiply the
	//translation vector by 2.
	this->t *= 2;
}

//gets the D3DXMATRIX equivalent of the matrix class
D3DXMATRIX EmMatrix::D3DMat() const
{
	D3DXMATRIX d3dmat;
	//(float*)d3dmat Makes use of an overloaded operator FLOAT* ();
	getColumnMajor44((float*)d3dmat);

	return d3dmat;
}

//Given the above the remaining functions should be self explanatory...

//operator overloads (note it's better to return D3DXMATRIX in case we are dealing with d3d matrices,
//since EmMatrix is derived from NxMat34 we are not presented with any conversion issues when using them
//with physx.
D3DXMATRIX EmMatrix::operator*(const EmMatrix& m)
{
	D3DXMATRIX multiple = this->D3DMat() * m.D3DMat();

	return multiple;
}

D3DXMATRIX EmMatrix::operator*(const D3DXMATRIX& m)
{
	D3DXMATRIX curr = this->D3DMat();
	D3DXMatrixMultiply(&curr, &curr, &m);

	return curr;
}

EmMatrix EmMatrix::operator *=(const EmMatrix& m)
{
	EmMatrix multiple = *this * m;
	*this = multiple;

	return multiple;
}

D3DXMATRIX EmMatrix::operator *=(const D3DXMATRIX& m)
{
	D3DXMATRIX curr = this->D3DMat();
	D3DXMatrixMultiply(&curr, &curr, &m);

	this->setColumnMajor44((float*)curr);

	return curr;
}

Download Code

Just uploaded a DirectX/PhysX library, currently the best feature it has is a function which takes in an ID3DXMesh* pointer and converts it into an NxActor. Be sure to contact and tell me if you find any bugs or flaws in the code or just have suggestions.

Get it here.