Advertisement

another direct draw problem...

Started by May 13, 2000 01:05 AM
2 comments, last by Moe 24 years, 4 months ago
I have just started to learn Direct Draw by reading WGPFD. I have made it up to the section where you make a primary surface, but i am stuck. I can''t figure out what is causing 3 errors, and i figured that you people, being the intelligent, kind, and helping folks that you are could maybe give me a hand. Here is the code (i appologize for not using that code tag thingy, but im not sure how) //INCLUDES #define WIN32_LEAN_AND_MEAN #include #include #include #include #include //DEFINES //defines for windows #define WINDOW_CLASS_NAME "WINCLASS1" #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) //PROTOTYPES int Game_Init(void *parms=NULL); int Game_Shutdown(void *parms=NULL); int Game_Main(void *parms=NULL); //GLOBALS HWND main_window_handle = NULL; LPDIRECTDRAW lpdd; // pointer to direct draw object DDSDSURFACEDESC ddsd; //used to hold the ddraw surface description LPDIRECTDRAWSURFACE lpddsprimary; //FUNCTIONS LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { //main message handler of the system PAINTSTRUCT ps; //used in WM_PAINT HDC hdc; //handle to device context //find out what the message is switch(msg) { case WM_CREATE: //called when window created { //do init. stuff here return(0); } break; case WM_PAINT: { //simply validate the window hdc=BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return(0); } break; case WM_KEYDOWN: { if (KEY_DOWN(VK_ESCAPE)) if (wparam == VK_ESCAPE) { // the user is trying to kill the app, we could post // a quit message or send a WM_DESTROY message // let''s do the later PostMessage(hwnd, WM_DESTROY,0,0); } // end if } break; case WM_DESTROY: { //kill the app PostQuitMessage(0); return(0); } break; default: break; } //end switch //process any messages that you 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) { WNDCLASS winclass; //this will hold the class i create HWND hwnd; //generic window handle MSG msg; //generic message //first, fill in the window class structure 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 = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; //register th window class if(!RegisterClass(&winclass)) return(0); if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class "Prototype", // title WS_POPUP / WS_VISIBLE, 0,0, // x,y GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), // width, height NULL, // handle to parent NULL, // handle to menu hinstance,// instance NULL))) // creation parms return(0); //save the window handle in a global main_window_handle = hwnd; // perform all game console specific initialization Game_Init(); //enter main event loop while(1) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { //test if it 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) { // create object and test for error if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK) return(0); //create a window and get a handle in hwnd //create directdraw object lpdd->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN / DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT); //set the display mode if((lpdd->SetDisplayMode(800, 600, 16))!= DD_OK) { // MessageBox(hwnd, "Error setting display mode", "Error setting display mode", NULL); } //create the primery surface //manually set the size, very important ddsd.dwSize = sizeof(ddsd); //the only field i modify, so i must indicate //in the flags that i want a primary drawing surface; //in this case, i don''t have to define anything else, //because ddraw already knows the resolution & video mode ddsd.dwFlags = DDSD_CAPS; //set the capabilities to what you want, a primary surface ddsd.ddsCaps.dwCaps = DDSDCAPS_PRIMARYSURFACE; //create teh surface and check for errors if(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)!=DD_OK) { /* error */ } // return success return(1); } // end Game_Init /////////////////////////////////////////////////////////// int Game_Shutdown(void *parms) { //first release the surface, but check for errors //if (lpddsprimary) // lpddsprimary->Release(); //now release the ddraw object itself if(lpdd) lpdd->Release(); // return success return(1); } // end Game_Shutdown /////////////////////////////////////////////////////////// int Game_Main(void *parms) { // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! // your code goes here // return success return(1); } // end Game_Main /////////////////////////////////////////////////////////// I think that is all of it. Now here are the errors i am getting: D:\STYDX7IN24\Source\prototype\prototype.cpp(23) : error C2146: syntax error : missing '';'' before identifier ''ddsd'' D:\STYDX7IN24\Source\prototype\prototype.cpp(23) : error C2501: ''DDSDSURFACEDESC'' : missing storage-class or type specifiers D:\STYDX7IN24\Source\prototype\prototype.cpp(23) : fatal error C1004: unexpected end of file found I have no idea what is causing them, especially the one about the missing semicolon. things look good to me. I am pretty sure i have included all the ddraw files properly because i have been able get the other ddraw code to work that changes the resolution, etc. anyway, can anyone here halp me? - Moe -
I''m pretty sure that DDSDSURFACEDESC should be DDSURFACEDESC instead. Also, I don''t think that DDSDCAPS_PRIMARYSURFACE is right either. Try DDSCAPS_PRIMARYSURFACE instead.
Advertisement
Yep, just looked at SDK. SiCrane is right. Either you keyed wrong or source in book is tweaked...
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
That cleared things up guys. Thanks again.

Another fine example of my crappy typing skills.

"a dog may be a man's best friend, but a computer is the next best thing"

This topic is closed to new replies.

Advertisement