As an experiment, I am trying to build a generic 2d graphics library. One of the goals I have in mind is to be able to use different implementation, ranging from SDL to DirectDraw.
The "proper" way I have been taught is to use abstract base classes, so I define one:
:
class IGraphics
{
virtual void ~IGraphics() = 0 {};
virtual void BeginRender() = 0;
virtual void EndRender() = 0;
.
.
.
}
So far so good, but I come to a problem with the BlitBitmap function. Now, SDL, DirectDraw, OpenGL and Allegro uses different data types for blitting images. I cannot do this:
virtual void Blit() = 0;
''cos I need to define the image to blit for the function, but different API uses different types (surfaces for SDL, textures for D3D, and I forgot what Allergo uses)
And here''s another problem - I define a structure to store the video mode settings, the bytes per pixel and the resolution - as different API keeps track of different stuff (SDL keeps track of a few variables compared to DX), I would need to define different structures. This would not work
virtual void GetSetting() const = 0;
So all right, is all this talk about inheritance and proper object modelling and generic interfaces just pie in the sky?
Any suggestions? Many thanks in advance.
"Magic makes the world go round." - Erasmus, Quest For Glory I