Anyway, I've been having trouble actually executing this code. I started to get these errors:
1>------ Build started: Project: Cubes, Configuration: Debug Win32 ------ 1> winmain.cpp 1>c1xx : fatal error C1083: Cannot open source file: '..\..\..\..\Part II - It's A 3D World After All\Chapter 5 - Matrices, Transforms, and Rotations\Notes\Cubes\winmain.cpp': No such file or directory 1> dxManager.cpp 1>c1xx : fatal error C1083: Cannot open source file: '..\..\..\..\Part II - It's A 3D World After All\Chapter 5 - Matrices, Transforms, and Rotations\Notes\Cubes\dxManager.cpp': No such file or directory 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I couldn't find much on the internet, so I thought maybe I had to put the code in another place because the file directory was getting too long. So I created another project, and decided to copy and paste my code to this new project. Changing the properties such as Character Set and including the appropriate library files. I try and compile it and I get these errors:
1>------ Build started: Project: Cube, Configuration: Debug Win32 ------ 1> winmain.cpp 1>c:\users\jamie\desktop\cube\dxmanager.h(26): error C2146: syntax error : missing ';' before identifier 'pD3D' 1>c:\users\jamie\desktop\cube\dxmanager.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.h(27): error C2146: syntax error : missing ';' before identifier 'pD3DDevice' 1>c:\users\jamie\desktop\cube\dxmanager.h(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.h(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1> dxManager.cpp 1>c:\users\jamie\desktop\cube\dxmanager.h(26): error C2146: syntax error : missing ';' before identifier 'pD3D' 1>c:\users\jamie\desktop\cube\dxmanager.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.h(27): error C2146: syntax error : missing ';' before identifier 'pD3DDevice' 1>c:\users\jamie\desktop\cube\dxmanager.h(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.h(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\jamie\desktop\cube\dxmanager.cpp(7): error C2065: 'pD3D' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(8): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(18): error C2065: 'pD3D' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(20): error C2065: 'pD3D' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(20): error C2227: left of '->Release' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(21): error C2065: 'pD3D' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(24): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(26): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(26): error C2227: left of '->Release' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(27): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(42): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(45): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(45): error C2227: left of '->Clear' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(51): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(51): error C2227: left of '->Present' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(56): error C2065: 'pD3D' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(73): error C2065: 'pD3D' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(73): error C2227: left of '->CreateDevice' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(75): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(124): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(124): error C2227: left of '->CreateVertexBuffer' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(154): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(154): error C2227: left of '->SetTransform' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(170): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(170): error C2227: left of '->SetTransform' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(177): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(177): error C2227: left of '->BeginScene' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(179): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(179): error C2227: left of '->SetStreamSource' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(181): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(181): error C2227: left of '->SetFVF' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(189): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(189): error C2227: left of '->SetTransform' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(191): warning C4552: '+' : operator has no effect; expected operator with side-effect 1>c:\users\jamie\desktop\cube\dxmanager.cpp(192): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(192): error C2227: left of '->DrawPrimitive' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1>c:\users\jamie\desktop\cube\dxmanager.cpp(194): error C2065: 'pD3DDevice' : undeclared identifier 1>c:\users\jamie\desktop\cube\dxmanager.cpp(194): error C2227: left of '->EndScene' must point to class/struct/union/generic type 1> type is ''unknown-type'' 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It's quite a long list of errors and they are all pretty much the same. This is pretty much the same code I have been using throughout the few chapters of the book and haven't been getting any of these errors at all.
This is my code, remember pretty much the same code from other chapters:
customVertex.h File
struct CUSTOMVERTEX
{
float x, y, z;
DWORD color;
};dxManager.h File
#ifndef DXMANAGER_H
#define DXMANAGER_H
#include <d3d9.h>
#include <d3dx9.h>
#include "customVertex.h"
class dxManager
{
public:
dxManager();
~dxManager();
void cleanUp(void);
void clearScreen(void);
void endScene(void);
bool initDirect3D(HWND hWnd);
bool createCube(void);
void createCamera(float nearClip, float farClip);
void moveCamera(D3DXVECTOR3 vec);
void lookCamera(D3DXVECTOR3 vec);
void renderScene(void);
private:
LPDIRECT3D pD3D;
LPDIRECT3DDEVICE pD3DDevice;
LPDIRECT3DVERTEXBUFFER9 pVertexBuffer;
IDirect3DSurface9* pBackBuffer;
HRESULT hResult;
D3DXMATRIX viewMat;
D3DXMATRIX projMat;
D3DXVECTOR3 cameraPosition;
D3DXVECTOR3 cameraLook;
};
#endif // DXMANAGER_HdxManager.cpp File
#include "dxManager.h"
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
dxManager::dxManager()
{
pD3D = NULL;
pD3DDevice = NULL;
pVertexBuffer = NULL;
}
dxManager::~dxManager()
{
}
void dxManager::cleanUp(void)
{
if(pD3D != NULL)
{
pD3D->Release();
pD3D = NULL;
}
if(pD3DDevice != NULL)
{
pD3DDevice->Release();
pD3DDevice = NULL;
}
if(pVertexBuffer != NULL)
{
pVertexBuffer->Release();
pVertexBuffer = NULL;
}
}
void dxManager::clearScreen(void)
{
pBackBuffer = NULL;
hResult = NULL;
if(pD3DDevice == NULL)
return;
pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0), 1.0f, 0.0);
}
void dxManager::endScene(void)
{
pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
bool dxManager::initDirect3D(HWND hWnd)
{
if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
{
hResult = E_FAIL;
return false;
}
D3DPRESENT_PARAMETERS pD3DPresent;
ZeroMemory(&pD3DPresent, sizeof(D3DPRESENT_PARAMETERS));
pD3DPresent.BackBufferWidth = 640;
pD3DPresent.BackBufferHeight = 480;
pD3DPresent.BackBufferFormat = D3DFMT_X8R8G8B8;
pD3DPresent.BackBufferCount = 0;
pD3DPresent.SwapEffect = D3DSWAPEFFECT_DISCARD;
pD3DPresent.hDeviceWindow = hWnd;
pD3DPresent.Windowed = true;
hResult = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&pD3DPresent, &pD3DDevice);
if(FAILED(hResult))
return false;
return true;
}
bool dxManager::createCube(void)
{
CUSTOMVERTEX gVertices[] =
{
// 1
{-64.0f, 64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, 64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, -64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, -64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
// 2
{-64.0f, 64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, -64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, 64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, -64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
// 3
{-64.0f, 64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, 64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, 64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, 64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
// 4
{-64.0f, -64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, -64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, -64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, -64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
// 5
{ 64.0f, 64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, 64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, -64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{ 64.0f, -64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
// 6
{-64.0f, 64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, -64.0f, -64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, 64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)},
{-64.0f, -64.0f, 64.0f, D3DCOLOR_ARGB(0,0,0,255)}
};
hResult = pD3DDevice->CreateVertexBuffer(sizeof(gVertices) *
sizeof(CUSTOMVERTEX),
D3DUSAGE_SOFTWAREPROCESSING,
CUSTOMFVF,
D3DPOOL_DEFAULT,
&pVertexBuffer,
NULL);
if(FAILED(hResult))
return false;
VOID* vertexData;
hResult = pVertexBuffer->Lock(0, 0, (void**)vertexData, D3DLOCK_DISCARD);
if(FAILED(hResult))
return false;
memcpy(vertexData, gVertices, sizeof(gVertices));
pVertexBuffer->Unlock();
return true;
}
void dxManager::createCamera(float nearClip, float farClip)
{
D3DXMatrixPerspectiveFovLH(&projMat, D3DX_PI/4, 640/480,
nearClip, farClip);
pD3DDevice->SetTransform(D3DTS_PROJECTION, &projMat);
}
void dxManager::moveCamera(D3DXVECTOR3 vec)
{
cameraPosition = vec;
}
void dxManager::lookCamera(D3DXVECTOR3 vec)
{
cameraLook = vec;
D3DXMatrixLookAtLH(&viewMat, &cameraPosition,
&cameraLook,
&D3DXVECTOR3(0.0f, 1.0f, 0.0f));
pD3DDevice->SetTransform(D3DTS_VIEW, &viewMat);
}
void dxManager::renderScene(void)
{
D3DXMATRIX objectMat, translationMat, rotationMat;
pD3DDevice->BeginScene();
pD3DDevice->SetStreamSource(0, pVertexBuffer, 0, sizeof(CUSTOMVERTEX));
pD3DDevice->SetFVF(CUSTOMFVF);
D3DXMatrixTranslation(&translationMat, 0.0f, 64.0f, 0.0f);
D3DXMatrixRotationY(&rotationMat, timeGetTime()/1000.0f);
D3DXMatrixMultiply(&objectMat, &translationMat, &rotationMat);
pD3DDevice->SetTransform(D3DTS_WORLD, &objectMat);
for (int i = 0; i < 20; i+4)
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, i, 2);
pD3DDevice->EndScene();
}
winmain.cpp File
#include "dxManager.h"
HINSTANCE hInstance;
HWND hWnd;
dxManager* dxMgr = new dxManager();
bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void initCamera();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR cmdLine, int cmdShow)
{
if(!initWindow(hInstance))
return false;
if(!dxMgr->initDirect3D(hWnd))
return false;
if(!dxMgr->createCube())
return false;
initCamera();
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
dxMgr->clearScreen();
dxMgr->renderScene();
dxMgr->endScene();
}
}
dxMgr->cleanUp();
return (int)msg.wParam;
}
bool initWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = NULL;
wcex.cbWndExtra = NULL;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "DirectXExample";
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
hWnd = CreateWindow("DirectXExample", "DirectXExample",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
640, 480, NULL, NULL, hInstance, NULL);
if(!hWnd)
return false;
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return true;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
void initCamera()
{
dxMgr->createCamera(1.0f, 500.0f);
dxMgr->moveCamera(D3DXVECTOR3(0.0f, 0.0f, -450.0f));
dxMgr->lookCamera(D3DXVECTOR3(0.0f, 0.0f, 0.0f));
}I know it's quite a lot to look through, but it's best to just include it all rather than none. Some of these errors are appearing on my dxManager.h file where I have declared my Direct3D Object, "pD3D" and Direct3D Device, "pD3DDevice".






