 |
|
 |
Simply changing (WinMain.h):
#define APP_ALLOW_FULLSCREEN true
#define APP_DEF_BPP 16
#define APP_DEF_FULLSCREEN true
#define APP_DEF_WIDTH 1024
#define APP_DEF_HEIGHT 768
shows a totally black screen... I've tried using this as a code base for my own project and for me it shows a green gradient from midding of the screen up to the right corner if I choose fullscreen. Very strange. I am however drawing a bunch of 16x16 greenish tiles, I'm guessing they're being displayed. But there definatly seems to be missing some important part in this tutorial or code base.
Also when building with vs2010 the project it says: exe can't be found.
simply right click the project and select Properties and do this:
Change Output dir under general to: $(SolutionDir)bin\$(Configuration)\
Change Intermediate dir under general to: bin\$(Configuration)\debug_crap\
These are obviously my preferred folders, but they'll work for you too
One thing which I think this tutorial needs is the ability to change from/to fullscreen in runtime. Cause like it's made up now, there's no way to do this.
EDIT:
Fix for fullscreen:
inside DrawMain.cpp: unsigned int __stdcall InitScene (const PRENDERARGS pArgList)
Just before the while loop add:
GetClientRect(pArgList->hWnd, &rcClient);
OnResizeFrame(pArgList->hWnd, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
Also make sure the other OnResizeFrame and RenderFrame uses same calculation for width and height as above.
modified 8 Dec '11.
|
|
|
|
 |
|
 |
a very nice sample, could you tell me how to catch events from mouse?
Thank you very much.
|
|
|
|
 |
|
 |
smart_dummies wrote: a very nice sample
Thanks.
smart_dummies wrote: could you tell me how to catch events from mouse?
If you look in the file WinMain.c there's a routine called WndProc. That's were you would catch notification messages sent by Windows for items such as the mouse. You can use the following MSDN link to see possible values to use in the switch block:
http://msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx[^]
|
|
|
|
 |
|
|
 |
|
 |
I wonder how to sync this demo with a 60Hz monitor refresh.
The Debug compilation tells something of 1248 Hz frame rate, which is quite hmmm....
Well, any ideas welcome
|
|
|
|
 |
|
 |
rinchendawa wrote: I wonder how to sync this demo with a 60Hz monitor refresh.
The article mentions setting APP_ALLOW_VSYNC to true to achieve this.
rinchendawa wrote: The Debug compilation tells something of 1248 Hz frame rate, which is quite hmmm....
That's not uncommon with cards this day and age for a very simple scene that's not vsynced.
|
|
|
|
 |
|
 |
Hi
First of all a million thanks for writing such a wonderful code . The comments have been really good to understand whats happening under the hood. I have just started OpenGL and its great to see an article that has integrated Win32 and OpenGL in such a nice way especially the messaging queue. Beside it doesnt have C++ so it makes lot easy for me to understand all .
I have noticed that when the window is active the CPU utlization is around 10-15% but the moment i minimize it reaches to 50-60%. Thats rather strange. Running it on VC2005 Team editon on Vista ultimate.
Let me know if u noticed anything like this?
Regards,
Kavitesh Singh.
|
|
|
|
 |
|
 |
kavitesh wrote: First of all a million thanks for writing such a wonderful code
Thank you!
kavitesh wrote: Beside it doesnt have C++ so it makes lot easy for me to understand all
That's actually one of the reasons this was done in C. I wanted the focus to be on OGL and WGL more than design patterns, etc.
kavitesh wrote: Let me know if u noticed anything like this?
It's because the game loop is running faster as there's less to update when no display is visible. You can either just pause the process and/or game loop or throttle it down when it's minimized and/or lost focus. In fact I may add that in an update since its common enough.
|
|
|
|
 |
|
 |
I also want to say thanks for the nice code.
I have also issues about CPU ubilization and window resizing:
1:
When the window is iconic there is no need to render on the OpenGL side.
So in function InitScene one could add:
if(!IsIconic(pArgList->hWnd))
{
...
}
else Sleep(100); // pause thread for 500 msec
This will slow down CPU usage, but may not be the best solution.
I still figure out how to use something like SuspendThread(bool yes_no) upon resizing the window.
2:
The WM_SIZE message should also be checked for SIZE_MAXIMIZED if one allows window maximizing.
Just do the same as in SIZE_RESTORED. This will re-center the graphics. Same probably goes for fullscreen mode.
Well, that's all.
Other than this, excellent code, really
|
|
|
|
 |
|
 |
rinchendawa wrote: I also want to say thanks for the nice code.
I have also issues about CPU ubilization and window resizing:
Thanks. Looks like you beat me to it. You do address some good points, although I would avoid the Sleep API but I do need to add a few more tidbits to this sooner than later.
|
|
|
|
 |
|
 |
Hi,
why if active system menu, display stops?
Thanks
Antonio Giuliana
|
|
|
|
 |
|
 |
giuliana_a wrote: why if active system menu, display stops?
This is by design, as the transparent drop shadow provided by Windows doesn't get updated. So, constant animation would leave some artifacts. This can be altered however, should you use an owner drawn menu and/or disable the drop shadows. Look into WM_ENTERMENULOOP in WinMain.c for more info as how to stop this.
|
|
|
|
 |
|
 |
Hi,
good job. Very interesting.
I modify the example project to allow resize (#define APP_ALLOW_RESIZE true). During resize it flickers. Does anyone know why?
Thanks.
PD: My message is a bit outdated, but haven't found this article before. .
|
|
|
|
 |
|
 |
Himar Carmona wrote:
I modify the example project to allow resize (#define APP_ALLOW_RESIZE true). During resize it flickers. Does anyone know why?
Check out my response to the thread below titled "worker thread slowed by MFC UI interactions" for more information as to why. The reasons are mostly the same, with the DC preempting the RC. However, with the resize, you do have an option to reduce the flicker, you can override WM_ERASEBKGND. Check MSDN and/or Google for more info.
|
|
|
|
 |
|
 |
I create a SDI MFC program in which there is a worker thread to render a 3D scene. I found the rendering speed will be interupted and slowed by some UI interactions, e.g., moving the window by drag the window title, mouse move on some toolbar's buttons. I don't why. Could you give some suggestion?
Thanks.
|
|
|
|
 |
|
 |
solehome wrote: Could you give some suggestion?
Assuming there's no bottlenecks in your threads and/or WM_PAINT...
When dragging a window around you will always notice a decrease in FPS because Windows has to redraw the window a lot, which redraws the client area and updates the DC, which forces the RC to be preempted by the DC it belongs to. Being in a separate thread doesn't matter because the RC will always be subservient to the DC it belongs to, and the DC still belongs to the GDI - which is slow.
To see this in action, try downloading, compiling, and then run the example application for this article in windowed mode, and then run Notepad and drag it back and forth over the GL sample app. You should notice a drop in FPS. And this is due to a totally different app!
|
|
|
|
 |
|
 |
Very Informative reply. Thanks
Maybe multi-core CPUs and full screen mode can help.
|
|
|
|
 |
|
 |
solehome wrote: Very Informative reply. Thanks
No problem.
solehome wrote: Maybe multi-core CPUs and full screen mode can help.
Yup, multi-core is the way of the future. Also, if you run your game/app in fullscreen Windows will give it a much higher priority, so yes you're right, that will help.
|
|
|
|
 |
|
 |
Also, a lot of games will use in-game menus and toolbars as well rather than the standard Windows version. This way, you won't have to worry about the DC slowing things down when navigating them either, if they happen to force a redraw that is.
|
|
|
|
 |
|
 |
Thank you Jeremy for this great article.
I'm trying to wrap it in classes, so i can create multiple windows doing continuous rendering.
As i'm rendering to video, uninterrupted rendering is a must (hence me putting the rendering in separate threads)....
yet as you explained above, performance suffers from other windows being dragged, minimized .
can you elaborate on the "RC to be preempted by the DC it belongs to", i do not understand what this means (i tried to google it, but that didn't make sense)
What can possibly be done to avoid this performance degradation?
Thanks up front
Bert
|
|
|
|
 |
|
 |
Piet Bibber wrote: Thank you Jeremy for this great article.
You're welcome.
Piet Bibber wrote: can you elaborate on the "RC to be preempted by the DC it belongs to"
Keep in mind, that was said before Vista came to be popular. If you turn on Aero/desktop compositing in Vista things are a bit different now. There's a slight loss in performance for moving stuff around, but it's not nearly as bad. If you turn off compositing, however, it still works the same way as previous versions of Windows and suffer the DC preemption. So, since not everyone uses Vista or Aero it's still a concern.
Anywho, the order of relationship of preemption with a Windows (the OS) app in regards to this is Window > DC > RC. The Window can kill the DC's drawing, and the DC can kill the RC's drawing. When Windows or menus move about the screen Windows (the OS) sends a signal to whichever DC (client or non) needs to be invalidated (usually means it needs to be redrawn to show it after being exposed) and voila. But the DC is not hardware accelerated. It's slow as dirt compared to the RC - which Windows (the OS) doesn't really care about. It just knows that until the DC is happy (redrawn) then everything can wait its turn like good little children.
Outside of using Vista's desktop compositing, there is zero way to stop this. It's just the way Windows (the OS) works.
Piet Bibber wrote: What can possibly be done to avoid this performance degradation?
You have two options really. You can either make your application fullscreen and don't use anything drawn by a DC (like menus provided by Windows, etc.) or you can look into off-screen rendering for your application. If it's not shown on the screen, the DC will never be invalidated by other Windows moving around.
|
|
|
|
 |
|
 |
Thanks for the elaboration, albeit not so good news
It looks like other application indeed also suffer from the effect, yet strangely, others don't. (under XP)
YouTube (flashplayer) movies stutters while minimizing/maximizing (even non overlapping) windows. But, another multi threaded app in [1] doesn't !? (click on the screen to get some balls moving - they *don't* stop moving - even when the window overlaps [2])
Under Vista, the YouTube doesn't stutter while minimizing/maximizing (area turned on or off)
Have I found a solid requirement to move to Vista?
Thanks
Bart
[1] http://www.codeproject.com/KB/cpp/SyncMultithreadedMFC.aspx[^]
[2] no hardware accel - just plain GDI
|
|
|
|
 |
|
 |
Piet Bibber wrote: YouTube (flashplayer) movies stutters while minimizing/maximizing (even non overlapping) windows.
This is not hardware accelerated. It's just like movie animation. It's just as slow as the DC, but it'll appear fluid due to the way it works. It's a trick on your eyes.
Piet Bibber wrote: click on the screen to get some balls moving - they *don't* stop moving - even when the window overlaps
In Vista, turn off desktop composting. Play around with the menus a lot. You'll notice some bottlenecks. Also, the effects of this animation is less noticeable again because it's the GDI doing the drawing in the first place. It only appears smooth sometimes since the animation is much much slower then what the RC can handle. So it gives it some time for the DC to do its thing. This can work to create an illusion, but the slow down is still happening.
|
|
|
|
 |
|
 |
I too am developing an engine using OpenGL, also for the learning more than anything else. My plan is to create an engine that is scriptable so have spent the last few months creating an interpreter for a C-style scripting language which manipulates objects, lights, cameras etc.
I am now looking into the more advanced OpenGL stuff to include in my engine, along with support for shaders - now that I have a new computer which has a seriously powerful graphics card. It has been a while since I looked at this project but I shall try this approach and see if it offers me any speed increases. Thanks!
PS. Your name is familiar, I think we spoke a few years ago - you were creating a VB encryption program. If it is you, it is funny how we are moving along the same lines.
|
|
|
|
 |
|
 |
alankelly wrote: Very nice article
Thanks.
alankelly wrote: also for the learning more than anything else.
It's a great plan. In the end we can learn a lot and possibly help others in the community as well maybe improve upon from public feedback. Sounds like win-win to me.
alankelly wrote: My plan is to create an engine that is scriptable so have spent the last few months creating an interpreter for a C-style scripting language which manipulates objects, lights, cameras etc.
Sounds cool. I never used LUA but I know that a lot of engines also use that as a script if you want to at least pull some ideas from it.
alankelly wrote: It has been a while since I looked at this project but I shall try this approach and see if it offers me any speed increases. Thanks!
The multi-threading will really shine on the newer systems that have dual cores, or even hyper threading will benefit somewhat. It really will be the way of the future, so it's worth integrating into your engine for sure.
alankelly wrote: PS. Your name is familiar, I think we spoke a few years ago - you were creating a VB encryption program. If it is you, it is funny how we are moving along the same lines.
I dunno. I have made one in the past in VB so maybe. And ya know what they say, great minds think alike.
|
|
|
|
 |