From: hicks16 on
I am trying to turn my current C++ easy game to a bitmap game using
DirectX SDK august 2009. I get everything to come out good but I have
1 error and I can't figure it out. I was told to come here for help. I
will post the error. Also not that I put in #pragma comment (lib,
"d3d9.lib"). so I got rid of one of 2 erros now I am just left with
this:

error LNK2019: unresolved external symbol _D3DXLoadSurfaceFromFileA(a)32
referenced in function "int __cdecl Game_Init(struct HWND__ *)" (?
Game_Init@@YAHPAUHWND__@@@Z)
From: Nathan Mates on
In article <2ee70065-ab6b-4c4f-863f-4264ed54ac20(a)l9g2000yqi.googlegroups.com>,
hicks16 <hickorynut(a)live.com> wrote:
>I am trying to turn my current C++ easy game to a bitmap game using
>DirectX SDK august 2009. I get everything to come out good but I have
>1 error and I can't figure it out. I was told to come here for help.

I don't like #pragmas to pull in libraries. Instead, I prefer to
explicitly list them on the linker's set of input libraries. I
recommend you look at an existing DirectX sample app, and copy its
list of input libraries. For reference, a program I've written has
these entries as part of its linker inputs:

Debug:
d3dxof.lib dxguid.lib d3dx9d.lib d3d9.lib DxErr.lib
Release:
d3dxof.lib dxguid.lib d3dx9.lib d3d9.lib DxErr.lib

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
From: hicks16 on
On Sep 11, 6:16 pm, nat...(a)visi.com (Nathan Mates) wrote:
> In article <2ee70065-ab6b-4c4f-863f-4264ed54a...(a)l9g2000yqi.googlegroups.com>,
>
> hicks16  <hickory...(a)live.com> wrote:
> >I am trying to turn my current C++ easy game to a bitmap game using
> >DirectX SDK august 2009. I get everything to come out good but I have
> >1 error and I can't figure it out. I was told to come here for help.
>
>    I don't like #pragmas to pull in libraries. Instead, I prefer to
> explicitly list them on the linker's set of input libraries. I
> recommend you look at an existing DirectX sample app, and copy its
> list of input libraries. For reference, a program I've written has
> these entries as part of its linker inputs:
>
> Debug:
> d3dxof.lib dxguid.lib d3dx9d.lib d3d9.lib DxErr.lib
> Release:
> d3dxof.lib dxguid.lib d3dx9.lib d3d9.lib DxErr.lib
>
> Nathan Mates
> --
> <*> Nathan Mates - personal webpagehttp://www.visi.com/~nathan/ 
> # Programmer at Pandemic Studios --http://www.pandemicstudios.com/
> # NOT speaking for Pandemic Studios. "Care not what the neighbors
> # think. What are the facts, and to how many decimal places?" -R.A. Heinlein

I am very new to DirectX SDK so I don't know what you mean by

> Debug:
> d3dxof.lib dxguid.lib d3dx9d.lib d3d9.lib DxErr.lib
> Release:
> d3dxof.lib dxguid.lib d3dx9.lib d3d9.lib DxErr.lib

