I'm making a modular engine for all of my games. I'll show you the structure:
CEngine
/ | / | / | / | CAudio CWindow CInput
|
CGraphics
/ COpenGL CDirect3D
Come to think of it, it looks like a stick figure. But what I'm having trouble with is the CGraphics component. I don't know what to do with it. As I see it, I have to options:
- Option #1: Put a function in CGraphics to select the API to use. From then on, for all of the functions, use a pointer pointing to the selected API for all of the calls.
class CGraphics
{
void SelectAPI(int API)
{
if(API==0) { m_pRenderer = &CDirect3D }
if(API==1) { m_pRenderer = &COpenGL }
}
int Create(int blah)
{
m_pRenderer->Create(blah);
}
- Option #2: Make CGraphics an abstract class, so the user would make a pointer of CGraphics and simply point it to either API and call all of the functions from there.
CGraphics *pGraphics = &CDirect3D
pGraphics->Create(blah);
I am leaning toward Option #2, but what do you think? Thanks for your consideration!
[edited by - elendil67 on December 1, 2002 2:45:37 PM]
When you go homeTell them of us, and say:For your tomorrow,We gave our today.