Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

omegasyphon

16bpp runtime problem

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

my problem is when i run my program the second after it is executed it quits and i dont know why this is doing this. my ( = greater than less then signs i dont know how to display greater then less then signs correctly // INCLUDES /////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN #define INITGUID #include () // include important windows stuff #include () #include () #include () // include important C/C++ stuff #include () #include () #include () #include () #include () // directX includes // defines for windows #define WINDOW_CLASS_NAME "WINXCLASS" // class name #define WWIDTH 640 // size of window #define WHEIGHT 480 #define BPP 16 #define BITMAP_ID 0x4D42 // universal id for a bitmap //#define MAXCOLORS 256 // MACROS ///////////////////////////////////////////////// // these read the keyboard asynchronously #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) #define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); } // this builds a 16 bit color value in 5.6.5 format (green dominate mode) #define _RGB16BIT(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11)) // TYPES ////////////////////////////////////////////////// typedef unsigned short USHORT; typedef unsigned char UCHAR; typedef struct BITMAP_FILE_TAG { BITMAPFILEHEADER bitmapfileheader; BITMAPINFOHEADER bitmapinfoheader; PALETTEENTRY palette[256]; UCHAR *buffer; } BITMAPFILE, *BITMAPFILEPTR; typedef struct BITMAPOBJTYP { int x,y; LPDIRECTDRAWSURFACE4 image; } BITMAPOBJ, *BITMAPOBJPTR; ////////// directdraw objects///////////// LPDIRECTDRAW lpdd1 = NULL; LPDIRECTDRAW4 lpdd4 = NULL; LPDIRECTDRAWSURFACE4 lpddsprimary = NULL; LPDIRECTDRAWSURFACE4 lpddsback = NULL; DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; BITMAPFILE bitmap; // GLOBALS //////////////////////////////////////////////// HWND main_window_handle = NULL; // save the window handle HINSTANCE main_instance = NULL; // save the instance char buffer[80]; // used to print text int window_closed = 0; // tracks if window is closed // PROTOTYPES ///////////////////////////////////////////// int Game_Init(void *parms=NULL, int num_parms = 0); int Game_Shutdown(void *parms=NULL, int num_parms = 0); int Game_Main(void *parms=NULL, int num_parms = 0); int loadbitmap(BITMAPFILEPTR bitmap, char *filename); int unloadbitmap(BITMAPFILEPTR bitmap); int flipbitmap(UCHAR *image, int bytes_per_line, int height); LPDIRECTDRAWSURFACE4 createsurface(int width,int height, int memflags); // FUNCTIONS ////////////////////////////////////////////// int loadbitmap(BITMAPFILEPTR bitmap, char *filename) { int filehandle,index; UCHAR *tbuffer = NULL; OFSTRUCT filedata; if ((filehandle = OpenFile(filename,&filedata,OF_READ))==-1) return 0; _lread(filehandle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER)); if (bitmap->bitmapfileheader.bfType!=BITMAP_ID) { _lclose(filehandle); return 0; } _lread(filehandle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER)); _lseek(filehandle, -(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END); if (bitmap->bitmapinfoheader.biBitCount==8 // bitmap->bitmapinfoheader.biBitCount==16) { if (bitmap->buffer) free(bitmap->buffer); if(!(bitmap->buffer=(UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage))) { _lclose(filehandle); return 0; } _lread(filehandle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage); } else { if (!(tbuffer =(UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage))) { _lclose(filehandle); return 0; } // allocate final 16 bit storage buffer if (!(bitmap->buffer=(UCHAR *)malloc(2*bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight))) { // close the file _lclose(filehandle); // release working buffer free(tbuffer); // return error return(0); } // end if _lread(filehandle,tbuffer,bitmap->bitmapinfoheader.biSizeImage); for (index=0;indexbitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++) { UCHAR blue = (tbuffer[index*3+0] >>3), green = (tbuffer[index*3+1] >>3), red = (tbuffer[index*3+2] >>3); USHORT color = _RGB16BIT(red,green,blue); ((USHORT *)bitmap->buffer)[index] = color; } bitmap->bitmapinfoheader.biBitCount=16; } _lclose(filehandle); flipbitmap(bitmap->buffer,bitmap->bitmapinfoheader.biWidth* (bitmap->bitmapinfoheader.biBitCount/8), bitmap->bitmapinfoheader.biHeight); return 1; } int unloadbitmap(BITMAPFILEPTR bitmap) { if (bitmap->buffer) { free(bitmap->buffer); bitmap->buffer= NULL; } return 1; } int flipbitmap(UCHAR *image, int bytes_per_line, int height) { // this function is used to flip bottom-up .BMP images UCHAR *buffer; // used to perform the image processing int index; // looping index // allocate the temporary buffer if (!(buffer = (UCHAR *)malloc(bytes_per_line*height))) return(0); // copy image to work area memcpy(buffer,image,bytes_per_line*height); // flip vertically for (index=0; index < height; index++) memcpy(&image[((height-1) - index)*bytes_per_line], &buffer[index*bytes_per_line], bytes_per_line); // release the memory free(buffer); // return success return(1); } // end Flip_Bitmap LPDIRECTDRAWSURFACE4 createsurface(int width,int height, int memflags) { DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE4 lpdds; DDRAW_INIT_STRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_WIDTH / DDSD_HEIGHT; ddsd.dwWidth = width; ddsd.dwHeight = height; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN / memflags; if (FAILED(lpdd4->CreateSurface(&ddsd,&lpdds,NULL))) return (NULL); DDCOLORKEY colorkey; colorkey.dwColorSpaceLowValue = _RGB16BIT(0,0,0); colorkey.dwColorSpaceHighValue = _RGB16BIT(0,0,0); lpdds->SetColorKey(DDCKEY_SRCBLT, &colorkey); return (lpdds); } LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // this is the main message handler of the system PAINTSTRUCT ps; // used in WM_PAINT HDC hdc; // handle to a device context // what is the message switch(msg) { case WM_CREATE: { // do initialization stuff here return(0); } break; case WM_PAINT: { // start painting hdc = BeginPaint(hwnd,&ps); // end painting EndPaint(hwnd,&ps); return(0); } break; case WM_DESTROY: { // kill the application PostQuitMessage(0); return(0); } break; default:break; } // end switch // process any messages that we didn''t take care of return (DefWindowProc(hwnd, msg, wparam, lparam)); } // end WinProc // WINMAIN //////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message HDC hdc; // generic dc PAINTSTRUCT ps; // generic paintstruct // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS / CS_OWNDC / CS_HREDRAW / CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(NULL,WINDOW_CLASS_NAME, // class "WinX Game Console", // title WS_POPUP / WS_VISIBLE, 0,0, // x,y WWIDTH, // width WHEIGHT, // height NULL, // handle to parent NULL, // handle to menu hinstance,// instance NULL))) // creation parms return(0); // save the window handle and instance in a global main_window_handle = hwnd; main_instance = hinstance; // perform all game console specific initialization Game_Init(); // enter main event loop while(1) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here Game_Main(); } // end while // shutdown game and release all resources Game_Shutdown(); // return to Windows like this return(msg.wParam); } // end WinMain // WINX GAME PROGRAMMING CONSOLE FUNCTIONS //////////////// int Game_Init(void *parms, int num_parms) { // first create base IDirectDraw interface if (FAILED(DirectDrawCreate(NULL, &lpdd1, NULL))) return(0); // now query for IDirectDraw4 if (FAILED(lpdd1->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4))) return(0); // set cooperation to full screen if (FAILED(lpdd4->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN / DDSCL_ALLOWMODEX / DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT))) return(0); // set display mode if (FAILED(lpdd4->SetDisplayMode(WWIDTH,WHEIGHT,BPP,0,0))) return(0); DDRAW_INIT_STRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.dwBackBufferCount=1; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; //create primary surface if (FAILED(lpdd4->CreateSurface(&ddsd, &lpddsprimary, NULL))) return 0; if (!loadbitmap(&bitmap,"ground2.bmp")) return 0; // lock the primary surface lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR / DDLOCK_WAIT,NULL); // get video pointer to primary surfce USHORT *primary_buffer = (USHORT *)ddsd.lpSurface; // process each line and copy it into the primary buffer for (int y = 0; y < WHEIGHT; y++) { memcpy(&primary_buffer[y*ddsd.lPitch >>1], &bitmap.buffer[y*WWIDTH*2], WWIDTH*2); } // end for index_y // now unlock the primary surface if (FAILED(lpddsprimary->Unlock(NULL))) return(0); // unload the bitmap file, we no longer need it unloadbitmap(&bitmap); // return success or failure or your own return code here return 1; } // end Game_Init /////////////////////////////////////////////////////////// int Game_Main(void *parms, int num_parms) { // make sure this isn''t executed again if (window_closed) return(0); // for now test if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) { PostMessage(main_window_handle,WM_CLOSE,0,0); window_closed = 1; } // end if return 1; } // end Game_Main /////////////////////////////////////////////////////////// int Game_Shutdown(void *parms, int num_parms) { // now the primary surface if (lpddsprimary) { lpddsprimary->Release(); lpddsprimary = NULL; } // end if // release the directdraw object if (lpdd4!=NULL) lpdd4->Release(); return 1; } // end Game_Shutdown

Share this post


Link to post
Share on other sites
Advertisement
Maybe your graphics card doesn''t support 16bpp colour depth? I had this problem with 32bpp, although 24bpp worked just fine.

Try putting in some code just after you set the display mode. You are already using if(FAILED(..., so maybe put in a MessageBox before the return(0). (and don''t forget to enclode the code in {}''s, as there is now more than 1 line after the if statement ;->)

Alternatively, if you''re using VC++ you can drop in some breakpoints and step through the code to see exactly where it falls over.

It looks like you''re working from ''Tricks of the Windows Game Proramming Gurus'', and I think there''s a section in there covering how to determine what your graphics card can handle.

If it turns out that you can''t use 16bpp, well good ;-> I would always recommend 8bpp for speed or 32bpp for quality (and better speed on the latest hardware).

Share this post


Link to post
Share on other sites
quote:
Original post by omegasyphon
my ( = greater than less then signs
i dont know how to display greater then less then signs correctly


Here is how to do this:
I thought it would work. Does anyone know why the #defines and #includes aren't formatted correctly? Oh well, I hope it's made your code a little clearer to read.
            
// INCLUDES ///////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN
#define INITGUID
#include <windows.h> // include important windows stuff
#include <windowsx.h>
#include <mmsystem.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <malloc.h>
#include <memory.h>
#include <io.h>
#include <ddraw.h> // directX includes


// defines for windows

#define WINDOW_CLASS_NAME "WINXCLASS" // class name


#define WWIDTH 640 // size of window
#define WHEIGHT 480
#define BPP 16
#define BITMAP_ID 0x4D42 // universal id for a bitmap
//#define MAXCOLORS 256
// MACROS /////////////////////////////////////////////////


// these read the keyboard asynchronously

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }
// this builds a 16 bit color value in 5.6.5 format (green dominate mode)
#define _RGB16BIT(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))


// TYPES //////////////////////////////////////////////////


typedef unsigned short USHORT;
typedef unsigned char UCHAR;

typedef struct BITMAP_FILE_TAG
{
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
PALETTEENTRY palette[256];
UCHAR *buffer;
} BITMAPFILE, *BITMAPFILEPTR;

typedef struct BITMAPOBJTYP
{
int x,y;
LPDIRECTDRAWSURFACE4 image;
} BITMAPOBJ, *BITMAPOBJPTR;



////////// directdraw objects/////////////

LPDIRECTDRAW lpdd1 = NULL;
LPDIRECTDRAW4 lpdd4 = NULL;
LPDIRECTDRAWSURFACE4 lpddsprimary = NULL;
LPDIRECTDRAWSURFACE4 lpddsback = NULL;
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;
BITMAPFILE bitmap;

// GLOBALS ////////////////////////////////////////////////


HWND main_window_handle = NULL; // save the window handle

HINSTANCE main_instance = NULL; // save the instance

char buffer[80]; // used to print text

int window_closed = 0; // tracks if window is closed



// PROTOTYPES /////////////////////////////////////////////


int Game_Init(void *parms=NULL, int num_parms = 0);
int Game_Shutdown(void *parms=NULL, int num_parms = 0);
int Game_Main(void *parms=NULL, int num_parms = 0);
int loadbitmap(BITMAPFILEPTR bitmap, char *filename);
int unloadbitmap(BITMAPFILEPTR bitmap);
int flipbitmap(UCHAR *image, int bytes_per_line, int height);
LPDIRECTDRAWSURFACE4 createsurface(int width,int height, int memflags);

// FUNCTIONS //////////////////////////////////////////////

int loadbitmap(BITMAPFILEPTR bitmap, char *filename)
{
int filehandle,index;
UCHAR *tbuffer = NULL;
OFSTRUCT filedata;
if ((filehandle = OpenFile(filename,&filedata,OF_READ))==-1)
return 0;
_lread(filehandle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));
if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
{
_lclose(filehandle);
return 0;
}
_lread(filehandle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));

_lseek(filehandle, -(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);
if (bitmap->bitmapinfoheader.biBitCount==8 // bitmap->bitmapinfoheader.biBitCount==16)
{
if (bitmap->buffer)
free(bitmap->buffer);
if(!(bitmap->buffer=(UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
_lclose(filehandle);
return 0;
}
_lread(filehandle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage);
}
else
{
if (!(tbuffer =(UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
_lclose(filehandle);
return 0;
}
// allocate final 16 bit storage buffer

if (!(bitmap->buffer=(UCHAR *)malloc(2*bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight)))
{
// close the file

_lclose(filehandle);

// release working buffer

free(tbuffer);

// return error

return(0);
} // end if

_lread(filehandle,tbuffer,bitmap->bitmapinfoheader.biSizeImage);
for (index=0;index<bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
{
UCHAR blue = (tbuffer[index*3+0] >>3),
green = (tbuffer[index*3+1] >>3),
red = (tbuffer[index*3+2] >>3);
USHORT color = _RGB16BIT(red,green,blue);
((USHORT *)bitmap->buffer)[index] = color;
}
bitmap->bitmapinfoheader.biBitCount=16;
}
_lclose(filehandle);
flipbitmap(bitmap->buffer,bitmap->bitmapinfoheader.biWidth*
(bitmap->bitmapinfoheader.biBitCount/8),
bitmap->bitmapinfoheader.biHeight);
return 1;
}


int unloadbitmap(BITMAPFILEPTR bitmap)
{
if (bitmap->buffer)
{
free(bitmap->buffer);
bitmap->buffer= NULL;
}
return 1;
}


int flipbitmap(UCHAR *image, int bytes_per_line, int height)
{
// this function is used to flip bottom-up .BMP images


UCHAR *buffer; // used to perform the image processing

int index; // looping index


// allocate the temporary buffer

if (!(buffer = (UCHAR *)malloc(bytes_per_line*height)))
return(0);

// copy image to work area

memcpy(buffer,image,bytes_per_line*height);

// flip vertically

for (index=0; index < height; index++)
memcpy(&image[((height-1) - index)*bytes_per_line],
&buffer[index*bytes_per_line], bytes_per_line);

// release the memory

free(buffer);

// return success

return(1);

} // end Flip_Bitmap


LPDIRECTDRAWSURFACE4 createsurface(int width,int height, int memflags)
{
DDSURFACEDESC2 ddsd;
LPDIRECTDRAWSURFACE4 lpdds;
DDRAW_INIT_STRUCT(ddsd);

ddsd.dwFlags = DDSD_CAPS / DDSD_WIDTH / DDSD_HEIGHT;

ddsd.dwWidth = width;
ddsd.dwHeight = height;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN / memflags;
if (FAILED(lpdd4->CreateSurface(&ddsd,&lpdds,NULL)))
return (NULL);
DDCOLORKEY colorkey;
colorkey.dwColorSpaceLowValue = _RGB16BIT(0,0,0);
colorkey.dwColorSpaceHighValue = _RGB16BIT(0,0,0);
lpdds->SetColorKey(DDCKEY_SRCBLT, &colorkey);

return (lpdds);
}

LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system

PAINTSTRUCT ps; // used in WM_PAINT

HDC hdc; // handle to a device context


// what is the message

switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here

return(0);
} break;

case WM_PAINT:
{
// start painting

hdc = BeginPaint(hwnd,&ps);

// end painting

EndPaint(hwnd,&ps);
return(0);
} break;

case WM_DESTROY:
{
// kill the application

PostQuitMessage(0);
return(0);
} break;

default:break;

} // end switch


// process any messages that we didn't take care of

return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc


// WINMAIN ////////////////////////////////////////////////


int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create

HWND hwnd; // generic window handle

MSG msg; // generic message

HDC hdc; // generic dc

PAINTSTRUCT ps; // generic paintstruct


// first fill in the window class stucture

winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS / CS_OWNDC /
CS_HREDRAW / CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

// register the window class

if (!RegisterClassEx(&winclass))
return(0);

// create the window

if (!(hwnd = CreateWindowEx(NULL,WINDOW_CLASS_NAME, // class

"WinX Game Console", // title

WS_POPUP / WS_VISIBLE,
0,0, // x,y
WWIDTH, // width

WHEIGHT, // height

NULL, // handle to parent

NULL, // handle to menu

hinstance,// instance

NULL))) // creation parms

return(0);

// save the window handle and instance in a global

main_window_handle = hwnd;
main_instance = hinstance;

// perform all game console specific initialization

Game_Init();

// enter main event loop

while(1)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit

if (msg.message == WM_QUIT)
break;

// translate any accelerator keys

TranslateMessage(&msg);

// send the message to the window proc

DispatchMessage(&msg);
} // end if


// main game processing goes here

Game_Main();

} // end while


// shutdown game and release all resources

Game_Shutdown();

// return to Windows like this

return(msg.wParam);

} // end WinMain


// WINX GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////

int Game_Init(void *parms, int num_parms)
{


// first create base IDirectDraw interface

if (FAILED(DirectDrawCreate(NULL, &lpdd1, NULL)))
return(0);

// now query for IDirectDraw4

if (FAILED(lpdd1->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd4)))
return(0);

// set cooperation to full screen

if (FAILED(lpdd4->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN / DDSCL_ALLOWMODEX /
DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT)))
return(0);

// set display mode

if (FAILED(lpdd4->SetDisplayMode(WWIDTH,WHEIGHT,BPP,0,0)))
return(0);

DDRAW_INIT_STRUCT(ddsd);

ddsd.dwFlags = DDSD_CAPS;
ddsd.dwBackBufferCount=1;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
//create primary surface

if (FAILED(lpdd4->CreateSurface(&ddsd, &lpddsprimary, NULL)))
return 0;

if (!loadbitmap(&bitmap,"ground2.bmp"))
return 0;

// lock the primary surface

lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR / DDLOCK_WAIT,NULL);

// get video pointer to primary surfce

USHORT *primary_buffer = (USHORT *)ddsd.lpSurface;

// process each line and copy it into the primary buffer

for (int y = 0; y < WHEIGHT; y++)
{
memcpy(&primary_buffer[y*ddsd.lPitch >>1],
&bitmap.buffer[y*WWIDTH*2],
WWIDTH*2);
} // end for index_y


// now unlock the primary surface

if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);

// unload the bitmap file, we no longer need it
unloadbitmap(&bitmap);

// return success or failure or your own return code here


return 1;
} // end Game_Init


///////////////////////////////////////////////////////////


int Game_Main(void *parms, int num_parms)
{

// make sure this isn't executed again

if (window_closed)
return(0);

// for now test if user is hitting ESC and send WM_CLOSE

if (KEYDOWN(VK_ESCAPE))
{
PostMessage(main_window_handle,WM_CLOSE,0,0);
window_closed = 1;
} // end if


return 1;
} // end Game_Main


///////////////////////////////////////////////////////////



int Game_Shutdown(void *parms, int num_parms)
{


// now the primary surface

if (lpddsprimary)
{
lpddsprimary->Release();
lpddsprimary = NULL;
} // end if

// release the directdraw object

if (lpdd4!=NULL)
lpdd4->Release();
return 1;
} // end Game_Shutdown




BeOS, "It's da bomb, baby"

Edited by - wrenhal on June 22, 2000 2:46:18 PM

Edited by - wrenhal on June 22, 2000 2:50:34 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!