like how do I put that into my program? or how do I fix this error I
am getting without using the #pragmas? This a for fun program and my
second thing I have made with the SDK so it is still very new to me.
From: hicks16 on
On Sep 11, 6:24 pm, hicks16 <hickory...(a)live.com> wrote:
> On Sep 11, 6:16 pm, nat...(a)visi.com (Nathan Mates) wrote:
>
>
>
> > In article <2ee70065-ab6b-4c4f-863f-4264ed54a...(a)l9g2000yqi.googlegroups.com>,
>
> > hicks16  <hickory...(a)live.com> wrote:
> > >I am trying to turn my current C++ easy game to a bitmap game using
> > >DirectX SDK august 2009. I get everything to come out good but I have
> > >1 error and I can't figure it out. I was told to come here for help.
>
> >    I don't like #pragmas to pull in libraries. Instead, I prefer to
> > explicitly list them on the linker's set of input libraries. I
> > recommend you look at an existing DirectX sample app, and copy its
> > list of input libraries. For reference, a program I've written has
> > these entries as part of its linker inputs:
>
> > Debug:
> > d3dxof.lib dxguid.lib d3dx9d.lib d3d9.lib DxErr.lib
> > Release:
> > d3dxof.lib dxguid.lib d3dx9.lib d3d9.lib DxErr.lib
>
> > Nathan Mates
> > --
> > <*> Nathan Mates - personal webpagehttp://www.visi.com/~nathan/ 
> > # Programmer at Pandemic Studios --http://www.pandemicstudios.com/
> > # NOT speaking for Pandemic Studios. "Care not what the neighbors
> > # think. What are the facts, and to how many decimal places?" -R.A. Heinlein
>
> I am very new to DirectX SDK so I don't know what you mean by
>
> > Debug:
> > d3dxof.lib dxguid.lib d3dx9d.lib d3d9.lib DxErr.lib
> > Release:
> > d3dxof.lib dxguid.lib d3dx9.lib d3d9.lib DxErr.lib
>
> like how do I put that into my program? or how do I fix this error I
> am getting without using the #pragmas? This a for fun program and my
> second thing I have made with the SDK so it is still very new to me.

Here is my program if it helps:
[code]
// Load_Bitmap program

//header files to include
#include <d3d9.h>
#include <d3dx9.h>
#include <time.h>
#include <math.h>

//application title
#define APPTITLE "Create_Surface"

//macros to read the keyboard asynchronously
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 :
0)
#define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

//screen resolution
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

//forward declarations
LRESULT WINAPI WinProc(HWND,UINT,WPARAM,LPARAM);
ATOM MyRegisterClass(HINSTANCE);
int Game_Init(HWND);
void Game_Run(HWND);
void Game_End(HWND);

//Direct3D objects
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;

LPDIRECT3DSURFACE9 backbuffer = NULL;
LPDIRECT3DSURFACE9 surface = NULL;
LPDIRECT3DSURFACE9 player = NULL;
LPDIRECT3DSURFACE9 dead = NULL;

//game definitions
#define N 0
#define NE 1
#define E 2
#define SE 3
#define S 4
#define SW 5
#define W 6
#define NW 7
#define NDIR 8
#define OPEN 1
#define BLOCKED 0
#define WALL -2
#define ME 2
#define TARGET 3
#define DEAD -10

void clearGrid(int[][100],int,int);//gird,maxX,maxY
void blockBorders(int[][100],int,int);//grid[][],maxX,maxY
float getDistance(int,int,int,int);//x1,y1,x2,y2
void calPath(int [][100],int,int,int&,int&,int,int);
static int PATH[1000];
static int nSteps;
int maxX = 7;
int maxY = 7;
int grid[100][100];
int atX = 1;
int atY = 1;
int targetX = 7;
int targetY = 5;
int maxSteps = 24;

//window event callback function
LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
lParam )
{
switch( msg )
{
case WM_DESTROY:
Game_End(hWnd);
PostQuitMessage(0);
return 0;
}

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


//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
//create the window class structure
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);

//fill the struct with info
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIconSm = NULL;

//set up the window with the class info
return RegisterClassEx(&wc);
}


//entry point for a Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// declare variables
MSG msg;

// register the class
MyRegisterClass(hInstance);

// initialize application
//note--got rid of initinstance
HWND hWnd;

//create a new window
hWnd = CreateWindow(
APPTITLE, //window class
APPTITLE, //title bar
WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP, //window style
CW_USEDEFAULT, //x position of window
CW_USEDEFAULT, //y position of window
SCREEN_WIDTH, //width of the window
SCREEN_HEIGHT, //height of the window
NULL, //parent window
NULL, //menu
hInstance, //application instance
NULL); //window parameters

//was there an error creating the window?
if (!hWnd)
return FALSE;

//display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

//initialize the game
if (!Game_Init(hWnd))
return 0;


// main message loop
int done = 0;
while (!done)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
//look for quit message
if (msg.message == WM_QUIT)
done = 1;

//decode and pass messages on to WndProc
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
//process game loop (else prevents running after window is
closed)
Game_Run(hWnd);
}

return msg.wParam;
}


