Million and one errors : HELP!!!!!!!!!!!!!!

Started by
4 comments, last by PuterPaul 20 years, 3 months ago
Right i''m trying to build my simple project, and yet I''m getting far too many errors and i''m not sure why. I accept there may be the odd typo here and there but not 250 of them. I think it may have something to do with my includes of files. Here are the files i''ve got Main.cpp - Has the winmain function and creates a new CGame instance and CLogManager. Game.cpp - Creates the DxWindow and InputManager LogManager.cpp - Logs the progress of stuff DxWindow.cpp - Initialises D3D and stuff InputManager.cpp - Initialises DirectInput and stuff Also i''ve made sure I''ve included all the necessary lib files and directories. main.cpp

#include "Game.h"
#include "LogManager.h"
#include "commondefs.h"

CGame* g_pGame = NULL;
CLogManager* m_logManager = new CLogManager();

void CleanUp()
{
	SafeDelete(g_pGame);
}

//The windows message handler

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}

//Application entry point

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
    //Register the window class

    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, 
                     GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                     "DX Project 12", NULL};
	
	//Set the mouse pointer to an arrow

    wc.hCursor = LoadCursor(NULL, IDC_ARROW);	
	ShowCursor(FALSE);

	RegisterClassEx(&wc);

    //Create the application''s window

    HWND hWnd = CreateWindow("DX Project 12", "www.andypike.com: Tutorial 12", 
                              WS_OVERLAPPEDWINDOW, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
                              NULL, NULL, wc.hInstance, NULL);

	//Show our window

    ShowWindow(hWnd, SW_SHOWDEFAULT);
    UpdateWindow(hWnd);
	
	g_pGame = new CGame(m_logManager);
    m_logManager->StartLogging();

	//Initialize Direct3D

	if(g_pGame->Initialise(hWnd, hInst, 800, 600))
    { 
        //Start game running: Enter the game loop

		g_pGame->GameLoop();
    }
    
    CleanUp();

    UnregisterClass("DX Project 12", wc.hInstance);
    
    return 0;
}
Game.h

#ifndef GAME_H
#define GAME_H

#include <d3dx9.h>
#include <stdarg.h>
#include "LogManager.h"
#include "DxWindow.h"
#include <windows.h>

class CGame
{
  public:
    bool Initialise(HWND hWnd,HINSTANCE hInst,UINT nWidth,UINT nHeight);
    void GameLoop();

    CGame(CLogManager* logManager);
    virtual ~CGame();    
  private:
    CLogManager* m_LogManager;
	CDxWindow* m_DxWindow;
	CInputManager* m_InputManager;

    void CleanUpGame();
    void RenderText();
    void Render2D();
    void Render3D();  
    bool InitialiseGame();
    void Render();   

    DWORD m_dwFrames;
    DWORD m_dwStartTime;
    DWORD m_dwEndTime;
    DWORD m_dwTotalPolygons;
    bool m_fQuit;   
}

#endif
Game.cpp

// Game.cpp: implementation of the CGame class.

//

//////////////////////////////////////////////////////////////////////


#include "Game.h"
#include "commondefs.h"

//////////////////////////////////////////////////////////////////////

// Construction/Destruction

//////////////////////////////////////////////////////////////////////


CGame::CGame(CLogManager *logManager)
{
	m_dwFrames = 0;
	m_dwStartTime = 0;
	m_dwEndTime = 0;
	m_dwTotalPolygons = 0;
	m_fQuit = false;

	m_LogManager = logManager;
	m_DxWindow = new CDxWindow(m_LogManager);
	m_InputManager = new CInputManager(m_LogManager);
	
	m_pFont = NULL;	
}

CGame::~CGame()
{
	//Game finished, so destroy game objects

	m_LogManager->LogInfo("<br>Finish Game:");

	//Clean up our objects and interfaces

	CleanUpGame();	

	//Game finished, so save statistics to log

	DWORD dwDuration = (m_dwEndTime - m_dwStartTime) / 1000;
	
	if((dwDuration != 0)&&(m_dwFrames != 0))
	{
		//Log stats

		m_LogManager->LogInfo("<br>Statistics:");
		m_LogManager->LogInfo("<li>Start Time (ms): %d", m_dwStartTime);
		m_LogManager->LogInfo("<li>End Time (ms): %d", m_dwEndTime);
		m_LogManager->LogInfo("<li>Duration (s): %d", dwDuration);
		m_LogManager->LogInfo("<li>Total Frame Count: %d", m_dwFrames);
		m_LogManager->LogInfo("<li>Total Polygons: %d", m_dwTotalPolygons);
		m_LogManager->LogInfo("<li>Average Polygons per Frame: %d", (m_dwTotalPolygons / m_dwFrames));
	}
	else
	{
		m_LogManager->LogInfo("<br>No statistics to report");
	}

	m_LogManager->StopLogging();
}

