Sign in to follow this  

Im drowning help....

This topic is 4159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Id like to add this book called " physics modeling for game prommaers" by David Conger to the book discussion forum. Its a great book (3d math code is well explained) but im having a hell of a time to get the code to run(and im guessing many others have the same prob). gamedev.net is advertised in the back of the book (if thats any incetive!) [Edited by - pascalosti on July 22, 2006 10:52:26 PM]

Share this post


Link to post
Share on other sites
Can someone help me please get this code to work it came with the book I cannot get it to work on any compilers i tried. It says PMD3DApp.h is missing but its inside the project (and many other errors) ( i have DirectX linked). I've include the 3 files PMD3DApp.cpp, FrameFns.cpp, PMD3DApp.h in these 3 posts.

The authour gives 3 choices the appwizard (which does not exist, com (whatever that is) and the easy way (these 3 files) which ive been fighting with forever)


file name FrameFns.cpp

//------------------------------Begin FrameFns.cpp-------------------
/*
File Name: FrameFns.cpp
Comments: This file contains the functions required by the
physics modeling framework. They are all ready and
waiting for your code.
*/



// Include Files-----------------------------------------------------

#include "PMD3DApp.h"
#include "stdafx.h"

// End Include Files-------------------------------------------------


// Begin Use Namespaces----------------------------------------------

using namespace pmframework;

// End Use Namespaces------------------------------------------------


/*
Function: OnAppLoad
Parameters
Input: None.
Output: None.
Returns: Returns if it is successful, or false if not.
Comments: This function is required by the physics modeling
framework. It MUST call the d3d_app::InitApp() function.
*/

bool OnAppLoad()
{
bool loadOK=true;

// This call MUST appear in this function.
theApp.InitApp("test");

// Your code goes here.

return (loadOK);
}


/*
Function: PreD3DInitialization
Parameters
Input: None.
Output: None.
Returns: Returns true if initialization is successful, or false
if not.
Comments: This function is required by the physics modeling
framework.
*/

bool PreD3DInitialization()
{
bool initOK=true;

// Your code goes here.

return (initOK);
}


/*
Function: PostD3DInitialization
Parameters
Input: None.
Output: None.
Returns: Returns true if initialization is successful, or false
if not.
Comments: This function is required by the physics modeling
framework.
*/

bool PostD3DInitialization()
{
bool initOK=true;

// Your code goes here.

return (initOK);
}

/*
Function: GameInitialization
Parameters
Input: None.
Output: None.
Returns: Returns true to indicate successful initialization.
Comments: This function is required by the physics modeling
framework. It is used to set up the program's scenery
or other geometry.
*/

bool GameInitialization()
{
bool initOK=true;

// Your code goes here.

return (initOK);
}


/*
Function: HandleMessage
Parameters
Input: hWnd, msg, wParam, lParam - These are the standard
parameters that a program's message handling
function receives from Windows. For more information
on these parameters, see topic "WindowProc" in the
Windows Platform SDK documentation.
Output: None.
Returns: Returns true if this function handles the message.
Returns false if this function did not handle the
message.
Comments: This function is required by the physics modeling
framework. Games use it to handle standard Windows
messages.
*/

bool HandleMessage(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
bool messageHandled=false;

// Your code goes here.

return (messageHandled);
}


/*
Function: UpdateFrame
Parameters
Input: None.
Output: None.
Returns: Returns true if the update is successful, or false if
not.
Comments: This function is required by the physics modeling
framework. It is called once per frame and does the work
of updating the frame.
*/

bool UpdateFrame()
{
bool updateOK=true;

// Your code goes here.

return (updateOK);
}


/*
Function: RenderFrame
Parameters
Input: None.
Output: None.
Returns: Returns true if the frame was rendered, or false if not.
Comments: This function is required by the physics modeling
framework. It renders frame, usually by rendering the
contents of the vertex buffer.

Note that it is not necessary to call the D3D funcitons
BeginScene() and EndScene(). The framework handles that
for you.
*/

bool RenderFrame()
{
bool renderOK=true;

// Your code goes here.

return (renderOK);
}


