A little directx help please?
Ive been learning dx from LaMothe''s "Tricks" book but Ive had a lot of problems with some of his code so Im taking the stuff I need and putting it my own file and using that instead. One of his functions creates a directx surface like this
int DDraw_Init(int width, int height, int bpp)
{
// this function initializes directdraw
int index; // looping variable
LPDIRECTDRAW lpdd_temp = NULL; // used to get directdraw1
// create IDirectDrawdirectdraw interface 1.0 object and test for error
if (FAILED(DirectDrawCreate(NULL,&lpdd_temp,NULL)))
return(0);
// now query for IDirectDraw4
if (FAILED(lpdd_temp->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd)))
return(0);
// set cooperation level to requested mode
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return(0);
// set the display mode
if (FAILED(lpdd_temp->SetDisplayMode(width,height,bpp,0,0)))
return(0);
here I get an error, SetDisplayMode does not take 5 parameters
so I changed the code to this
int DDraw_Init(int width, int height, int bpp)
{
// this function initializes directdraw
int index; // looping variable
LPDIRECTDRAW4 lpdd4 = NULL;
// create IDirectDrawdirectdraw interface 1.0 object and test for error
if (FAILED(DirectDrawCreate(NULL,&lpdd_temp,NULL)))
return(0);
// now query for IDirectDraw4
if (FAILED(lpdd->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd4)))
return(0);
// set cooperation level to requested mode
if (FAILED(lpdd4->SetCooperativeLevel(main_window_handle,
DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return(0);
// set the display mode
if (FAILED(lpdd4->SetDisplayMode(width,height,bpp,0,0)))
return(0);
no problems up to here now, I complie the file fine, but when I build I get
Animal.obj : error LNK2001: unresolved external symbol "struct IDirectDraw4 * lpdd4" (?lpdd4@@3PAUIDirectDraw4@@A)
Debug/Animal.exe : fatal error LNK1120: 1 unresolved externals
before I added this function I didnt get a linking error with any of the other functions I put in so Im sure my includes are right and Ive included the right libraries, dxguid, ddraw, winmm, etc. Im not too familiar with directx so this hard for me to figure out. If anyone could offer some advice Id be very appreciative. The entire function before my changes is below. Thanks
int DDraw_Init(int width, int height, int bpp)
{
// this function initializes directdraw
int index; // looping variable
LPDIRECTDRAW lpdd_temp = NULL; // used to get directdraw1
// create IDirectDrawdirectdraw interface 1.0 object and test for error
if (FAILED(DirectDrawCreate(NULL,&lpdd_temp,NULL)))
return(0);
// now query for IDirectDraw4
if (FAILED(lpdd_temp->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd)))
return(0);
// set cooperation level to requested mode
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return(0);
// set the display mode
if (FAILED(lpdd->SetDisplayMode(width,height,bpp,0,0)))
return(0);
// set globals
screen_height = height;
screen_width = width;
screen_bpp = bpp;
// Create the primary surface
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
// we need to let dd know that we want a complex
// flippable surface structure, set flags for that
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
// set the backbuffer count to 1, 2 for triple buffering
ddsd.dwBackBufferCount = 1;
// create the primary surface
lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);
// query for the backbuffer i.e the secondary surface
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if (FAILED(lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback)))
return(0);
// create and attach palette
// create palette data
// clear all entries defensive programming
memset(palette,0,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY));
// create a R,G,B,GR gradient palette
for (index=0; index < MAX_COLORS_PALETTE; index++)
{
// set each entry
if (index < 64)
palette[index].peRed = index*4;
else // shades of green
if (index >= 64 && index < 128)
palette[index].peGreen = (index-64)*4;
else // shades of blue
if (index >= 128 && index < 192)
palette[index].peBlue = (index-128)*4;
else // shades of grey
if (index >= 192 && index < 256)
palette[index].peRed = palette[index].peGreen =
palette[index].peBlue = (index-192)*4;
// set flag to force directdraw to leave alone
palette[index].peFlags = PC_NOCOLLAPSE;
} // end for index
// now create the palette object
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_INITIALIZE | DDPCAPS_ALLOW256,
palette,&lpddpal,NULL)))
return(0);
// attach the palette to the primary
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
return(0);
// clear out both primary and secondary surfaces
DDraw_Fill_Surface(lpddsprimary,0);
DDraw_Fill_Surface(lpddsback,0);
// return success
return(1);
} // end DDraw_Init
///////////////////////////////////////////////////////////
Dunno if this will work-but I had a similar problem and it fixed it. If you have MS VC++ do this:
Click Tools, Options,Directories Tab, & then move the DX7 or 6 directory to the top of the list. I dunno how to this in Borland-Hope this helps!
Click Tools, Options,Directories Tab, & then move the DX7 or 6 directory to the top of the list. I dunno how to this in Borland-Hope this helps!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement