Time for some OpenGL bashing

| No Comments

Yes, I know, I'm a bit late to the game, but today (after 8 years of using OpenGL exclusively) I've just gotten the small rendering engine I'm working on to use DirectX 9. 

Why DX9 and not 10 (or 11)? Because I need it to run on computers with WinXP (could Microsoft have been more stupid, limiting DirectX like that?)

Anyway, the engine was working on MacOS and Linux, but I needed to be sure to support DX as well (OpenGL drivers for Windows are known to be buggy as hell and fairly incomplete in some cases). So here we are, coding using a propietary Microsoft library. Yes, I know I'm unclean and un-free, but such is life (and for what it's worth, I'm still using bash, g++ and vim, even on Windows ;)

The thing is, after using DirectX for 2 days, I wish OpenGL was more like it in some ways. 

Small example. First, OpenGL code to render from a vertex buffer object:

glBindBuffer(GL_ARRAY_BUFFER, mdataBuffer);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); 
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexData), (char*)NULL+sizeof(uint8t)*3);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData), 0);
glDrawArrays(GL_TRIANGLES, startVertex, endVertex-startVertex);

And now, equivalent DirectX9 code:

md3dDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
md3dDevice->SetStreamSource( 0, mdataBuffer, 0, sizeof(VertexData) );
md3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, startVertex, (endVertex-startVertex)/3);

Those 2 blocks of code do exactly the same thing: take information from a buffer about a bunch of vertices (vertex position and color), and use that info to render some triangles. Just that.
 
But see the difference in the code? Now choose the cleaner, saner API. I don't think many will choose OpenGL. And that's a shame.

Sometimes I hope for a clean API redesign for OpenGL, and do away with all that crap. ...sigh...

I highly recomend this session (page 194) (btw, thanks to shash for that link) where an NVidia engineer talks about problems the OpenGL API (and DirectX's too) causes for application portability. 

Leave a comment