The first thing you will need to do is open the D3DGraphics.h Header file.
Below the other functions under "public:" add the following line:
Code: Select all
void DrawBackground(int width, int height, int r, int g, int b);
Code: Select all
#pragma once
#include <d3d9.h>
class D3DGraphics
{
public:
D3DGraphics( HWND hWnd );
~D3DGraphics();
void PutPixel( int x,int y,int r,int g,int b );
void DrawLine( int x1,int y1,int x2,int y2,int r,int g,int b );
void DrawRectangle(int x, int y, int x2, int y2, int borderRed, int borderGreen, int borderBlue, int r, int g, int b);
void DrawCircle( int cx,int cy,int radius,int r,int g,int b );
void DrawDisc( int cx,int cy,int r,int rd,int g,int b );
void DrawBackground(int width, int height, int r, int g, int b);
void BeginFrame();
void EndFrame();
private:
IDirect3D9* pDirect3D;
IDirect3DDevice9* pDevice;
IDirect3DSurface9* pBackBuffer;
D3DLOCKED_RECT backRect;
};
Now, open your D3DGraphics.cpp Source file. At the end of the file, add the following:
Code: Select all
void D3DGraphics::DrawBackground(int width, int height, int r, int g, int b)
{
for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
{
PutPixel(i, j, r, g, b);
}
}
}
To demonstrate a red background, open the Game.cpp Source file. Inside the ComposeFrame function where Chili's video tutorials have you typing the code, you can call the DrawBackground function. Since a background is usually the very bottom layer, DrawBackground should be the very first function you call before any additional drawing functions. If you were to call the DrawLine function first and then DrawBackground, the background would be drawn afterwards and thus, cover up your line.
To call the draw background function with red background:
Code: Select all
gfx.DrawBackground(800, 600, 255, 0, 0);