void CGame::CleanUpGame()
{
	
}

bool CGame::Initialise(HWND hWnd, HINSTANCE hInst, UINT nWidth, UINT nHeight)
{
	//Initialise Direct3D

	if(!m_DxWindow->InitialiseDirect3D(hWnd, nWidth, nHeight))
	{
		return false;
	}
	
	//Initialise DirectInput

	if(!m_InputManager->InitialiseDirectInput(hWnd, hInst))
	{
		return false;
	}
	
	//Initialise Lighting

	if(!m_DxWindow->InitialiseLights()) 
	{
		return false;
	}

	//Initialise Game Objects

	if(!InitialiseGame())
	{
		return false;
	}

	return true;
}

bool CGame::InitialiseGame()
{
	m_LogManager->LogInfo("<br>Initialise Game:");

	//Setup games objects here

	

	//Setup fonts here

	m_pFont = new CFont(m_DxWindow->GetDevice(), "Verdana", 12, false, false, false);

	//Setup panels for 2D



	return true;
}

void CGame::GameLoop()
{
    //Enter the game loop

    MSG msg; 
    BOOL fMessage;

    PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);

	//Game started, so record time

	m_dwStartTime = timeGetTime();

    while((msg.message != WM_QUIT) && (!m_fQuit))
    {
        fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);

        if(fMessage)
        {
            //Process message

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            //No message to process, so render the current scene

            Render();
        }
    }

	//Game finished, so record time

	m_dwEndTime = timeGetTime();
}

void CGame::Render()
{
	if(m_DxWindow->GetDevice() == NULL)
    {
        return;
    }

	//Process keyboard and mouse user input

	m_InputManager->ProcessKeyboard();
	m_InputManager->ProcessMouse();

	if(!m_fQuit)
	{
		//Clear the back buffer and depth buffer

		m_DxWindow->GetDevice()->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    
		//Begin the scene

		m_DxWindow->GetDevice()->BeginScene();
    
		
		//Setup the camera ready for 3D elements

		m_DxWindow->Setup3DCamera();
		
		//Now that the 3D camera is setup, render the 3D objects

		Render3D();
		
		//Now render the text

		RenderText();

		//End the scene

		m_DxWindow->GetDevice()->EndScene();
    
		//Filp the back and front buffers so that whatever has been rendered on the back buffer

		//will now be visible on screen (front buffer).

		m_DxWindow->GetDevice()->Present(NULL, NULL, NULL, NULL);

		//Count Frames

		m_dwFrames++;
	}
}

void CGame::Render2D()
{
  //Render our 2D objects	

}

void CGame::Render3D()
{	
  //Render our 3D objects	

}

void CGame::RenderText()
{
	//Draw some text at the top of the screen showing stats

	char buffer[255];
	DWORD dwDuration = (timeGetTime() - m_dwStartTime) / 1000;
	
	if(dwDuration > 0)
	{
		sprintf(buffer, "Duration: %d seconds. Frames: %d. FPS: %d. ", dwDuration, m_dwFrames, (m_dwFrames / dwDuration));
	}
	else
	{
		sprintf(buffer, "Calculating...");
	}
		
	m_pFont->DrawText(buffer, 0, 0, D3DCOLOR_XRGB(255, 255, 255));
}
LogManager.h

#ifndef LOGMANAGER_H
#define LOGMANAGER_H

#include <stdio.h>
#include <stdarg.h>
#include <tlhelp32.h>
#include <windows.h>

class CLogManager
{
  public:
    static void StartLogging();
    static void StopLogging();
    static void LogError(char *lpszText, ...);
    static void LogInfo(char *lpszText, ...);
    static void LogWarning(char *lpszText, ...);

    CLogManager();
    virtual ~CLogManager();
  private:
    static bool m_fEnableLogging;
}

#endif
LogManager.cpp

// LogManager.cpp: implementation of the CLogManager class.

//

//////////////////////////////////////////////////////////////////////


#include "LogManager.h"

void CLogManager::CLogManager()
{
  m_fEnableLogging = false;
}

