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
84 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:

Create the static library project

First, create a "static library" project. We'll call ours GameFramework. (Note that for clarity purposes, we'll only talk about the classes relevant to this article. For following along, feel free to download the accompanying source code).

Let's first sketch out our interface class:

//This class is to provide us with an interface object to our graphics hardware,
//to free us from having specific graphic API calls inside our static library.
class rendererInterface
    //some base level objects can go here

    virtual ~rendererInterface(){};

    //method to create and initialize our hardware
    virtual HRESULT createDevice(HWND, DWORD, DWORD, DWORD, BOOL) = 0;

    //method to destroy it
    virtual void destroyDevice() = 0;

    //method to begin rendering primitives
    virtual HRESULT beginRenderingScene() = 0;

    //method to end rendering primitives
    virtual void endRenderingScene() = 0;

    //method to change the screen clearing color
    virtual void setClearColor(FLOAT, FLOAT, FLOAT, FLOAT) = 0;


//In order to properly follow a kind of OO design, let's create ourselves
//a "factory" object, which is SOLELY responsible for the creation and
//destruction of our rendererInterface object. Note that we made the member
//functions of the rendererInterface object pure virtual, in order to prevent
//the programmer from instantiating this class DIRECTLY.
class rendererFactory
      rendererInterface    *m_pRenderer;
      HINSTANCE           m_hInst;
      HMODULE             m_hDLL;

      rendererFactory(HINSTANCE hInst){ m_hInst = hInst;};
      ~rendererFactory(){ destroyInterface();};

      HRESULT initInterface(TCHAR *szType);
      rendererInterface* getInterface(){ return m_pRenderer; };
      void destroyInterface();

Okay we'll have to do some explainin'...first off, we're just creating a rendererInterface object which is responsible for interfacing with our graphics API. We're setting up an environment within our framework, so that we can abstract our graphics API calls. The rendererFactory object's responsibility is to properly create and destroy our rendererInterface object.

What are DLL's??

Again, if you're unsure of what DLL's are, then please consider re-reading GameDev.net's other DLL article. Back already? Okay then let's keep going. Within our GameFramework workspace, create a win32 DLL project with NO files, as we'll add them ourselves. For this sample, we'll call it GameD3DRenderer. Again, follow along with the source code, but for the article's sake, we'll just jot down the more pertinent information:

;The following functions are exported from this DLL, in order to
;properly create and destroy our renderer object without worrying about
;name mangling.
LIBRARY    "GameD3DRenderer.dll"

//now in our .cpp file
HRESULT createRendererInterface(rendererInterface **pInterface)
    //convert our interface pointer to a D3DRenderer object
    //note: that in our GameOGLRenderer project, we just
    //need to replace the following class with OGLRenderer
    *pInterface = new D3DRenderer;
    return S_OK;

  return E_FAIL;


// Release our Handle to the class
HRESULT destroyRendererInterface(rendererInterface **pInterface)
    return E_FAIL;
  delete *pInterface;
  *pInterface = 0;
  return S_OK;

The two functions above should be clear enough. We're taking as input the rendererInterface object, which we use to properly create and destroy an instance of our D3DRenderer class, which is the Direct3D implementation of our rendererInterface.


  Static .lib and the DLL

  Source code
  Printable version
  Discuss this article

The Series
  Part I
  Part II
  Part III
  Part IV