Hi I have the book Beginning DirectX9 I've gotten everything until example2 in the book to compile when typed in. And I've tried to even copy their code thinking I might have typed it in wrong. But is still does not work right the way I've linked it is with this -ld3d9 and -ld3dx9 is there another link I do not know about. That or what is causing it not to compile the box before this was the same. But it did nto rotate like this one I ran the .exe file from the book to know.
Here is the code below to the project
include <windows.h>
include <d3d9.h>
include <d3dx9tex.h>
HINSTANCE hInst; // holds the instance for this app
HWND wndHandle; // global window handle
// camera variables
D3DXMATRIX matView; // the view matrix
D3DXMATRIX matProj; // the projection matrix
D3DXVECTOR3 cameraPosition; // the position of the camera
D3DXVECTOR3 cameraLook; // where the camera is pointing
// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z; // The untransformed, 3D position for the vertex
DWORD color;
};
// Our custom FVF, which describes our custom vertex structure
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
// call our function to init and create our window
if (!initWindow(hInstance))
{
MessageBox(NULL, "Unable to create window", "ERROR", MB_OK);
return false;
}
// 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,255,0,255)},{-64.0f,-64.0f,64.0f,D3DCOLOR_ARGB(0,0,0,255)},};// Create the vertex buffer.HRESULThr;hr=pd3dDevice->CreateVertexBuffer(sizeof(g_Vertices)*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&vertexBuffer,NULL);ifFAILED(hr)returnfalse;// prepare to copy the vertices into the vertex bufferVOID*pVertices;// lock the vertex bufferhr=vertexBuffer->Lock(0,sizeof(g_Vertices),(void**)&pVertices,0);// check to make sure the vertex buffer can be lockedifFAILED(hr)returnfalse;// copy the vertices into the buffermemcpy(pVertices,g_Vertices,sizeof(g_Vertices));// unlock the vertex buffervertexBuffer->Unlock();returntrue;
/**********
* createCamera
* creates a virtual camera **********/
void createCamera(float nearClip, float farClip)
{
//Here we specify the field of view, aspect ration and near and far clipping planes.
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 640/480, nearClip, farClip);
pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
}
/**********
* moveCamera
* moves the camera to a position specified by the vector passed as a
* parameter **********/
void moveCamera(D3DXVECTOR3 vec)
{
cameraPosition = vec;
}
/**********
* pointCamera
* points the camera a location specified by the passed vector **********/
void pointCamera(D3DXVECTOR3 vec)
{
cameraLook = vec;
D3DXMatrixLookAtLH(&matView,&cameraPosition,//Camera Position&cameraLook,//Look At Position&D3DXVECTOR3(0.0f,1.0f,0.0f));//Up Directionpd3dDevice->SetTransform(D3DTS_VIEW,&matView);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
D3DXMatrixLookAtLH(&matView, &cameraPosition, //Camera Position
&cameraLook, //Look At Position
&D3DXVECTOR3(0.0f, 1.0f, 0.0f)); //Up Direction I want you to know this line stops
pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
}
Just in case you did not see it this is the line in this function.
&D3DXVECTOR3(0.0f, 1.0f, 0.0f));
Stops right here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I must have messed up the link in the other code I compiled because I copied the links from stuff I compiled. And it ran past where it stoped before here is the Compile Log below.
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Mike Neiheisel\My Documents\chapter5\example2\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Mike Neiheisel\My Documents\chapter5\example2\Makefile.win" all
g++.exe winmain.o -o "example2.exe" -L"C:/Dev-Cpp/lib" -mwindows -ld3d9 -ld3dx9
winmain.o(.text+0x2e9):winmain.cpp: undefined reference to `timeGetTime@0'
collect2: ld returned 1 exit status
make.exe: *** [example2.exe] Error 1
Execution terminated
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I moved the code to the C: area like you have told me before without spaces. I've run tons of code I've done in the MyDocuments are with spaces and they almost always run fine. I just wanted to let you know this I don't want to stick a bunch of code in the C: area on my compter.
Here is what the Compile Log says and this code came from the book just they did it in Microsoft Visual C++ 6.0. I thought it might be because there was not #include <time.h> and tried it still did not work correct.
Compiler: Default compiler
Building Makefile: "C:\example2\Makefile.win"
Executing make...
make.exe -f "C:\example2\Makefile.win" all
g++.exe winmain.o -o "example2.exe" -L"C:/Dev-Cpp/lib" -mwindows -ld3d9 -ld3dx9
winmain.o(.text+0x2e9):winmain.cpp: undefined reference to `timeGetTime@0'
collect2: ld returned 1 exit status
make.exe: *** [example2.exe] Error 1
Execution terminated
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I know it is a linker problem but what did he really learn from you pointing out what needed to be linked. Sometimes it is best to just give a hint and make people actually do some research, that way in the future they get into the habit of looking for the answer instead of just posting for it. If he was to search the inet for mmsystem.h he would have seen the million of posts that have that info in it(what to link). IMO he was being lazy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-07-27
Yawn
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ya that is probably what he did while he waited for you to give him the answer. Funny how you bitch about people and their homework and not giving out the answers yet if you do it its all good and dandy. Funny shit
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-07-27
Learning how to distinguish between a compiler error and a linker error is a far more important and useful lesson than which Win32 export libraries need linking.
And this is not homework in any case, no one takes an academic course in DirectX, and even if it were, the aim of a programming course is to learn to program, not how to wield any particular tool-chain.
If we ask people to post a log and someone actually does the right thing and posts it to simply ignore it would be just dumb and plain rude.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the help and you are right how would I know what is in a linker especially when the book does not say it needs this linker. They tell you about needing the –ld3d9 and –ld3dx9, but nothing about linking this one thank you for the answer. I would have given up and figure that it was a compiler problem not the fact it wanted this linker I kind of did though, which is why I went here for an answer.
And no I’m not in school making it harder for me I’m just using the books I’ve had Visual Basic 6.0 in Jr. College. But I never had any C++ classes ever just studying it on my own. I just have books on programming in C++ and ones for making Video Games in C++.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi I have the book Beginning DirectX9 I've gotten everything until example2 in the book to compile when typed in. And I've tried to even copy their code thinking I might have typed it in wrong. But is still does not work right the way I've linked it is with this -ld3d9 and -ld3dx9 is there another link I do not know about. That or what is causing it not to compile the box before this was the same. But it did nto rotate like this one I ran the .exe file from the book to know.
Here is the code below to the project
include <windows.h>
include <d3d9.h>
include <d3dx9tex.h>
HINSTANCE hInst; // holds the instance for this app
HWND wndHandle; // global window handle
LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pd3dDevice;
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
// camera variables
D3DXMATRIX matView; // the view matrix
D3DXMATRIX matProj; // the projection matrix
D3DXVECTOR3 cameraPosition; // the position of the camera
D3DXVECTOR3 cameraLook; // where the camera is pointing
// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z; // The untransformed, 3D position for the vertex
DWORD color;
};
// Our custom FVF, which describes our custom vertex structure
define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
////////////////////////////////////////////// forward declarations
bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
bool initDirect3D(HWND hwnd);
void shutdownDirect3D(void);
bool createCube(void);
void createCamera(float nearClip, float farClip);
void moveCamera(D3DXVECTOR3 vec);
void pointCamera(D3DXVECTOR3 vec);
define SCREEN_WIDTH 640
define SCREEN_HEIGHT 480
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
// call our function to init and create our window
if (!initWindow(hInstance))
{
MessageBox(NULL, "Unable to create window", "ERROR", MB_OK);
return false;
}
}
bool initWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
if (!wndHandle)
return false;
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
bool createCube(void)
{
// Initialize three vertices for rendering a triangle
CUSTOMVERTEX g_Vertices[] =
{
// 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)},
}
bool initDirect3D(HWND hwnd)
{
if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return false;
}
void shutdownDirect3D(void)
{
if( pd3dDevice != NULL)
{
pd3dDevice->Release();
pd3dDevice = NULL;
}
if( pD3D != NULL)
{
pD3D->Release();
pD3D = NULL;
}
}
/**********
* createCamera
* creates a virtual camera
**********/
void createCamera(float nearClip, float farClip)
{
//Here we specify the field of view, aspect ration and near and far clipping planes.
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 640/480, nearClip, farClip);
pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
}
/**********
* moveCamera
* moves the camera to a position specified by the vector passed as a
* parameter
**********/
void moveCamera(D3DXVECTOR3 vec)
{
cameraPosition = vec;
}
/**********
* pointCamera
* points the camera a location specified by the passed vector
**********/
void pointCamera(D3DXVECTOR3 vec)
{
cameraLook = vec;
}
Thanks it worked was a link error you were right once I put in -lwinmm the program ran correct.
Before I forget it stops at this part in the code right at the bottom look.
void pointCamera(D3DXVECTOR3 vec)
{
cameraLook = vec;
D3DXMatrixLookAtLH(&matView, &cameraPosition, //Camera Position
&cameraLook, //Look At Position
&D3DXVECTOR3(0.0f, 1.0f, 0.0f)); //Up Direction I want you to know this line stops
pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
}
Just in case you did not see it this is the line in this function.
&D3DXVECTOR3(0.0f, 1.0f, 0.0f));
Stops right here.
I must have messed up the link in the other code I compiled because I copied the links from stuff I compiled. And it ran past where it stoped before here is the Compile Log below.
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Mike Neiheisel\My Documents\chapter5\example2\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Mike Neiheisel\My Documents\chapter5\example2\Makefile.win" all
g++.exe winmain.o -o "example2.exe" -L"C:/Dev-Cpp/lib" -mwindows -ld3d9 -ld3dx9
winmain.o(.text+0x2e9):winmain.cpp: undefined reference to `timeGetTime@0'
collect2: ld returned 1 exit status
make.exe: *** [example2.exe] Error 1
Execution terminated
I moved the code to the C: area like you have told me before without spaces. I've run tons of code I've done in the MyDocuments are with spaces and they almost always run fine. I just wanted to let you know this I don't want to stick a bunch of code in the C: area on my compter.
Here is what the Compile Log says and this code came from the book just they did it in Microsoft Visual C++ 6.0. I thought it might be because there was not #include <time.h> and tried it still did not work correct.
Compiler: Default compiler
Building Makefile: "C:\example2\Makefile.win"
Executing make...
make.exe -f "C:\example2\Makefile.win" all
g++.exe winmain.o -o "example2.exe" -L"C:/Dev-Cpp/lib" -mwindows -ld3d9 -ld3dx9
winmain.o(.text+0x2e9):winmain.cpp: undefined reference to `timeGetTime@0'
collect2: ld returned 1 exit status
make.exe: *** [example2.exe] Error 1
Execution terminated
timeGetTime is a function in "mmsystem.h"
>> timeGetTime is a function in "mmsystem.h"
This is a linker error not a compiler error, the header file will make no difference.
The solution is to link libwinmm.s (-lwinmm)
Clifford
I know it is a linker problem but what did he really learn from you pointing out what needed to be linked. Sometimes it is best to just give a hint and make people actually do some research, that way in the future they get into the habit of looking for the answer instead of just posting for it. If he was to search the inet for mmsystem.h he would have seen the million of posts that have that info in it(what to link). IMO he was being lazy.
Yawn
ya that is probably what he did while he waited for you to give him the answer. Funny how you bitch about people and their homework and not giving out the answers yet if you do it its all good and dandy. Funny shit
Learning how to distinguish between a compiler error and a linker error is a far more important and useful lesson than which Win32 export libraries need linking.
And this is not homework in any case, no one takes an academic course in DirectX, and even if it were, the aim of a programming course is to learn to program, not how to wield any particular tool-chain.
If we ask people to post a log and someone actually does the right thing and posts it to simply ignore it would be just dumb and plain rude.
Clifford
Thanks for the help and you are right how would I know what is in a linker especially when the book does not say it needs this linker. They tell you about needing the –ld3d9 and –ld3dx9, but nothing about linking this one thank you for the answer. I would have given up and figure that it was a compiler problem not the fact it wanted this linker I kind of did though, which is why I went here for an answer.
And no I’m not in school making it harder for me I’m just using the books I’ve had Visual Basic 6.0 in Jr. College. But I never had any C++ classes ever just studying it on my own. I just have books on programming in C++ and ones for making Video Games in C++.