virtual CLogManager::~CLogManager(){}

void CLogManager::LogError(char *lpszText, ...)
{
	if(m_fEnableLogging)
	{
		va_list argList;
		FILE *pFile = NULL;

		//Initialize variable argument list

		va_start(argList, lpszText);

		//Open the log file for appending

		pFile = fopen("Log.htm", "a+");

		if(pFile != NULL)
		{
			//Write the error to the log file

			fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#FF0000\"><b>");
			vfprintf(pFile, lpszText, argList);
			fprintf(pFile, "</b></font><br>\n");

			//Close the file

			fclose(pFile);
		}

		va_end(argList);
	}
}

void CLogManager::LogInfo(char *lpszText, ...)
{
	if(m_fEnableLogging)
	{
		va_list argList;
		FILE *pFile = NULL;

		//Initialize variable argument list

		va_start(argList, lpszText);

		//Open the log file for appending

		pFile = fopen("Log.htm", "a+");

		if(pFile != NULL)
		{
			//Write the error to the log file

			fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#000000\">");
			vfprintf(pFile, lpszText, argList);
			fprintf(pFile, "</font><br>\n");

			//Close the file

			fclose(pFile);
		}

		va_end(argList);
	}
}

void CLogManager::LogWarning(char *lpszText, ...)
{
	if(m_fEnableLogging)
	{
		va_list argList;
		FILE *pFile = NULL;

		//Initialize variable argument list

		va_start(argList, lpszText);

		//Open the log file for appending

		pFile = fopen("Log.htm", "a+");

		if(pFile != NULL)
		{
			//Write the error to the log file

			fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#E7651A\"><b>");
			vfprintf(pFile, lpszText, argList);
			fprintf(pFile, "</b></font><br>\n");

			//Close the file

			fclose(pFile);
		}

		va_end(argList);
	}
}

void CLogManager::StartLogging()
{
	FILE* pFile = NULL;

	//OPen the file and clear the contents

	pFile = fopen("Log.htm", "wb");

	if(pFile != NULL)
	{
		//Write start html to log

		fprintf(pFile, "<html><head><title>Log File</title></head><body>\n");
		fprintf(pFile, "<font face=\"Arial\" size=\"4\" color=\"#000000\"><b><u>Log File</u></b></font><br>\n");

		//Close the file

		fclose(pFile);

		m_fEnableLogging = true;
	}
}

void CLogManager::StopLogging()
{
	if(m_fEnableLogging)
	{
		FILE *pFile = NULL;

		//Open the log file for appending

		pFile = fopen("Log.htm", "a+");
		
		if(pFile != NULL)
		{
			//Write end html to log

			fprintf(pFile, "</body></html>");

			//Close the file

			fclose(pFile);
		}

		m_fEnableLogging = false;
	}
}
DxWindow.h

#ifndef DXWINDOW_H
#define DXWINDOW_H

#include <d3dx9.h>
#include "LogManager.h"

class CDxWindow
{
public:
    LPDIRECT3DDDEVICE9 GetDevice();

    int GetScreenWidth();
	void SetScreenWidth(int width);

	int GetScreenHeight();
	void SetScreenHeight();

    char* GetWindowName();
    void SetWindowName(char* name);
	
	bool InitialiseLights();   
	void Setup3DCamera();
    void Setup2DCamera();
    bool InitialiseDirect3D(HWND hWnd, UINT nWidth, UINT nHeight);

	CDxWindow(CLogManager* logManager);
	virtual ~CDxWindow();
private:	
	D3DFORMAT CheckDisplayMode(UINT nWidth, UINT nHeight, UINT nDepth);
	void CleanUpDirect3D();

    char* m_WindowName;
    int m_nScreenWidth;
    int m_nScreenHeight;

    CLogManager* m_LogManager;

    LPDIRECT3D9 m_pD3D;		
    LPDIRECT3DDEVICE9 m_pD3DDEVICE;
}

#endif
DxWindow.cpp

// DxWindow.cpp: implementation of the CDxWindow class.

//

//////////////////////////////////////////////////////////////////////


#include "DxWindow.h"
#include "commondefs.h"

void CDxWindow::CDxWindow(CLogManager *logManager)
{
	m_pD3D = NULL;
	m_pD3DDEVICEE = NULL;

	m_LogManager = logManager;	
}

virtual CDxWindow::~CDxWindow()
{
	CleanUpDirect3D();	
}

char* CDxWindow::GetWindowName()
{
	return m_WindowName;
}

