Irrlicht on MFC CButton causes flicker on click

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Dave
Posts: 25
Joined: Wed Mar 28, 2007 11:00 am

Irrlicht on MFC CButton causes flicker on click

Post 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 :)
lester
Posts: 86
Joined: Mon Jan 29, 2007 3:33 pm

Post by lester »

man, have you ever spoken with the psychiatrist?

irrlicht inside the button, what a mess
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

Why the hell would you put Irrlicht inside a button?
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
Dave
Posts: 25
Joined: Wed Mar 28, 2007 11:00 am

Post 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.
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post 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.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
Dave
Posts: 25
Joined: Wed Mar 28, 2007 11:00 am

Post 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 ;)
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post 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.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
Dave
Posts: 25
Joined: Wed Mar 28, 2007 11:00 am

Post 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?
lester
Posts: 86
Joined: Mon Jan 29, 2007 3:33 pm

Post by lester »

maybe you should try a panel for rendering into? I think the same what GuerillaSoftworks said, redrawing the button causes a flickering.
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post 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.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
lester
Posts: 86
Joined: Mon Jan 29, 2007 3:33 pm

Post 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
Dave
Posts: 25
Joined: Wed Mar 28, 2007 11:00 am

Post 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.
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post 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.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
Dave
Posts: 25
Joined: Wed Mar 28, 2007 11:00 am

Post 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.
Post Reply