Porting from Win32 to wxWidgets

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
r4t4t0sk
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 23, 2005 12:29 am

Porting from Win32 to wxWidgets

Post by r4t4t0sk »

Hello everyone! I'm very new to wxWidgets, and I've decided to port an application I'm in the middle of writing from Win32, and I have a problem that I was hoping someone would have a solution to:

The main window of my program displays a 3D DirectX scene.

Now, all of the child windows of the main window can be easily ported to wxWidgets. However, I can't for the life of me seem to get the main window in wxWidgets to draw DirectX. I'm sure there's a way to either do this, or work around it. I just don't know how because I just started learning wxWidgets a few days ago.

Because I already have the main window running smoothly in Win32, I also wouldn't mind having wxWidgets run concurrently with my Win32 code. Again, because I'm so new with wxWidgets, I'm not sure how I would do that properly so that the main window was win32 but all the children were wxWidgets. My main concern would be getting the wxApp to shutdown when I shut the win32 window down, and having the Menu in the win32 window call up wxWidget windows. I know where I would put the shutdown and windows calling functions in my win32 code, I just don't know what wxWidgets functions to call.

Thank you to anyone who replies!

I'm compiling with VC++ .net 2003, and my wxWidgets version is 2.4.2
r4t4t0sk
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 23, 2005 12:29 am

a continuously updating MainLoop() ?

Post by r4t4t0sk »

Ok, well I've gotten a lot closer. If I take the DirectX code and drop it into wxApp::MainLoop() I can get it to draw to the window. UNFORTUNATELY, it only updates when I do something that would send a windows message (like jiggle the mouse). After some screwing around, I've found that the DoMessage(); function towards the bottom seems to be the culprit. When I comment it out, my directx function updates with great fury, but then my window doesn't process messages (for instance, the "x" to close the application).

Does anyone know of a way to stop DoMessage() from halting MainLoop's cycle when no inputs to the program are made? OR, does anyone know of another place that I could drop my directx function that would allow it to update continuously? Like say a paint function?

Below is my "hacked" MainLoop(). The changes I've made are bolded

int MyApp::MainLoop()
{
m_keepGoing = TRUE;

while ( m_keepGoing )
{
#if wxUSE_THREADS
wxMutexGuiLeaveOrEnter();
#endif // wxUSE_THREADS
while ( !Pending() && ProcessIdle() )
;

// a message came or no more idle processing to do
DoDirectXStuff();
DoMessage();
}

//return s_currentMsg.wParam;
return 0;

}

apparently s_currentMsg.wParam isn't recognized outside of app.cpp because s_currentMsg isn't an extern. However, it doesn't seem like that particular message actually goes anywhere, or affects the program's shutdown procedure at all. So I just nixed it to get MainLoop() running.
geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon »

You shouldn't need to hack the event loop. On windows, you have access to the handle of your window. Is'nt that enough to write windows-speciffic code in your window-class?

I gladly admit I din't know any windows programming of directX, but I know his has been done before.

Depending you your project, it might be relatively easy to port your DirectX code to OpenGL. Then you will have a platform independent app.
r4t4t0sk
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 23, 2005 12:29 am

Post by r4t4t0sk »

Well, actually, I'd tend to agree with you that I don't need to hack the event loop. However, the even loop is one of the places that is frequently updated, which is something I do need for the directx code. I just need to put it in a place where windows will run it for every tick of the program. Normally when programming in DirectX, you place your drawing code into the message loop for convenience (since it updates every tick when you're only handling the quit message). I'm not exactly sure where to put it now. As I mentioned before, is there any function in wxWindows that the program will run constantly throughout the program? At this point, I don't think any knowledge of DirectX is required to answer the question :) Again, my guess is some sort of paint command, but I don't know enough about wxWidgets to know whether or not I'm right, and what function that would be. Anyone know?
r4t4t0sk
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 23, 2005 12:29 am

Post by r4t4t0sk »

Aha! I finally got it! You can run a DirectX window fairly easily in wxWidgets. In fact, I'd imagine you could use the same technique for openGL:

1) give your target frame a D3D device and a D3D initialization function. Call the init function in the frame constructor.

2) release the device in the frame destructor.

3) give the target frame a D3D "run" function, which has the code for cleaning the surface, displaying the 3D objects, and presenting them. Hook this function up to a Timer Event, and set the timer event to 1/fps (one over your frames-per-second. Usually you want at least 30fps, if not 60)

apparently, wxWidgets nails the frame-rate as well as my win32 code. However, I have yet to test it under conditions where there are a huge number of polygons to display. If anyone is looking to quickly port a DirectX or openGL win32 app into wxWidgets, drop me a line and I'd be happy to explain.
Kiryn
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Mar 22, 2007 11:16 am
Contact:

Post by Kiryn »

yes please for love of god. :). Post a tutorial on the main site for this part. Cause I don't want OpenGL or win32 api ;)
Post Reply