void CDxWindow::SetWindowName(char* name)
{
	m_WindowName = name;
}

void CDxWindow::CleanUpDirect3D()
{
	SafeRelease(m_pD3DDevice);
	SafeRelease(m_pD3D);
}

D3DFORMAT CDxWindow::CheckDisplayMode(UINT nWidth, UINT nHeight, UINT nDepth)
{
	UINT x;
	D3DDISPLAYMODE d3ddm;

	for(x = 0; x < m_pD3D->GetAdapterModeCount(0); x++)
	{
		m_pD3D->EnumAdapterModes(0, x, &d3ddm);
		if(d3ddm.Width == nWidth)
		{
			if(d3ddm.Height == nHeight)
			{
				if((d3ddm.Format == D3DFMT_R5G6B5) || (d3ddm.Format == D3DFMT_X1R5G5B5) || (d3ddm.Format == D3DFMT_X4R4G4B4))
				{
					if(nDepth == 16)
					{
						return d3ddm.Format;
					}
				}
				else if((d3ddm.Format == D3DFMT_R8G8B8) || (d3ddm.Format == D3DFMT_X8R8G8B8))
				{
					if(nDepth == 32)
					{
						return d3ddm.Format;
					}
				}
			}
		}
	}

	return D3DFMT_UNKNOWN;
}

bool CDxWindow::InitialiseDirect3D(HWND hWnd, UINT nWidth, UINT nHeight)
{
	m_LogManager->LogInfo("<br>Initialise Direct3D:");

    //First of all, create the main D3D object. If it is created successfully we 

    //should get a pointer to an IDirect3D8 interface.

    m_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
    if(m_pD3D == NULL)
    {
		m_LogManager->LogError("<li>Unable to create DirectX8 interface.");
        return false;
    }

    //Get the current display mode

    D3DDISPLAYMODE d3ddm;

	d3ddm.Format = CheckDisplayMode(nWidth, nHeight, 32);
	if(d3ddm.Format != D3DFMT_UNKNOWN)
	{
		//Width x Height x 32bit has been selected

		d3ddm.Width = nWidth;
		d3ddm.Height = nHeight;

		m_LogManager->LogInfo("<li>%d x %d x 32bit back buffer format selected. Format = %d.", nWidth, nHeight, d3ddm.Format);
	}
	else
	{
		d3ddm.Format = CheckDisplayMode(nWidth, nHeight, 16);
		if(d3ddm.Format != D3DFMT_UNKNOWN)
		{
            //Width x Height x 16bit has been selected

			d3ddm.Width = nWidth;
			d3ddm.Height = nHeight;

			m_LogManager->LogInfo("<li>%d x %d x 16bit back buffer format selected. Format = %d.", nWidth, nHeight, d3ddm.Format);
		}
        else
		{
			m_LogManager->LogError("<li>Unable to select back buffer format for %d x %d.", nWidth, nHeight);
            return false;
        }
	}

	
    //Create a structure to hold the settings for our device

    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));

	d3dpp.Windowed = FALSE;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferFormat = d3ddm.Format;
    d3dpp.BackBufferWidth = d3ddm.Width;
    d3dpp.BackBufferHeight = d3ddm.Height;
    d3dpp.hDeviceWindow = hWnd;
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;

	m_nScreenWidth = d3ddm.Width;
	m_nScreenHeight = d3ddm.Height;

	//Select the best depth buffer, select 32, 24 or 16 bit

    if(m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) == D3D_OK)
	{
        d3dpp.AutoDepthStencilFormat = D3DFMT_D32;
        d3dpp.EnableAutoDepthStencil = TRUE;

		m_LogManager->LogInfo("<li>32bit depth buffer selected");
    }
    else if(m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) == D3D_OK)
    {
		d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;
        d3dpp.EnableAutoDepthStencil = TRUE;

		m_LogManager->LogInfo("<li>24bit depth buffer selected");
	}
    else if(m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) == D3D_OK)
    {
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
        d3dpp.EnableAutoDepthStencil = TRUE;

		m_LogManager->LogInfo("<li>16bit depth buffer selected");
	}
    else
	{
        d3dpp.EnableAutoDepthStencil = FALSE;
		m_LogManager->LogError("<li>Unable to select depth buffer.");
	}


    //Create a Direct3D device.

    if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, 
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pD3DDevice)))
    {
		m_LogManager->LogError("<li>Unable to create device.");
        return false;
    }
    
	//Turn on back face culling. This is becuase we want to hide the back of our polygons

	if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW)))
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_CULLMODE Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_CULLMODE OK");
	}


	//Turn on Depth Buffering

	if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE)))
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_ZENABLE Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_ZENABLE OK");
	}


	//Set fill state. Possible values: D3DFILL_POINT, D3DFILL_WIREFRAME, D3DFILL_SOLID

	if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID)))
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_FILLMODE Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_FILLMODE OK");
	}

	//Set the D3DRS_NORMALIZENORMALS render state to fix the problem when scaling the objects get darker

	if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE)))
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_NORMALIZENORMALS Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_NORMALIZENORMALS OK");
	}


	//Enable alpha blending so we can use transparent textures

	if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,  TRUE)))
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_ALPHABLENDENABLE Failed");
		return false;
	}
	else
	{
		//Set how the texture should be blended (use alpha)

		m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_ALPHABLENDENABLE OK");
	}
	

    return true;
}

