Hi.
I've made a start on my game engine. I only have 1 class so far.... CRenderDevice. I don't know if that's the only class I need for rendering the window right now, but we'll come to that later.....
Anyways.....
I had it all working and I was actually really happy with myself because I had made countless attempts to get this working and I did it. I decided to tidy up the code a bit and I have 3 stupid errors that I can't get rid of unless i'm msiing something really stupid.
Here's the errors:
... and here is the code, some is commented and some is not, I was just happy to see it working so i'll work on the comments later.Code:1>.\CMain.cpp(9) : error C2512: 'CRenderDevice' : no appropriate default constructor available 1>.\CMain.cpp(16) : error C2065: 'm_Device' : undeclared identifier 1>.\CMain.cpp(22) : error C2065: 'CDisplay' : undeclared identifier
I have highlighted the lines where the errors are in red.
CMain.cpp
CRenderDevice.hCode:#include "CRenderDevice.h" int WINAPI WinMain( HINSTANCE ChInstance, /*Handle to the current application instance*/ HINSTANCE ChPrevInstance, /*Not used in 32-bit Win32 programming and is 0*/ LPSTR cmdLine, /*Command line argument string used to run the program*/ int cmdShow) /*Specifies how the application window should be displayed*/ { CRenderDevice CDevice; if(!CDevice.CInitD3D( /*If CInitD3D fails*/ ChInstance, /*Application instance*/ 450, /*Application width*/ 375, /*Application height*/ true, /*Windowed?*/ D3DDEVTYPE_HAL, /*DeviceType*/ &m_Device)) /*Device*/ { MessageBox(0, "CInitD3D() - FAILED!", "Error", 0); return 0; } CDevice.EnterMsgLoop(CDisplay); /*Pump the message loop*/ return 0; /*Return false*/ }
CRenderDevice.cppCode:/*CRenderDevice.h*/ #include <d3dx9.h> class CRenderDevice { public: CRenderDevice(IDirect3DDevice9*); ~CRenderDevice(); bool CInitD3D( HINSTANCE ChInstance, int CWidth, int CHeight, bool CWindowed, D3DDEVTYPE CDeviceType, IDirect3DDevice9** Device); static LRESULT CALLBACK WndProc( HWND CHwnd, UINT CMsg, WPARAM wParam, LPARAM lParam); int EnterMsgLoop( bool (*ptr_display)(float timeDelta)); bool CDisplay(float CTimeDelta); protected: IDirect3DDevice9* m_Device; };
......Oh yeah... on a final note. If you have any ways to improve my code or any critisicm please share.... Thanks.Code:#include "CRenderDevice.h" CRenderDevice::CRenderDevice(IDirect3DDevice9* Device) { m_Device = Device; } CRenderDevice::~CRenderDevice() { m_Device->Release(); /*Done with the device*/ } bool CRenderDevice::CInitD3D( HINSTANCE ChInstance, int CWidth, int CHeight, bool CWindowed, D3DDEVTYPE CDeviceType, IDirect3DDevice9** Device) { HWND CHwnd = 0; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = ChInstance; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = "D3D Framework"; if(!RegisterClass(&wc)) { MessageBox(0, "RegisterClass() - FAILED!", "Error", 0); return 0; } CHwnd = CreateWindowEx( 0, "D3D Framework", "Engine", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CWidth, CHeight, CHwnd, 0, ChInstance, 0); if(!CHwnd) { MessageBox(0, "CreateWindowEx() - FAILED!", "Error", 0); return 0; } ShowWindow(CHwnd, SW_SHOW); UpdateWindow(CHwnd); HRESULT hr = 0; IDirect3D9* d3d9 = 0; d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if(!d3d9) { MessageBox(0, "Direct3DCreate9() - FAILED!", "Error", 0); return 0; /*Return false*/ } /*Step 2, Check for Hardware vp(VertexProcessing)*/ D3DCAPS9 caps; d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, CDeviceType, &caps); int vp = 0; /*Vertex processing variable*/ if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) /*If hardware vp is supported*/ { vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; /*Create hardware VertexProcessing*/ } else { vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; /*Create Software Vertwx Processing*/ } /*Step 3, Fill out the D3DPRESENT_PARAMETERS structure*/ D3DPRESENT_PARAMETERS d3dpp; /*The backbuffer width in pixels*/ d3dpp.BackBufferWidth = CWidth; /*The backbuffer height in pixels*/ d3dpp.BackBufferHeight = CHeight; /*The pixel format of the backbuffer eg(Alpha - 8, Red - 8, Green - 8, Blue - 8 = 32-bit pixel format)*/ d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; /*How many backbuffers we want*/ d3dpp.BackBufferCount = 1; /*The type of multisampling we want to use with the backbuffer*/ d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; /*The quality level of the multisampling*/ d3dpp.MultiSampleQuality = 0; /*Specify how the buffers in the flipping chain will be swapped*/ d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; /*The window handle associated with the device*/ d3dpp.hDeviceWindow = CHwnd; /*Specify true to run in windowed mode, false to run in fullscreen mode*/ d3dpp.Windowed = CWindowed; /*Set to true to have Direct3D create and maintain the depth/stencil buffer automatically*/ d3dpp.EnableAutoDepthStencil = true; /*The format of the depth/stencil format eg(24-bit depth with 8 bits reserved for the stencil buffer*/ d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; /*Some additional characteristics*/ d3dpp.Flags = 0; /*Refresh rate*/ d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; /*Describes the refresh rate between the adapter refresh rate and the rate which IDirect3DDevice9::Present operations are completed*/ d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; /*Step 4, Create the Device*/ hr = d3d9->CreateDevice( D3DADAPTER_DEFAULT, /*Primary Adapter*/ CDeviceType, /*Device type*/ CHwnd, /*Window associated with the device*/ vp, /*VertexProcessing*/ &d3dpp, /*Present parameters*/ Device); /*Return the created device*/ if(FAILED(hr)) /*If creating the device failed*/ { /*Try again using a 16-bit depth buffer*/ d3dpp.AutoDepthStencilFormat = D3DFMT_D16; hr = d3d9->CreateDevice( D3DADAPTER_DEFAULT, /*Primary Adapter*/ CDeviceType, /*Device type*/ CHwnd, /*Window associated with the device*/ vp, /*VertexProcessing*/ &d3dpp, /*Present parameters*/ Device); /*Return the created device*/ } if(FAILED(hr)) /*If it failed again*/ { d3d9->Release(); /*Done with the d3d9 object*/ MessageBox(0, "CreateDevice() - FAILED!", "Error", 0); return 0; /*Return false*/ } d3d9->Release(); /*Done with the d3d9 object*/ return 1; /*Return true*/ } int CRenderDevice::EnterMsgLoop(bool (*ptr_display)(float timeDelta)) { MSG CMsg; /*Message handler*/ ZeroMemory(&CMsg, sizeof(MSG)); /*Set everything in the message loop to zero*/ static float lastTime = (float)timeGetTime(); /*While msg doesn't = WM_QUIT(quit the program), execute the message loop*/ while(CMsg.message != WM_QUIT) /*Start of message loop*/ { /*Check to see for any messages in the message queue and see if any of them need processing*/ if(PeekMessage(&CMsg, 0, 0, 0, PM_REMOVE)) { /*Translate virtual-key messages into character messages*/ TranslateMessage(&CMsg); /*Dispatch a message to the windows procedure*/ DispatchMessage(&CMsg); } else { float currTime = (float)timeGetTime(); float timeDelta = (currTime - lastTime)* 0.001f; ptr_display(timeDelta); lastTime = currTime; } } return CMsg.wParam; } bool CRenderDevice::CDisplay(float CTimeDelta) { if(m_Device) { m_Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); m_Device->Present(0, 0, 0, 0); } return 1; } LRESULT CALLBACK CRenderDevice::WndProc(HWND CHwnd, UINT CMsg, WPARAM wParam, LPARAM lParam) { switch(CMsg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_KEYDOWN: if( wParam == VK_ESCAPE) DestroyWindow(CHwnd); break; } return DefWindowProc(CHwnd, CMsg, wParam, lParam); }
And sorry about my post being long.



LinkBack URL
About LinkBacks



CornedBee