Before I start please know I am a beginner so I may be asking a silly question or getting terminology wrong.
I have a simple program which initializes a win32 window, and then initializes directX 11 in that window.
The directX initialization is held in a class Graphics
The win32 window is held in a class MainWindow. My program flow goes as follows:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
window = new MainWindow;
window->initialize(hwnd, hInstance, nCmdShow);
the MainWindow::initialize function does all of that registering a win32 class and creating the window. At the bottom of this function is where I want to initialize directX within the window. This is where I get confused. As far as I am aware there seems to be three ways to do this.
METHOD 1. Use inheritance.
class MainWindow : public Graphics
{
private:
HWND hwnd;
HINSTANCE hInstance;
HRESULT hr;
int nCmdShow;
public:
MainWindow();
~MainWindow();
void initialize(HWND hwnd, HINSTANCE hInstance, int nCmdShow);
static LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
};
then after the ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); of my MainWindow::initialize() function, I can write.
Graphics graphics;
graphics.initialize(hwnd, 640, 480, false);
graphics.showBackbuffer();
METHOD 2. Composition with an object.
Removing the inheritance line : public Graphics, means I need to put a Graphics object in my MainWindow member variable section e.g.
class MainWindow
{
private:
HWND hwnd;
HINSTANCE hInstance;
Graphics graphics; <------------- ADDED THIS
HRESULT hr;
int nCmdShow;
I can now leave the same code as before, but remove the Graphics graphics; object declaration since it has already been done.
METHOD 3. Composition with a pointer to a graphics object.
The third method is to declare a pointer to a graphics object (which will be created later), in class MainWindow e.g.
class MainWindow
{
private:
HWND hwnd;
HINSTANCE hInstance;
Graphics *graphics; <------------- ADDED THIS
HRESULT hr;
int nCmdShow;
This time, to initialize my directX window I write
graphics = new Graphics();
graphics->initialize(hwnd, 640, 480, false);
graphics->showBackbuffer();
At this stage I am very confused. They all essentially get me where I want to be, but there would be a lot of behind the scenes stuff going on of which I have no idea.
So could someone clarify which method is best to use in this example?
Thanks