bool CDxWindow::InitialiseLights()
{
	m_LogManager->LogInfo("<br>Initialise Lights:");

	D3DLIGHT8 d3dLight;

	//Initialize the light structure.

	ZeroMemory(&d3dLight, sizeof(D3DLIGHT8));

	d3dLight.Type = D3DLIGHT_POINT;
	
	d3dLight.Position.x = -30.0f;
	d3dLight.Position.y = 0.0f;
	d3dLight.Position.z = -15.0f;

	d3dLight.Attenuation0 = 1.0f; 
	d3dLight.Attenuation1 = 0.0f; 
	d3dLight.Attenuation2 = 0.0f; 
	d3dLight.Range = 1000.0f;	

	d3dLight.Diffuse.r = 1.0f;
	d3dLight.Diffuse.g = 1.0f;
	d3dLight.Diffuse.b = 1.0f;
	
	d3dLight.Ambient.r = 0.0f;
	d3dLight.Ambient.g = 0.0f;
	d3dLight.Ambient.b = 0.0f;
	
	d3dLight.Specular.r = 0.0f;
	d3dLight.Specular.g	= 0.0f;
	d3dLight.Specular.b	= 0.0f;

	//Assign the point light to our device in poisition (index) 0

	if(FAILED(m_pD3DDevice->SetLight(0, &d3dLight)))
	{
		m_LogManager->LogError("<li>SetLight Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetLight OK");
	}

	//Enable our point light in position (index) 0

	if(FAILED(m_pD3DDevice->LightEnable(0, TRUE)))
	{
		m_LogManager->LogError("<li>LightEnable Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>LightEnable OK");
	}

	//Turn on lighting

    if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE)))
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_LIGHTING Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_LIGHTING OK");
	}

	//Set ambient light level

	if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100))))	
	{
		m_LogManager->LogError("<li>SetRenderState: D3DRS_AMBIENT Failed");
		return false;
	}
	else
	{
		m_LogManager->LogInfo("<li>SetRenderState: D3DRS_AMBIENT OK");
	}

	return true;
}

void CDxWindow::Setup2DCamera()
{
	D3DXMATRIX matOrtho;	
	D3DXMATRIX matIdentity;
	
	//Setup the orthogonal projection matrix and the default world/view matrix

	D3DXMatrixOrthoLH(&matOrtho, (float)m_nScreenWidth, (float)m_nScreenHeight, 0.0f, 1.0f);
	D3DXMatrixIdentity(&matIdentity);

	m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);
	m_pD3DDevice->SetTransform(D3DTS_WORLD, &matIdentity);
	m_pD3DDevice->SetTransform(D3DTS_VIEW, &matIdentity);

	//Make sure that the z-buffer and lighting are disabled

	m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
	m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
}

void CDxWindow::Setup3DCamera()
{
   //Here we will setup the camera.

   //The camera has three settings: "Camera Position", "Look at Position" and "Up Direction"

   //We have set the following:

   //Camera Position:	(0, 15, -50)

   //Look at Position: (0, 0, 0)

   //Up direction:		Y-Axis.

   D3DXMATRIX matView;
   D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f, 15.0f, -50.0f),	//Camera Position

                                &D3DXVECTOR3(0.0f, 0.0f, 0.0f),		//Look At Position

                               &D3DXVECTOR3(0.0f, 1.0f, 0.0f));		//Up Direction

   m_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);

   //Here we specify the field of view, aspect ration and near and far clipping planes.

   D3DXMATRIX matProj;
   D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.25f, 1.0f, 2000.0f);
   m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);

   //Make sure that the z-buffer and lighting are enabled

   m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
   m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
}

