Advertisement

dll's, classes, me gettin pissed off

Started by February 15, 2000 06:44 PM
3 comments, last by HellStorm 24 years, 7 months ago
Here is my problem, I have two seperate dll's that my main program could choose from at RUNTIME to use for rendering. In one dll I have a class named Directx_Rend while in the other dll I have a class named Opengl_Rend. Now Thats all fine and dandy. Now in the main program I need to have a global class named oddly enough, current_renderer. Now in the main program in WinMain I load the dll I need and then have the class imported from the desired dll. Now I need to do somethin like: //notice the dx_rend is a pointer to class Directx_Rend current_renderer = dx_rend; Now this would be fine except that I do not know what type of class current_render needs to be.(ie, Directx_Rend or Opengl_Rend). So basically I am saying that current_renderer needs to be globally defined so other files can access its functions in a manner like current_renderer->DrawTriangle(Vertex a, .............); But in order to assign dx_rend to current_renderer I need to declare current_render as type Directx_Rend but it wont work if I needed the class Opengl_Rend instead(and vice-versa). Hope yall understand that explanation(I am tired). Thnx HellStorm Edited by - HellStorm on 2/15/00 6:47:42 PM
Sounds like a job for Polymorphism...
Advertisement
What I''ve seen done (and what I''d do in that situation) is create a rendering class that Directx_Rend and Opengl_Rend inherit from. They you can do

current_render->DrawTri (....)

and not have to worry whether it''s a DirectX or an OpenGL implementation.
To add on what Kyle said.

You also need to export a function from each dll that creates the Renderer and binds it to the given pointer to the base Renderer class.

I use the following code for the project I''m working on.

HRESULT __stdcall GetRendererAPI(I_Renderer ** pRender)
{
if(!*pRender)
{
* pRender = new CRenExp;
return S_OK;
}
return E_FAIL;
}

HRESULT __stdcall FreeRenderer(I_Renderer * pRender)
{
if(!pRender)
return E_FAIL;
delete pRender;
pRender = 0;
return S_OK;
}

These two are the only functions exported by the dll.
And I_Renderer is the base Renderer Interface.
Right on Kyle, Skid. Just one slight comment -

I think FreeRenderer needs an extra *, just like GetRenderer... otherwise it doesn''t matter if you set it to NULL after you delete it (a good practice).

Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com
Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!

This topic is closed to new replies.

Advertisement