/*
Function: GameCleanup
Parameters
Input: None.
Output: None.
Returns: Returns true if cleanup was successful, or false if not.
Comments: This function is required by the physics modeling
framework. Use it to do any game-specific clean up.
*/

bool GameCleanup()
{
bool cleanupOK=true;

// Your code goes here.

return (cleanupOK);
}

//------------------------------End cleanupOK.cpp--------------------


Share this post


Link to post
Share on other sites

PMD3DApp.cpp file

//------------------------------Begin PMD3DApp.cpp--------------------
/*
File Name: PMD3DApp.cpp
Comments: This file contains the objects, types, functions, and
so forth, that provide the framework for a game. The
function in this file initialize Direct3D and call a
set of functions provided by your game. The functions
provided by your game implement the game logic, while
the functions in this file handle much of the work of
using D3D.
*/



// Include Files-----------------------------------------------------

/* The constant EXTERN is defined as blank so that memory will be
allocated for the the global variable theApp.*/

#define EXTERN
#include "PMD3DApp.h"
#include "stdafx.h"

// End Include Files-------------------------------------------------


// Begin Use Namespaces----------------------------------------------

using namespace pmframework;

// End Use Namespaces------------------------------------------------


// Constants---------------------------------------------------------

// Visible only in this file.
static const char *D3DAPP_WINDOW_CLASS_NAME="D3DAPP";

// End Constants-----------------------------------------------------


// Prototypes--------------------------------------------------------

LRESULT WINAPI MsgProc(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);

namespace pmframework
{
INT WINAPI AppMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow);
HRESULT InitD3D(
HWND hWnd);
VOID CleanupD3D();
VOID Render();
}
// End Prototypes-----------------------------------------------------


/* Program entry point for every windows program. If you need more
information on WinMan(), please see the Windows Platform SDK
documentation. */

INT WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
return (pmframework::AppMain(
hInstance,hPrevInstance,lpCmdLine,nCmdShow));
}


/*Standard Windows message processing function. For mor information,
please see the Windows Platform SDK documentation.*/

LRESULT WINAPI MsgProc(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
if (!HandleMessage(hWnd,msg,wParam,lParam))
{
switch(msg)
{
case WM_DESTROY:
// Perform game cleanup.
GameCleanup();
// Clean up D3D
CleanupD3D();
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}



namespace pmframework
{


/*
Function: AppMain
Parameters
Input: hInstance, hPrevInstance, lpCmdLine, nCmdShow - Standard
parameters that are normally passed by Windows to
WinMain(). For more information, please see the
Windows Platform SDK documentation topic "WinMain".
Output: None.
Returns: Returns 0.
Comments: This function does the tasks that are normally
performed by WinMain(). Unlike WinMain() this function
is a member of the pmframework namespace. Therefore,
unlike WinMain() it can easily be made a friend
function of the d3d_app class. Its status as a friend
function enables AppMain() to get access to the
private member data of the variable theApp. Having
this type of access helps the framework hide its
implementation and data. AppMain() has direct access
to all the data that it needs to get the program's
window up and running. The game, on the other hand,
just has read-only access to most of the data.
*/

INT WINAPI AppMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
bool noError=true;
WNDCLASSEX wc;
HWND hWnd;

noError=OnAppLoad();
assert(theApp.appInitialized==true);

if (noError)
{
// Register the window class
WNDCLASSEX tempWC =
{
sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,
GetModuleHandle(NULL),NULL,NULL,NULL,NULL,
D3DAPP_WINDOW_CLASS_NAME,NULL
};

wc=tempWC;
if (RegisterClassEx(&wc)==0)
{
return (0);
}
}

if (noError)
{
// Create the application's window
hWnd = CreateWindow(
D3DAPP_WINDOW_CLASS_NAME,
(LPCSTR)theApp.windowTitle.c_str(),
WS_OVERLAPPEDWINDOW,
100,100,256,256,
GetDesktopWindow(),
NULL,wc.hInstance,NULL);
}

// If the window was created...
if ((noError) && (hWnd!=NULL))
{
// If the initialization could not be performed...
if (!PreD3DInitialization())
{
noError=false;;
}
}

// Initialize Direct3D
if ((noError) && (SUCCEEDED(InitD3D(hWnd))))
{
noError=PostD3DInitialization();
}

// Initialize the game.
if (noError)
{
noError=GameInitialization();
}

if (noError)
{
// Show the window
ShowWindow(hWnd,SW_SHOWDEFAULT);
UpdateWindow(hWnd);

// Enter the message loop
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message!=WM_QUIT)
{
if(PeekMessage(&msg,NULL,0U,0U,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
UpdateFrame();
Render();
}
}
}

UnregisterClass(D3DAPP_WINDOW_CLASS_NAME,wc.hInstance);
return 0;
}

/*
Function: InitD3D
Parameters
Input: hWnd - The handle of the window to which D3D renders
the scene.
Output: None.
Returns: Returns S_OK upon success, or E_FAIL if an error occurs.
Comments: Handles D3D initialization.
*/

HRESULT InitD3D(HWND hWnd)
{
HRESULT hr = S_OK;
D3DPRESENT_PARAMETERS d3dpp;

// Create the D3D object.
if((theApp.direct3D = Direct3DCreate9(D3D_SDK_VERSION))==NULL)
{
// If the object wasn't created...
hr = E_FAIL;
}
else
{
// If the D3D object was created...
// Set up the structure used to create the D3DDevice
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
}

// Create the D3DDevice
// Can the device use the HAL?
if ((hr==S_OK) &&
(FAILED(theApp.direct3D->CreateDevice(
D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,&theApp.d3dDevice))))
{
// If not, maybe it can use software emulation...
if(FAILED(theApp.direct3D->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,
&theApp.d3dDevice)))
{
// If not, too bad.
hr = E_FAIL;
}
}

if (hr==S_OK)
{
/* Turn off culling,so we see the front and back of the
triangle.*/

theApp.d3dDevice->SetRenderState(
D3DRS_CULLMODE,
D3DCULL_NONE);

/* Turn off D3D lighting,since we are providing our own
vertex colors.*/

theApp.d3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
}

return hr;
}


/*
Function: CleanupD3D
Parameters
Input: None.
Output: None.
Returns: Nothing.
Comments: Performs the required cleanup for Direct3D. This
function does not handle such tasks as releasing
memory for any 3-D scenes or models you created.
You must provide a function called GameCleanup()
to perform that type of cleanup.
*/

VOID CleanupD3D()
{
// Release the vertex buffer.
if(theApp.vertexBuffer != NULL)
theApp.vertexBuffer->Release();

// Release the rendering device.
if(theApp.D3DRenderingDevice() != NULL)
theApp.D3DRenderingDevice()->Release();

// Release the D3D object.
if(theApp.direct3D != NULL)
theApp.direct3D->Release();
}


/*
Function: Render
Parameters
Input: None.
Output: None.
Returns: Nothing.
Comments: Handles some of the overhead required for rendering a
frame.
*/

VOID Render()
{
// Clear the backbuffer to a black color
theApp.D3DRenderingDevice()->Clear(
0,NULL,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0),
1.0f,0);

// Begin the scene
if(SUCCEEDED(theApp.D3DRenderingDevice()->BeginScene()))
{
RenderFrame();

// End the scene
theApp.D3DRenderingDevice()->EndScene();
}

// Present the backbuffer contents to the display
theApp.D3DRenderingDevice()->Present(NULL,NULL,NULL,NULL);
}

}



//------------------------------End PMD3DApp.cpp---------------------



Share this post


Link to post
Share on other sites
//PMD3DApp.h file


//------------------------------Begin PMD3DApp.h---------------------
/*
File Name: PMD3DApp.h
Comments: This file contains the definitions of the objects,
types, inline functions, and so forth, that provide
the framework for a game. Your game uses the
framework to initialize and handle some of the
overhead required to use D3D.
*/


#ifndef _PMD3DAPP_H
#define _PMD3DAPP_H

// Include Files-----------------------------------------------------

