Archived

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

Wierd DirectX (d)effect :/

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

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
nope the window-handle-trick didn''t work. I will try a little more and then i might mail you the code

btw i am using the c style code due to the simple fact that my compiler doesn''t support c++ style

--Spencer

Share this post


Link to post
Share on other sites