O-Town Graphics

Wednesday, May 03, 2006

Annoying idioms

I'm really tired of the idiom I see in Win32 and sometimes now OpenGL where you try something, and if it works, then its supported, otherwise, your out of luck. Why can't we just query what a device features?

This really complicates code. For example, to enable full-screen anti-aliasing, you have to do things like create a dummy window and then try to set a pixel format context.


Look at the OpenGL extension:


wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)



This requires an HDC, but you might not know ahead of time if and what modes it supports! So wow, let's try it on a dummy window, and if it works maybe try a few more, just to see what options we have. 8X isn't supported? Hey, let's try 4X? Oh, no, can't do that? Okay, 2X. Shaheesh.


Why not something like this, huh?

int count = wglGetDeviceCapsCount(GL_FSAA_MODES);

std::vector<int> fsaaModes;
fsaaModes.resize(count);
wglGetDeviceCapsiv(GL_FSAA_MODES, &fsaaModes[0]);


Is that so hard?? There are also similar evil functions in Win32, where for example if you need to see how many bytes to allocate to a Unicode to string conversion, you use the exact same function for conversion but pass in a different value. Yes I'm talking about the oh so ugly WideCharToMultiByte function.


Do we really need a super function to try to do everything? I'm just tired of round-about ways of trying to get information.

1 Comments:

  • Yes, I also think that testing for every single feature is a nuisance. But OpenGL's main objective wasn't to make your programming easier but rather to provide functions to render your scene.

    I do suppose that it should have been part of the design though. Now if we really wanted to have that implemented, then somebody would have to make a wrapper that first tests every single feature from the current library then passes the feature list back to your program.

    All of this bad design just turns up with more bad design from end programmers. As if we didn't have enough bad code already. There should be some organization to organize interfaces. We want to keep programming simple!

    By Anonymous hid, at 9:39 PM  

Post a Comment

<< Home