int Game_Init(HWND hwnd)
{
HRESULT result;

//initialize Direct3D
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (d3d == NULL)
{
MessageBox(hwnd, "jmk 1Error initializing Direct3D", "Error",
MB_OK);
return 0;
}

//set Direct3D presentation parameters
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));

d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.hDeviceWindow = hwnd;

//create Direct3D device
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);

if (d3ddev == NULL)
{
MessageBox(hwnd, "Error 17 creating Direct3D device", "Error",
MB_OK);
//return 0;
}

//set random number seed
srand(time(NULL));

//clear the backbuffer to black
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0),
1.0f, 0);

//create surface
result = d3ddev->CreateOffscreenPlainSurface(
638, //width of the surface
458, //height of the surface
D3DFMT_X8R8G8B8, //surface format
D3DPOOL_DEFAULT, //memory pool to use
&surface, //pointer to the surface
NULL); //reserved (always NULL)

if (result != D3D_OK)
return 1;

//load surface from file into newly created surface
result = D3DXLoadSurfaceFromFile(
surface, //destination surface
NULL, //destination palette
NULL, //destination rectangle
"pathmap.bmp", //source filename
NULL, //source rectangle
D3DX_DEFAULT, //controls how image is filtered
0, //for transparency (0 for none)
NULL); //source image info (usually NULL)

//make sure file was loaded okay
if (result != D3D_OK)
return 1;

//create player surface
result = d3ddev->CreateOffscreenPlainSurface(
70, //width of the surface
50, //height of the surface
D3DFMT_X8R8G8B8, //surface format
D3DPOOL_DEFAULT, //memory pool to use
&player, //pointer to the surface
NULL); //reserved (always NULL)

if (result != D3D_OK)
return 1;

//load surface from file into newly created surface
result = D3DXLoadSurfaceFromFile(
player, //destination surface
NULL, //destination palette
NULL, //destination rectangle
"necro.bmp", //source filename
NULL, //source rectangle
D3DX_DEFAULT, //controls how image is filtered
0, //for transparency (0 for none)
NULL); //source image info (usually NULL)

//make sure file was loaded okay
if (result != D3D_OK)
return 1;

//create dead surface
result = d3ddev->CreateOffscreenPlainSurface(
70, //width of the surface
50, //height of the surface
D3DFMT_X8R8G8B8, //surface format
D3DPOOL_DEFAULT, //memory pool to use
&dead, //pointer to the surface
NULL); //reserved (always NULL)

if (result != D3D_OK)
return 1;

//load surface from file into newly created surface
result = D3DXLoadSurfaceFromFile(
dead, //destination surface
NULL, //destination palette
NULL, //destination rectangle
"dead.bmp", //source filename
NULL, //source rectangle
D3DX_DEFAULT, //controls how image is filtered
0, //for transparency (0 for none)
NULL); //source image info (usually NULL)

//make sure file was loaded okay
if (result != D3D_OK)
return 1;

//initialize board
maxX+=2;//adjust for border
maxY+=2;//adjust for border
clearGrid(grid,maxX,maxY);
blockBorders(grid,maxX,maxY);//set border spaces as blocked
grid[atY][atX] = ME;
grid[targetY][targetX] = TARGET;
grid[3][5] = WALL;
grid[4][5] = WALL;
grid[5][5] = WALL;
grid[6][5] = WALL;
grid[6][4] = WALL;
grid[6][3] = WALL;
grid[2][2] = WALL;
grid[3][6] = WALL;
grid[4][7] = WALL;

//return okay
return 1;
}

void Game_Run(HWND hwnd)
{ RECT rect;

//make sure the Direct3D device is valid
if (d3ddev == NULL)
return;

//start rendering
if (d3ddev->BeginScene())
{
//create pointer to the back buffer
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO,
&backbuffer);

//draw surface to the backbuffer
d3ddev->StretchRect(surface, NULL, backbuffer, NULL,
D3DTEXF_NONE);

//locate and draw player
rect.left = atX*70 + atX;
rect.right = rect.left + 70;
rect.top = atY*50 + atY*4;
rect.bottom = rect.top + 50;
d3ddev->StretchRect(player,NULL,backbuffer,&rect,D3DTEXF_NONE);

//locate and draw dead spots
for(int r = 1;r < maxX;r++)
{ for(int c = 1;c < maxY;c++)
{ if(grid[c][r] == DEAD)
{ rect.left = r*70+r;
rect.right = rect.left + 70;
rect.top = c*50 + c*4;
rect.bottom = rect.top + 50;
d3ddev->StretchRect(dead,NULL,backbuffer,&rect,D3DTEXF_NONE);
}
}
}

//stop rendering
d3ddev->EndScene();
}