LPDIRECT3DDEVICE9 CDxWindow::GetDevice()
{
	return m_pD3DDevice;
}
InputManager.h

#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

#include <dinput.h>
#include "LogManager.h"

#define KEYDOWN(name, key) (name[key] & 0x80) 
#define MOUSEBUTTONDOWN(key) (key & 0x80)

//Mouse buttons

#define MOUSEBUTTON_LEFT 0
#define MOUSEBUTTON_RIGHT 1
#define MOUSEBUTTON_MIDDLE 2

class CInputManager
{
public:
	CInputManager(CLogManager* logManager);
	virtual ~CInputManager();

	void ProcessMouse();
	void ProcessKeyboard();
    bool InitialiseDirectInput(HWND hWnd, HINSTANCE hInst);
private:
    void CleanUpDirectInput();    

	CLogManager* m_LogManager;

	LPDIRECTINPUT8 m_pDirectInput; 
    LPDIRECTINPUTDEVICE8 m_pKeyboard;
    LPDIRECTINPUTDEVICE8 m_pMouse;

	int m_nMouseLeft;
    int m_nMouseRight;
    int m_nMouseX;
    int m_nMouseY;
}

#endif
InputManager.cpp

#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

#include <dinput.h>
#include "LogManager.h"

#define KEYDOWN(name, key) (name[key] & 0x80) 
#define MOUSEBUTTONDOWN(key) (key & 0x80)

//Mouse buttons

#define MOUSEBUTTON_LEFT 0
#define MOUSEBUTTON_RIGHT 1
#define MOUSEBUTTON_MIDDLE 2

class CInputManager
{
public:
	CInputManager(CLogManager* logManager);
	virtual ~CInputManager();

	void ProcessMouse();
	void ProcessKeyboard();
    bool InitialiseDirectInput(HWND hWnd, HINSTANCE hInst);
private:
    void CleanUpDirectInput();    

	CLogManager* m_LogManager;

	LPDIRECTINPUT8 m_pDirectInput; 
    LPDIRECTINPUTDEVICE8 m_pKeyboard;
    LPDIRECTINPUTDEVICE8 m_pMouse;

	int m_nMouseLeft;
    int m_nMouseRight;
    int m_nMouseX;
    int m_nMouseY;
}

#endif
Advertisement
Instead of giving us your whole project, how about you give a list of the errors you''re getting. A small list of maybe 5 to 10 errors towards the beginning of your code could easily "confuse" your compiler enough to mess up its interpretation of the remainder of your code (in other words, errors are often cumulative).

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
c:\documents and settings\xxx\my documents\my projects\directx\testgame\dxwindow.h(8) : error C2236: unexpected ''class'' ''CDxWindow''c:\documents and settings\xxx\my documents\my projects\directx\testgame\dxwindow.h(8) : error C2143: syntax error : missing '';'' before ''{''c:\documents and settings\xxx\my documents\my projects\directx\testgame\dxwindow.h(8) : error C2447: missing function header (old-style formal list?)c:\documents and settings\xxx\my documents\my projects\directx\testgame\game.h(20) : error C2143: syntax error : missing '';'' before ''*''c:\documents and settings\xxx\my documents\my projects\directx\testgame\game.h(20) : error C2501: ''CDxWindow'' : missing storage-class or type specifiersc:\documents and settings\xxx\my documents\my projects\directx\testgame\game.h(20) : error C2501: ''m_DxWindow'' : missing storage-class or type specifiersc:\documents and settings\xxx\my documents\my projects\directx\testgame\game.h(21) : error C2143: syntax error : missing '';'' before ''*''c:\documents and settings\xxx\my documents\my projects\directx\testgame\game.h(21) : error C2501: ''CInputManager'' : missing storage-class or type specifiersc:\documents and settings\xxx\my documents\my projects\directx\testgame\game.h(21) : error C2501: ''m_InputManager'' : missing storage-class or type specifiersc:\documents and settings\xxx\my documents\my projects\directx\testgame\main.cpp(5) : error C2143: syntax error : missing '';'' before ''PCH creation point''DxWindow.cpp 
For one, you forgot the semicolon that goes at the end of the logmanager class declaration in logmanager.h. I suspect that''ll clear at least a couple of the errors.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
You forgot semicolons after your class blocks.
You have to put a semi-colon ";" after each class.

This topic is closed to new replies.

Advertisement