Original Post
Hi everyone. I feel like granting my computer flight *kicks out the window* Anyway I'm having a problem. For some stupid reason my program won't let me use any of my library functions that are Direct X. For example my major one. I can lock the surface(primary)using the following code in the main .cpp file:
if (FAILED(lpddsprimary->Lock(NULL, &ddsd,
DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
NULL)))
{
// error
return(0);
} // end if
But that's in the Game_Main function. Now if I put the code above in a function and put in a .h file it won't plot the pixels on the screen. It just stays black. Here's the source:
.h file with function
int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
SendMessage(main_window_handle,WM_CLOSE,0,0);
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if (FAILED(lpddsprimary->Lock(NULL, &ddsd,
DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
NULL)))
{
// error
return(0);
} // end if
// now ddsd.lPitch is valid and so is ddsd.lpSurface
// make a couple aliases to make code cleaner, so we don't
// have to cast
int mempitch = (int)ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;
// plot 1000 random pixels with random colors on the
// primary surface, they will be instantly visible
for (int index=0; index < 1000; index++)
{
// select random position and color for 640x480x8
UCHAR color = rand()%256;
int x = rand()%SCREEN_WIDTH;
int y = rand()%SCREEN_HEIGHT;
int x2 = rand()%700;
int y2 = rand()%700;
Plot8(x2, y2, color, (UCHAR *)ddsd.lpSurface, (int)ddsd.lPitch);
Plot16(x, y, color, color, color, (USHORT *)ddsd.lpSurface, (int)ddsd.lPitch);
} // end for index
// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
// sleep a bit
Sleep(30);
// return success or failure or your own return code here
return(1);
} // end Game_Main
And this is the way I want it:
int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
SendMessage(main_window_handle,WM_CLOSE,0,0);
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
locklp(lpddsprimary, ddsd);
// now ddsd.lPitch is valid and so is ddsd.lpSurface
// make a couple aliases to make code cleaner, so we don't
// have to cast
int mempitch = (int)ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;
// plot 1000 random pixels with random colors on the
// primary surface, they will be instantly visible
for (int index=0; index < 1000; index++)
{
// select random position and color for 640x480x8
UCHAR color = rand()%256;
int x = rand()%SCREEN_WIDTH;
int y = rand()%SCREEN_HEIGHT;
int x2 = rand()%700;
int y2 = rand()%700;
Plot8(x2, y2, color, (UCHAR *)ddsd.lpSurface, (int)ddsd.lPitch);
Plot16(x, y, color, color, color, (USHORT *)ddsd.lpSurface, (int)ddsd.lPitch);
} // end for index
// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
// sleep a bit
Sleep(30);
// return success or failure or your own return code here
return(1);
} // end Game_Main
Wh ycan't I use my own built in function? Thanks for your time. Oh yes and I have included the ".h" file btw.
[edited by - demonrealms on January 9, 2004 5:52:04 PM]