//display the back buffer on the screen
d3ddev->Present(NULL, NULL, NULL, NULL);

//if player isn't at target find next space to move to
if(!(atX == targetX && atY == targetY))
{ calPath(grid,maxX,maxY,atX,atY,targetX,targetY);
nSteps++;
}

//check for escape key (to exit program)
if (KEY_DOWN(VK_ESCAPE))
PostMessage(hwnd, WM_DESTROY, 0, 0);
Sleep(150);
}

void Game_End(HWND hwnd)
{
//free the surface
surface->Release();
player->Release();

//release the Direct3D device
if (d3ddev != NULL)
d3ddev->Release();

//release the Direct3D object
if (d3d != NULL)
d3d->Release();
}

void blockBorders(int x[][100],int nC,int nR)
{
for(int c = 0; c < nC;c++)
{ x[0][c] = BLOCKED;
x[nR-1][c] = BLOCKED;
}
for(int r = 1; r < nR;r++)
{
x[r][0] = BLOCKED;
x[r][nC - 1] = BLOCKED;
}
return;
}

float getDistance(int x1,int y1,int x2,int y2)
{
return sqrt(static_cast<double>((x2-x1) * (x2 - x1) + (y2 - y1) * (y2-
y1)));
}

void calPath(int x[][100],int nC,int nR,int &meX,int &meY,int tarX,int
tarY)
{
static int direction = -99;
int testX, testY, minX, minY;
float s = 1000000.;
float sTemp, sMin = 100000.;

testX = meX;
testY = meY;
minX = meX;
minY = meY;

for(int p = 0; p < NDIR; p++)
{
switch(p)
{
case N: testX = meX;
testY = meY+1;
break;
case NE: testX = meX+1;
testY = meY+1;
break;
case E: testX = meX+1;
testY = meY;
break;
case SE: testX = meX+1;
testY = meY-1;
break;
case S: testX = meX;
testY = meY-1;
break;
case SW: testX = meX-1;
testY = meY-1;
break;
case W: testX = meX-1;
testY = meY;
break;
case NW: testX = meX-1;
testY = meY+1;
break;
}//end switch
sTemp = getDistance(testX,testY,tarX,tarY);
if(sTemp < sMin && x[testY][testX] > 0)
{
sMin = sTemp;
//direction = p;
PATH[nSteps] = p;
minX = testX;
minY = testY;
}//end if
}//end for

x[meY][meX] = DEAD;
meY = minY;
meX = minX;
x[meY][meX] = ME;

//return direction;
}//end calPath

void clearGrid(int x[][100],int nC,int nR)
{ for(int r = 0; r < nR;r++)
for(int c = 0; c < nC;c++)
x[r][c] = OPEN;
return;
}//end clearGrid
[/code]
From: ScottMcP [MVP] on
On Sep 11, 6:42 pm, hicks16 <hickory...(a)live.com> wrote:
> I am trying to turn my current C++ easy game to a bitmap game using
> DirectX SDK august 2009. I get everything to come out good but I have
> 1 error and I can't figure it out. I was told to come here for help. I
> will post the error. Also not that I put in #pragma comment (lib,
> "d3d9.lib"). so I got rid of one of 2 erros now I am just left with
> this:
>
> error LNK2019: unresolved external symbol _D3DXLoadSurfaceFromFileA(a)32
> referenced in function "int __cdecl Game_Init(struct HWND__ *)" (?
> Game_Init@@YAHPAUHWND__@@@Z)

Look up the function in MSDN. It tells you on that page that you need
library file d3dx9.lib.

To link in a lib file you can either use the #pragma, or you can type
in the name of the lib in the settings:
Menu: Project, Properties, Linker, Input, Additional Dependencies =
d2dx9.lib