Jump to content
  • Advertisement
Sign in to follow this  
striker87

Role Playing Games with DirectX 2nd Edition help

This topic is 2985 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

I purchased the book and been trying to follow along and having problems using the source code and don't understand why it isn't working as I had setup my Visual Studio like it says in the book. I have both Visual Studio 2008 Proffesional and Visual Studio 2010 Beta 2. If anyone else has this book and has had the same issues and know a fix to get it where I can run the source code and go along with the book I would appreciate it. Also if anyone has any suggestions on any tutorials to making games with C++ I'd appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
What version of Visual Studio is the book written for? I have the first edition of this book, and I believe it's written for VC6, (which is over a decade old) and for an ancient DirectX SDK which is a bit different from the current SDK (Especially in the D3DX library).

What sort of "problems using the source code" are you having? Can't open the files? Won't compile? Won't link? Causes your PC to burst into flames when you put the CD in the drive?

Share this post


Link to post
Share on other sites
Quote:
Original post by striker87
The source code is VC6 in the second edition and can't compile it.
I'm not surprised to be honest - VC6 is not a C++ compiler, it was released before the first C++ standard, and it's broken in many, many ways.

What sort of errors do you get that you're not able to fix yourself?

Share this post


Link to post
Share on other sites
Sorry it took me so long to reply been in the field the past few weeks. For one the source code I get these errors:

Error 2 error C2664: 'D3DXCreateFontIndirectA' : cannot convert parameter 2 from 'LOGFONT *' to 'const D3DXFONT_DESCA *' d:\prpgdx\bookcode\chap02\font\winmain.cpp 138 Font
Error 3 error C2039: 'Begin' : is not a member of 'ID3DXFont' d:\prpgdx\bookcode\chap02\font\winmain.cpp 171 Font
Error 4 error C2660: 'ID3DXFont::DrawTextA' : function does not take 5 arguments d:\prpgdx\bookcode\chap02\font\winmain.cpp 172 Font
Error 5 error C2039: 'End' : is not a member of 'ID3DXFont' d:\prpgdx\bookcode\chap02\font\winmain.cpp 173 Font

Share this post


Link to post
Share on other sites
Those errors are because the version of D3DX the book uses is out of date. You'll have to either uninstall your current SDK and install the one that comes with the book, or understand what the code is trying to do, and convert that to the current SDK function calls.

Error 2 is because D3DXCreateFontIndirect now takes a D3DXFONT_DESC struct as the second parameter.
Error 3 and 5 are because ID3DXFont doesn't have Begin() and End() methods any more, instead it takes an option ID3DXSprite parameter which you can call Begin() and End() on
Error 4 is because ID3DXFont::DrawText() has changed.

Share this post


Link to post
Share on other sites
I made my Visual Studio use the SDK from the one used in the book and getting these errors from another piece of code:

Error 1 error C2440: '=' : cannot convert from 'const char [11]' to 'LPCWSTR' c:\users\david\documents\visual studio 2008\projects\baseframework\baseframework\winmain.cpp 107 BaseFramework
Error 2 error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWSTR' c:\users\david\documents\visual studio 2008\projects\baseframework\baseframework\winmain.cpp 119 BaseFramework
Error 3 error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR' c:\users\david\documents\visual studio 2008\projects\baseframework\baseframework\winmain.cpp 130 BaseFramework
Error 4 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [2048]' to 'LPCWSTR' c:\users\david\documents\visual studio 2008\projects\baseframework\baseframework\winmain.cpp 161 BaseFramework

I have been able to get some of the source code to work with both VS 2008 and VS 2010.

Also here is the code thats generating those errors:

// Include files
#include <Windows.h>
#include <stdio.h>
#include <stdarg.h>

// Main application instances
HINSTANCE g_hInst; // Global instance handle
HWND g_hWnd; // Global window handle

// Application window dimensions, type, class, and window name
#define WNDWIDTH 400
#define WNDHEIGHT 400
#define WNDTYPE WS_OVERLAPPEDWINDOW
const char g_szClass[] = "FrameClass";
const char g_szCaption[] = "FrameCaption";

// Main application prototypes

// Entry point
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
LPSTR szCmdLine, int nCmdShow);

// Function to display an error message
void AppError(BOOL Fatal, char *Text, ...);

// Message Procedure
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);

// Functions to register and unregister windows' classes
BOOL RegisterWindowClasses(HINSTANCE hInst);
BOOL UnregisterWindowClasses(HINSTANCE hInst);

// Function to create the application window
HWND CreateMainWindow(HINSTANCE hInst);

// Functions to init, shutdown, and handle per-frame functions
BOOL DoInit();
BOOL DoShutdown();
BOOL DoPreFrame();
BOOL DoFrame();
BOOL DoPostFrame();

int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
LPSTR szCmdLine, int nCmdShow)
{
MSG Msg;

// Save application instance
g_hInst = hInst;

// Register window classes - return on FALSE
if((g_hWnd = CreateMainWindow(hInst)) == NULL)
return FALSE;

// Do application initialization - return on FALSE
if(DoInit() == TRUE) {

// Enter the message pump
ZeroMemory(&Msg, sizeof(MSG));
while(Msg.message != WM_QUIT) {
// Handle Windows messages (if any)
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
} else {

// Do pre-frame processing, break on FALSE return value
if(DoPreFrame() == FALSE)
break;

// Do per-frame proccessing, break on FALSE return value
if(DoFrame() == FALSE)
break;

// Do post-frame proccessing, break on FALSE return value
if(DoPostFrame() == FALSE)
break;
}
}
}

// Do shutdown functions
DoShutdown();

// Unregister window
UnregisterWindowClasses(hInst);

return TRUE;
}

BOOL RegisterWindowClasses(HINSTANCE hInst)
{
WNDCLASSEX wcex;

// Create the window class here and register it
wcex.cbSize = sizeof(wcex);
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName =NULL;
wcex.lpszClassName = g_szClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wcex))
return FALSE;

return TRUE;
}

BOOL UnregisterWindowClasses(HINSTANCE hInst)
{
// Unregister the window class
UnregisterClass(g_szClass, hInst);
return TRUE;
}

HWND CreateMainWindow(HINSTANCE hInst)
{
HWND hWnd;

// Create the Main Window
hWnd = CreateWindow(g_szClass, g_szCaption,
WNDTYPE, 0, 0, WNDWIDTH, WNDHEIGHT,
NULL, NULL, hInst, NULL);
if(!hWnd)
return NULL;

// Show and update the window
ShowWindow(hWnd, SW_NORMAL);
UpdateWindow(hWnd);

// Return the window handle
return hWnd;
}

void AppError(BOOL Fatal, char *Text, ...)
{
char CaptionText[12];
char ErrorText[2048];
va_list valist;

// Build the message box caption based on fatal flag
if(Fatal == FALSE)
strcpy(CaptionText, "Error");
else
strcpy(CaptionText, "Fatal Error");

// Build variable text buffer
va_start(valist, Text);
vsprintf(ErrorText, Text, valist);
va_end(valist);

// Display the message box
MessageBox(NULL, ErrorText, CaptionText,
MB_OK | MB_ICONEXCLAMATION);


// Post a quit message if error was fatal
if(Fatal == TRUE)
PostQuitMessage(0);
}

// The message procedure - empty except for destroy message
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

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

BOOL DoInit()
{
// Peform application initialization functions here
// such as those that set up the graphics, sound, network, etc.
// Return a vlaue of TRUE for success, FALSE otherwise.
return TRUE;
}

BOOL DoShutdown()
{
// Perform application shutdown functions here
// such as those that shut down the graphics, sound etc.
// Return a value of TRUE for success, FALSE otherwise.
return TRUE;
}

BOOL DoPreFrame()
{
// Perform pre-frame processing, such as setting up a timer.
// Return TRUE on success, FALSE otherwise.
return TRUE;
}

BOOL DoFrame()
{
// Perform per-frame processing, such as rendering.
// Return TRUE on success, FALSE otherwise.
return TRUE;
}

BOOL DoPostFrame()
{
// Perform post-frame processing, such as time synching, etc.
// Return TRUE on success, FALSE otherwise.
return TRUE;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!