Wierd DirectX (d)effect :/
Hi!
I am quite new to directX and i just started programming in DirectDraw. The thing i was doing was :
DirectDrawCreate(...);
SetCooperativeLevel(..);
SetDisplayMode(...);
CreateSurface(...);
all this was in my WinMain function and everything worked fine.
So i decided to clean it up a bit and moved all the DirectDraw stuff to a separate function. Now the funny(?) thing happened.
After the directX function was called (it set everything correctly) the program exits and restores everything. My question is....why??? anyone had the same problem?
I have all the directX variables as globals in the same file...
thanx in advance
--Spencer
Hmm, it sounds as if something goes wrong with the message loop. You should check if the message loop is executed. I think it would be easier to answer your question, if you can post your code of the WinMain function (only the part of the DX initialization and message loop).
okej...here comes the relevant code:
if((DirectDrawCreate(NULL,&lpdd,NULL))!=DD_OK)
//error
if((lpdd->lpVtbl->SetCooperativeLevel(lpdd,hwndMain,
DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))!= DD_OK)
//error
if((lpdd->lpVtbl->SetDisplayMode(lpdd,SCR_WIDTH,SCR_HEIGHT,BPP,0, 0))!=DD_OK)
//error
memset(&ddsd,0,sizeof(ddsd));
memset(&lpddsprimary,0,sizeof(lpddsprimary));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
//MessageBox(hwndMain,"Failed DDcreate","ERROR",MB_OK);
if((lpdd->lpVtbl->CreateSurface(lpdd,&ddsd,&lpddsprimary,NULL))!=DD_OK)
//error
end of code
if i move these lines to another function and call it from here it doesnt work, but as long as it is in WinMain it is okay.
thanx
--Spencer
if((DirectDrawCreate(NULL,&lpdd,NULL))!=DD_OK)
//error
if((lpdd->lpVtbl->SetCooperativeLevel(lpdd,hwndMain,
DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))!= DD_OK)
//error
if((lpdd->lpVtbl->SetDisplayMode(lpdd,SCR_WIDTH,SCR_HEIGHT,BPP,0, 0))!=DD_OK)
//error
memset(&ddsd,0,sizeof(ddsd));
memset(&lpddsprimary,0,sizeof(lpddsprimary));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
//MessageBox(hwndMain,"Failed DDcreate","ERROR",MB_OK);
if((lpdd->lpVtbl->CreateSurface(lpdd,&ddsd,&lpddsprimary,NULL))!=DD_OK)
//error
end of code
if i move these lines to another function and call it from here it doesnt work, but as long as it is in WinMain it is okay.
thanx
--Spencer
i am terribly sorry for my sloppyness..i forgot the message loop.
here it comes:
while (not done) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
if(msg.message == WM_QUIT)
break;
TranslateAccelerator(msg.hwnd,hAccelTable,&msg);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//do whatever();
}
phew
here it comes:
while (not done) {
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
if(msg.message == WM_QUIT)
break;
TranslateAccelerator(msg.hwnd,hAccelTable,&msg);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//do whatever();
}
phew
Well, maybe it is the fact that you give a NULL pointer to the PeekMessage() function as the window handle. I would try to use the handle from your main window instead. I can see no other problem here. But maybe you can e-Mail me the code, so I can check if I have the same problem or can find the error.
BTW why are you using the C coding style with virtual tables ?
BTW why are you using the C coding style with virtual tables ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement