Page 1 of 1

Irrlicht on MFC CButton causes flicker on click

Posted: Wed Jun 20, 2007 10:59 am
by Dave
Hello everyone,

I have a Win32 MFC form with a CButton component on it. When I create my Irrlicht device I pass the hwnd of that button to creation parameters:

Code: Select all

irr::SIrrlichtCreationParameters parameters;
parameters.DriverType = irr::video::EDT_DIRECT3D9;
parameters.WindowId = hWnd; // hWnd is specified somewhere else.
irr::createDeviceEx(parameters);
This works perfectly, Irrlicht renders everything into the button (which covers most of the form). The problem is, I want users to be able to select objects using the mouse. I have this working already, but everytime I click somewhere within the render window, the MFC button redraws. This causes an annoying flicker on the screen.

When I disable the redraw of the button, nothing gets rendered. So the redraw/refreshing of the button is necessairy.

Does anyone know how to prevent the button from flickering? Or perhaps I need to create Irrlicht on another MFC component?

I know this problem is more related to Windows programming, but I appreciate any help :)

Posted: Wed Jun 20, 2007 11:45 am
by lester
man, have you ever spoken with the psychiatrist?

irrlicht inside the button, what a mess

Posted: Wed Jun 20, 2007 12:13 pm
by GuerillaSoftworks
Why the hell would you put Irrlicht inside a button?

Posted: Wed Jun 20, 2007 12:16 pm
by Dave
As you can see in example 14 of the Irrlicht SDK:

Code: Select all

// create window to put irrlicht in
HWND hIrrlichtWindow = CreateWindow("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 50, 80, 320, 220, hWnd, NULL, hInstance, NULL);
This works, you just create a button and Irrlicht renders on/in it.

Perhaps I was somewhat unclear, so what my question is: what is the best MFC element to use as render window for Irrlicht? I need some kind of element that has an OnClick event and doesn't cause flickering to the render window when clicking on it.

Posted: Wed Jun 20, 2007 12:42 pm
by GuerillaSoftworks
Ok.
But why do you need to put your Irrlicht device in a button? Whats the reasoning behind that? Is there a reason why it can't go in your root window? Where you put an Irrlicht device is dependent on what you hope to accomplish with your application.

Please note that the tutorial shows an example of using the Windows API not MFC, theres a difference I believe.

Posted: Wed Jun 20, 2007 12:56 pm
by Dave
It doesn't have to be a button. I just need a small part of my total form to be used as render window. The other part of the form contains listboxes, buttons and all kinds of regular MFC controls.

I picked a button because that worked, has an onclick event and was used in the example. The way that the example works is indeed different than my way using MFC.

So I what I need is this: a smaller part of my main form for Irrlicht to render in.

Edit: I now noticed that I didn't really mention that in the previous posts. Kind of important, so now you know ;)

Posted: Wed Jun 20, 2007 1:05 pm
by GuerillaSoftworks
I havn't personally done something like this myself so im not sure about this but can't you use your main window as the parent of your device and simply position where the device renders within that?

If not I would recommend using a static control.

About using a button to do this; when you click a button it needs to be redrawn to show that it is being clicked. This would cause problems as irrlicht is infact continuously drawing to the same area that button is.

Posted: Wed Jun 20, 2007 1:21 pm
by Dave
As far as I know, the SIrrlichtCreationParameters struct allows only a resolution to be set. However, if I let Irrlicht render in the main window, the resolution parameters seems to have no effect; the whole window just gets used.

About the button, do you know of a way to stop the button itself from redrawing when it gets clicked?

Posted: Wed Jun 20, 2007 1:30 pm
by lester
maybe you should try a panel for rendering into? I think the same what GuerillaSoftworks said, redrawing the button causes a flickering.

Posted: Wed Jun 20, 2007 1:47 pm
by GuerillaSoftworks
Unfortunatley im not familiar at all with MFC, only with WinAPI and with that im no expert. Sorry.

Can you post your code for your window procedure? and also any other code that has irrlicht stuff in it. just to check when things are draw and that they are drawn at the appropriate time.

Im not sure about telling a button (window) to not redraw when clicked; perhaps there is a message you can post on the mesage queue that does this for you. have a look at some MFC dev forums for that.

Posted: Wed Jun 20, 2007 2:19 pm
by lester
sorry, I don't use MFC particullary and windows at all, so I can't help you.

I was just wondering is there a better way to integrate irrlicht into your app

Posted: Thu Jun 21, 2007 7:31 am
by Dave
Thanks for your help so far.

GuerillaSoftworks: what do you mean with "my code for windows procedure"? Like, the code I use to create Irrlicht inside the button or how I create the button itself?

I'll try searching on forums regarding MFC for a solution (expanding CButton or use some kind of panel). That will probably be a piece of difficult/unreadable (macro)code I have to implement somewhere :(

If anyone has experience with Irrlicht and MFC, please contact me.

Posted: Thu Jun 21, 2007 8:24 am
by GuerillaSoftworks
Ok, im not familiar with MFC; Im guessing though, a MFC developer doesn't have to worry about message queues and window procedures. Sorry I can't help here, i'm a WinAPI man.

Posted: Thu Jun 21, 2007 12:26 pm
by Dave
I finally have it! The solution is stated below:

- Subclass a CButton to create your own CRenderButton
- Make sure that the button's property 'OwnerDrawn' is true
- Create the following method within your CRenderButton class:

Code: Select all

void CRenderButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	lpDrawItemStruct->itemState = ODS_DEFAULT;
}
Now when you click on the button, it doesn't update to show it's selected. So now when you let Irrlicht render into the button, the flickering is gone.