Skip to main content
GameDev.net gamedev.net
🔒 Locked

Slow windowed mode

Started by JonW Jan 21, 2003 at 6:26 PM 9 replies 600+ views
Original Post
JonW
JonW
I recently added a windowed mode for my DirectDraw app for debugging, but for some reason the application runs really slow unless I call GetDC () and ReleaseDC () on my backbuffer every frame. What is really strange is that the framerate is in the 100''s, but when I move the cursor it takes about 2 seconds for it to move. When I click it takes another two seconds for the application to do anything. But it works fine when calling GetDC every frame. Thanks.
mdias
mdias
I guess you''re using "GetMessage()" instead of "PeekMessage()".
It happened to me in Direct3D, I was using "GetMessage()" and only
when I moved the mouse over the window it runned fast otherwise it
was slow as hell....

"GetMessage()" is only used for aplications, if you''re developing a
game/demo you should use "PeekMessage()"

Hope that helps


KaMiKaZe
JonW
JonW
I don''t have the code with me right now, but it worked in fullscreen mode just fine. So I wouldn''t think it would have something to do with the message pump. And what is the deal with GetDC ()? The idea that I have to call it in order to get my program to work right is mind boggling :)

Good suggestion though.


[Edited by - JonW on July 21, 2009 8:23:46 PM]
mdias
mdias
Try the "PeekMessage()"
Well, about GetDC(), maybe it sends a notification to the window so the
"GetMessage()" receives the notification message and runs with the rest of the code...

[Edit:] About working fine in fullscreen:
I think that when direct draw is in fullscreen mode it renders directly to the
monitor, not to the window...


KaMiKaZe

[edited by - Kamikaze15 on January 22, 2003 10:40:38 AM]
JonW
JonW
No luck with PeekMessage (), but you are probably right in that the problem lies in Windows messages.

Maybe it is how I created the window? I only use WS_OVERLAPPED for the style, but maybe I need CS_VREDRAW, CS_HREDRAW, and CS_OWNDC also?
mdias
mdias
When I create my D3D windows I create it only with WS_OVERLAPPEDWINDOW
flag.
Don''t know what''s your problem, but you could see if it''s a windows messages
problem try to "PostMessage()" every frame to the window, if it works ok then
the problem lies on windows messages otherwise I can''t see where your
problem lies.
Good Luck


KaMiKaZe
neo_ryder
neo_ryder
right after you create you window do the following, sometimes it gives a huge boost in windowed mode.

rect_t rc(0, 0, width, height); // desired width , height

AdjustWindowRectEx(&rc, GetWindowStyle(g_hwnd), GetMenu(g_hwnd)!= 0,GetWindowExStyle(g_hwnd));

SetWindowPos(g_hwnd, NULL, 0, 0, rc.width(), rc.height(),
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );

BTW rect_t is a simple wrapper around the regular RECT.

hope this helps ...
Bullmax
Bullmax
Are you handling WM_PAINT. In this message handling, you ValidateRect()... or InvalidateRect().... not sure...

And by the way, if you resize your window (if you have an WS_OVERLAPPEDWINDOW), it will really things up.



/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, yin and yang.
/ Bullmax /-------------Reality has many forms : good and evil, black and white, yin and yang.
remi
remi
I think that u should call GetDC() and ReleaseDC() every frame, i read it somewhere but i don''t remember exactly.
"...and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces."----------Scott Meyers, "Effective C++"
JonW
JonW
I found out that you can call GetDC () on any surface every frame and it will work. I wasn''t handling WM_PAINT before, but I tried putting in some code to validate:

  
// Window needs repainting
case WM_PAINT:
{
// Tell Windows to leave us alone
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hWnd, &ps);
EndPaint (hWnd, &ps);
break;
}



But it didn''t work.

Kamikaze : What message do I post with PostMessage ()?
remi : I''ll use that as a last resort.
neo_ryder : The game runs just fine, like I said the fps is about 180. But everything goes so slow if I don''t call GetDC ().

Thanks for all the replies.


[Edited by - JonW on July 21, 2009 8:41:57 PM]
mdias
mdias
quote:
Original post by JonWoyame
Kamikaze : What message do I post with PostMessage ()?



try posting something like a mouse moviment:

PostMessage( hWnd, WM_MOUSEMOVE, 0, 0 );
// or
PostMessage( hWnd, WM_SHOWWINDOW, 0, 0 );


When I first had your kind of problem I posted a WM_MOUSEMOVE to my window
every frame and it ran well, but I didn''t want to post a message to the window
so I looked of what I could do and I found "GetMessage()" to be my problem but
if it doesn''t work with you I relly can''t see what''s wrong...
But I still suspect it''s some kind of window problem because you can run your
app fine when in Fullscreen mode...


KaMiKaZe

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.