Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
109 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Testing our changes

Well now that we've covered our approach to switching the graphics pipeline state, as well as playing around with our buffer comparison routines, let's do some flexin' and use some of this knowledge in our code!

We're not going to do anything that radical today. I'm simply going to demonstrate some of what we've covered in today's tutorial. Obviously it's pretty bare bones, but the power is there to handle more advanced tasks for your scene.

Step One

In our createProgram method we just need to add/update the following code:

  //load up a TGA image
  hr = pInterface->getTextureInterface()->
    addTexture("data\\textures\\title.tga", TITLE);
  if(FAILED(hr)){
    return E_FAIL;
  }

  pInterface->setState( ZBUFFER, DISABLE );//disable our depth buffer
  pInterface->setState( LIGHTING, DISABLE );//disable our lighting

  //enable our blending calculations
  pInterface->setState( ALPHABLENDING, ENABLE );
  //set our source parameter to the alpha information of the source pixel
  pInterface->setState( SRC_BLEND, SRC_ALPHA );
  //set our destination parameter to 1-alpha information of the source pixel
  pInterface->setState( DEST_BLEND, INV_SRC_ALPHA );

That's pretty much all we need to do! When we run our example along with the updated interface DLL's, we'll see the following (with our OpenGL DLL):

References

  1. TGA Loader code from theTutor at GameTutorials.com.
  2. OpenGL Game Programming by Hawkins/Astle. Page 217-219

Conclusion

Well there you have it. We did a lot of work today on our engine, and learned a bit about manipulating the state information of the graphics pipeline, as well as being able to update/modify the existing underlying renderer interface codebase without having to touch and/or recompile our application.

Again, note that this approach to our state machine within the graphics pipeline is merely one way to do things.

Another possible approach, is to use the use of bit fields to represent our state(s), which was fleshed out somewhat by gamedev.net reviewer RusselB.

#define ES_LIGHTING    1  // or 0x0001 
#define ES_ZBUFFER     2  // or 0x0002
#define ES_ALPHABLENDING  4  // or 0x0004
#define ES_SRC_BLEND    8  // or 0x0008
#define ES_DEST_BLEND    16  // or 0x0010
#define ES_ALPHATEST    32  // or 0x0020

Which can then be used in combination with each other to allow the engine to accept method calls such as:

setState( ES_LIGHTING | ES_ZBUFFER );     //set our state
disableState( ES_LIGHTING | ES_ZBUFFER ); //disable our state

Any comments, questions or concerns can be sent to Wazoo AT WazooEnterprises death-to-spam DOT com.


Contents
  TGA / BMP Image Loading
  Testing our changes

  Source code
  Printable version
  Discuss this article

The Series