#include <Windows.h>
#include <mmsystem.h>
#include <d3dx9.h>
#include <assert.h>
#include <string>

// End Include Files-------------------------------------------------

// Begin Namespace---------------------------------------------------

namespace pmframework
{

//Begin Class Definitions--------------------------------------------

//Begin d3d_app------------------------------------------------------

/* You can add member data to this class. However, the member data
should relate to initializing the application and initializing
DirectX. */

class d3d_app
{
private:
// App properties.
bool appInitialized;

// Window properties.
std::string windowTitle;

// D3D properties.
LPDIRECT3D9 direct3D; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 d3dDevice; // Our rendering device
LPDIRECT3DVERTEXBUFFER9 vertexBuffer; // Buffer to hold vertices

public:
d3d_app();
bool InitApp(
std::string initialWindowTitle);

LPDIRECT3DDEVICE9 D3DRenderingDevice(void);

LPDIRECT3DVERTEXBUFFER9 D3DVertexBuffer(void);
void D3DVertexBuffer(
LPDIRECT3DVERTEXBUFFER9 vertexBufferPointer);

friend INT WINAPI AppMain(
HINSTANCE hInst,
HINSTANCE,
LPSTR,
INT);
friend HRESULT InitD3D(
HWND hWnd);
friend VOID CleanupD3D();
};

//Begin Inline Functions for the d3d_app Class-----------------------

/*
Function: d3d_app
Member of: d3d_app
Parameters
Input: None.
Output: None.
Returns: Nothing.
Comments: No-arg constructor. Initializes the class data members
to known values. It especially vital that the member
appInitialized be set to false. This enables the
framework to throw an error if InitApp() isn't called
by the game.

If you add data members to this class, you should
initialize them in this function.
*/

inline d3d_app::d3d_app()
{
direct3D = NULL;
d3dDevice = NULL;
vertexBuffer = NULL;
appInitialized=false;
}


/*
Function: InitApp
Member of: d3d_app
Parameters
Input: initialWindowTitle - The initial title for windowed
applications. The title can change later, but
not by using this class member.
Output: None.
Returns: Returns true if initialization is successful, or
false if not.
Comments: This function must be called or the famework throws
an assertion. Your game must call this function in
the OnAppLoad() function.

If you add data members to the d3d_app class, then
you also need to add parameters to this function.
Use the parameters you add to set your new data
members to the appropriate values.
*/

inline bool d3d_app::InitApp(
std::string initialWindowTitle)
{
windowTitle=initialWindowTitle;

appInitialized=true;
return(appInitialized);
}


/*
Function: D3DRenderingDevice
Member of: d3d_app
Parameters
Input: None.
Output: None.
Returns: Returns a pointer to a Direct3D rendering device.
Comments: Use this function to get the device pointer.
*/

inline LPDIRECT3DDEVICE9 d3d_app::D3DRenderingDevice(void)
{
return (d3dDevice);
}


/*
Function: D3DRenderingDevice
Member of: d3d_app
Parameters
Input: None.
Output: None.
Returns: Returns a pointer to a Direct3D vertex buffer.
Comments: Use this function to get the vertex buffer
pointer.
*/

inline LPDIRECT3DVERTEXBUFFER9 d3d_app::D3DVertexBuffer(void)
{
return (vertexBuffer);
}

/*
Function: D3DRenderingDevice
Member of: d3d_app
Parameters
Input: vertexBufferPointer - A pointer to a D3D vertex buffer
that your game creates.
Output: None.
Returns: Nothing.
Comments: Use this function to set a pointer to a vertex buffer.
*/

inline void d3d_app::D3DVertexBuffer(
LPDIRECT3DVERTEXBUFFER9 vertexBufferPointer)
{
vertexBuffer=vertexBufferPointer;
}

//End Inline Functions for the d3d_app Class-------------------------

//End d3d_app--------------------------------------------------------

//End Class Definitions----------------------------------------------


// Global Variables--------------------------------------------------
/* This declaration provides all of the files in your game with
access to the global variable theApp. It uses an old C
programming trick to declare the variable external in
all program modules except PMD3DApp.obj.*/

#ifndef EXTERN
#define EXTERN extern
#endif

EXTERN d3d_app theApp;

// End Global Variables----------------------------------------------

}
// End Namespace---------------------------------------------------


// Prototypes--------------------------------------------------------

/* The following prototypes are for required functions. Your game
must provide all of these functions or it will not compile.*/

bool OnAppLoad();
bool PreD3DInitialization();
bool PostD3DInitialization();
bool GameInitialization();
bool HandleMessage(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
bool UpdateFrame();
bool RenderFrame();
bool GameCleanup();

// End Prototypes----------------------------------------------------


#endif

//------------------------------End PMD3DApp.h-----------------------


Share this post


Link to post
Share on other sites
what compilers did you try?

I suggest using a VS.NET C++ IDE, its easy to use.

Just create a new empty C++ Win32 project. Copy paste your files into the project directory, add them to the project and don't forget to link to DirectX.

You might have to remove all references to precompiled headers(stdafx.h) in case they don't come with the project.

Share this post


Link to post
Share on other sites
That helped alot thank you. I do still have 3 errors if anyone can help me with them.


Error 1 error C2440: 'initializing' : cannot convert from 'const char *' to 'LPCWSTR' c:\documents and settings\posti\desktop\delete\ass\ass\pmd3dapp.cpp 149

WNDCLASSEX tempWC =
{
sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,
GetModuleHandle(NULL),NULL,NULL,NULL,NULL,
D3DAPP_WINDOW_CLASS_NAME,NULL
};




Error 2 error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR' c:\documents and settings\posti\desktop\delete\ass\ass\pmd3dapp.cpp 168

if (noError)
{
// Create the application's window
hWnd = CreateWindow(
D3DAPP_WINDOW_CLASS_NAME,
(LPCSTR)theApp.windowTitle.c_str(),
WS_OVERLAPPEDWINDOW,
100,100,256,256,
GetDesktopWindow(),
NULL,wc.hInstance,NULL);
}



Error 3 error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR' c:\documents and settings\posti\desktop\delete\ass\ass\pmd3dapp.cpp 217


UnregisterClass(D3DAPP_WINDOW_CLASS_NAME,wc.hInstance);



Share this post


Link to post
Share on other sites
Quote:
Original post by ronkfist
try explicit casting to the right type, like this...

UnregisterClass((LPCWSTR)D3DAPP_WINDOW_CLASS_NAME,wc.hInstance);

No, don't. That won't do what you think. You need to change your project's character set to use Multi-Byte or Single-Byte instead of Unicode. You do this by going to "Project->Properties->Configuration Properties->General->Character Set" and set that to "Use Multi-Byte Character Set" or "Not Set". MSVC8 uses Unicode by default.

Share this post


Link to post
Share on other sites

with multi or single byte {i get

Error 1 error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "long __cdecl pmframework::InitD3D(struct HWND__ *)" (?InitD3D@pmframework@@YAJPAUHWND__@@@Z) PMD3DApp.obj


Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\posti\Desktop\delete\ass\Debug\ass.exe 1
}

------------------------------------------------------------------------

with a combination (ronkfist suggestion and multi){

Error 1 error C2664: 'UnregisterClassA' : cannot convert parameter 1 from 'LPCWSTR' to 'LPCSTR' c:\documents and settings\posti\desktop\delete\ass\ass\pmd3dapp.cpp 216


}




Share this post


Link to post
Share on other sites
You have to link in the DirectX libraries.

Go under Tools->Options->Projects and Solutions->VC++ Directories. Under the selection box "Show Directories For", select "Library Files" and add the directory to which you installed DirectX. There should be a folder in that directory called "Lib". Add this folder to the library list.

Next, select Project->Properties->Linker->Input, and under Additional Dependencies, enter these items separated by a space: "d3d9.lib d3dx9.lib".

About your second problem, remove the cast that ronkfist told you to add:
UnregisterClass(D3DAPP_WINDOW_CLASS_NAME,wc.hInstance);

Share this post


Link to post
Share on other sites

This topic is 4159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this