Using SDL and OpenGL with wxWidgets to create a game editor Topic is solved
Using SDL and OpenGL with wxWidgets to create a game editor
Hi dudes!
I would like to create a level editor for my game, a 2D platform usign opengl and a physics engine written in C, because of this, I must use C++ (Firstly I wanted to use Delphi, cause it is a RAD, but as it was not possible to integrate the physics engine, I discard it).
Questions:
Can I do this with wxWidgets? I guess so.
Is it possible to integrate SDL into wxWidgets? Is it necessary or not? Does using SDL has any advantage?
Can I use all mouse and keyboard events without SDL?
When I simulate a game (motion with physics) should I use a timer or a thread?
Thanks a lot for your time.
I would like to create a level editor for my game, a 2D platform usign opengl and a physics engine written in C, because of this, I must use C++ (Firstly I wanted to use Delphi, cause it is a RAD, but as it was not possible to integrate the physics engine, I discard it).
Questions:
Can I do this with wxWidgets? I guess so.
Is it possible to integrate SDL into wxWidgets? Is it necessary or not? Does using SDL has any advantage?
Can I use all mouse and keyboard events without SDL?
When I simulate a game (motion with physics) should I use a timer or a thread?
Thanks a lot for your time.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
-
- Experienced Solver
- Posts: 72
- Joined: Fri Feb 20, 2009 7:13 pm
- Location: $(#wx)\src
I recently have been researching the subjects. I think there are a couple of examples floating around that demonstrates that this is possible. I know you can integrate a basic Windows window with OpenGL.
SDL is more of a library that is used for Events, simple OpenGL window management, basic Audio rendering, etc. The reason people would want to integrate the two is too have native widgets integrated into there little program.
http://code.technoplaza.net/wx-sdl/
That is a tutorial based on how.
Also, SDL is very organized with the events and actually extremely easy to integrate.
Also, aren't Timers and Threads two completely different things?
SDL is more of a library that is used for Events, simple OpenGL window management, basic Audio rendering, etc. The reason people would want to integrate the two is too have native widgets integrated into there little program.
http://code.technoplaza.net/wx-sdl/
That is a tutorial based on how.
Also, SDL is very organized with the events and actually extremely easy to integrate.
Also, aren't Timers and Threads two completely different things?
-
- In need of some credit
- Posts: 9
- Joined: Tue Jul 31, 2007 5:01 pm
- Contact:
I'm currently writing an emulator and so far using wx's wxGLCanvas class with a wxTimer is working out very well for frame rendering (I need a refresh every 16.6ms).
Basically I merged the wxTimer based "render loop" and OpenGL examples available on the wx wiki. Using OpenGL also gives you the acceleration advantage available with the hardware.
SDL is nice, and I still might use parts of it for the sound, but I won't be using SDL's even loop or input functions since wx has everything I need.
I did initially try a wxThread for my VDP refresh, but I could not get a custom event to work. The VDP thread needed to let the rest of the emulator know when a vertical refresh had taken place and that the frame buffer was updated and should be redrawn (since you are not supposed to draw from any thread other than the main process.) Anyway, I could not get it to work. The wxTimer does work though, very well, and it is in the main process so I don't have to worry about threads, custom messages, or synchronization.
I'm currently planning on using another wxTimer for my main emulator tick as well. Something to keep in mind is the OS quantization time (the time slice your application gets to run), which on most modern GUI OSes is about 10ms. This was a problem for my VDP timer because on the real hardware the frames are drawn 60 times a second (every 16.6ms). You can see that 16.6ms does not divide evenly by 10ms, so when the wxTimer event runs the VDP code, the first thing I do is see how much *actual* time has elapsed since the last frame. If the actual time is over 16.6ms I generate a frame and subtract 16.6 from the actual time to keep as an "error" value that is added to the elapsed time on the next wxTimer event.
It actually works very well. Before adding the error tracking I was off by about 4 seconds (240 frames) after 1 minute of running. With the error tracking, the frame rate is still accurate after 30 minutes (and I got tired of checking it.)
In your case the idle event might work better. In my tests is happened much too often (much faster than the wxTimer set to 10ms) and was just wasting CPU. However, for your simulation where you don't have to worry about matching the CPU clock of a legacy computer system, running "all out" as fast as you can would probably be desirable.
The other option is to have a polling type of event loop (which is what games usually do), but I don't know if wx supports that. Also, you would not want that anyway for your editor.
Hope this helps somehow.
Matthew
Basically I merged the wxTimer based "render loop" and OpenGL examples available on the wx wiki. Using OpenGL also gives you the acceleration advantage available with the hardware.
SDL is nice, and I still might use parts of it for the sound, but I won't be using SDL's even loop or input functions since wx has everything I need.
I did initially try a wxThread for my VDP refresh, but I could not get a custom event to work. The VDP thread needed to let the rest of the emulator know when a vertical refresh had taken place and that the frame buffer was updated and should be redrawn (since you are not supposed to draw from any thread other than the main process.) Anyway, I could not get it to work. The wxTimer does work though, very well, and it is in the main process so I don't have to worry about threads, custom messages, or synchronization.
I'm currently planning on using another wxTimer for my main emulator tick as well. Something to keep in mind is the OS quantization time (the time slice your application gets to run), which on most modern GUI OSes is about 10ms. This was a problem for my VDP timer because on the real hardware the frames are drawn 60 times a second (every 16.6ms). You can see that 16.6ms does not divide evenly by 10ms, so when the wxTimer event runs the VDP code, the first thing I do is see how much *actual* time has elapsed since the last frame. If the actual time is over 16.6ms I generate a frame and subtract 16.6 from the actual time to keep as an "error" value that is added to the elapsed time on the next wxTimer event.
It actually works very well. Before adding the error tracking I was off by about 4 seconds (240 frames) after 1 minute of running. With the error tracking, the frame rate is still accurate after 30 minutes (and I got tired of checking it.)
In your case the idle event might work better. In my tests is happened much too often (much faster than the wxTimer set to 10ms) and was just wasting CPU. However, for your simulation where you don't have to worry about matching the CPU clock of a legacy computer system, running "all out" as fast as you can would probably be desirable.
The other option is to have a polling type of event loop (which is what games usually do), but I don't know if wx supports that. Also, you would not want that anyway for your editor.
Hope this helps somehow.
Matthew
matthew180 wrote:I'm currently writing an emulator and so far using wx's wxGLCanvas class with a wxTimer is working out very well for frame rendering (I need a refresh every 16.6ms).
Basically I merged the wxTimer based "render loop" and OpenGL examples available on the wx wiki. Using OpenGL also gives you the acceleration advantage available with the hardware.
SDL is nice, and I still might use parts of it for the sound, but I won't be using SDL's even loop or input functions since wx has everything I need.
I did initially try a wxThread for my VDP refresh, but I could not get a custom event to work. The VDP thread needed to let the rest of the emulator know when a vertical refresh had taken place and that the frame buffer was updated and should be redrawn (since you are not supposed to draw from any thread other than the main process.) Anyway, I could not get it to work. The wxTimer does work though, very well, and it is in the main process so I don't have to worry about threads, custom messages, or synchronization.
I'm currently planning on using another wxTimer for my main emulator tick as well. Something to keep in mind is the OS quantization time (the time slice your application gets to run), which on most modern GUI OSes is about 10ms. This was a problem for my VDP timer because on the real hardware the frames are drawn 60 times a second (every 16.6ms). You can see that 16.6ms does not divide evenly by 10ms, so when the wxTimer event runs the VDP code, the first thing I do is see how much *actual* time has elapsed since the last frame. If the actual time is over 16.6ms I generate a frame and subtract 16.6 from the actual time to keep as an "error" value that is added to the elapsed time on the next wxTimer event.
It actually works very well. Before adding the error tracking I was off by about 4 seconds (240 frames) after 1 minute of running. With the error tracking, the frame rate is still accurate after 30 minutes (and I got tired of checking it.)
In your case the idle event might work better. In my tests is happened much too often (much faster than the wxTimer set to 10ms) and was just wasting CPU. However, for your simulation where you don't have to worry about matching the CPU clock of a legacy computer system, running "all out" as fast as you can would probably be desirable.
The other option is to have a polling type of event loop (which is what games usually do), but I don't know if wx supports that. Also, you would not want that anyway for your editor.
Hope this helps somehow.
Matthew
Thanks matthew180 and all. Very helpfull.
I think I'm not going to use SDL, I don't need sound for my level editor and timing and events can be provided by wxwidgets.
@matthew180 or any other: I'm curious, how do you design menus and UI? coding it or do you use any other program?
Thanks a lot.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Just to add on what others said, the following articles will help you create an OpenGL canvas, catch events and render in a loop :
http://wiki.wxwidgets.org/Making_a_render_loop
http://wiki.wxwidgets.org/WxGLCanvas#wxGLCanvas_sample
About coding GUIs or using an editor, I guess it's a matter of personal preference wxFormBuilder seems quite good, though in general I code my GUIs by hand, the old-school way
http://wiki.wxwidgets.org/Making_a_render_loop
http://wiki.wxwidgets.org/WxGLCanvas#wxGLCanvas_sample
About coding GUIs or using an editor, I guess it's a matter of personal preference wxFormBuilder seems quite good, though in general I code my GUIs by hand, the old-school way
Thanks Auria, that is very usefull.Auria wrote:Just to add on what others said, the following articles will help you create an OpenGL canvas, catch events and render in a loop :
http://wiki.wxwidgets.org/Making_a_render_loop
http://wiki.wxwidgets.org/WxGLCanvas#wxGLCanvas_sample
About coding GUIs or using an editor, I guess it's a matter of personal preference wxFormBuilder seems quite good, though in general I code my GUIs by hand, the old-school way
I would like the easiest way to create my UI, but I don't know if programs like wxFormBuilder are compatible with OpenGL canvas (I'm a wxBeginner). Can I create a UI with menus and buttos and the main area a opengl animation using wxFormBuilder?
By the way, apart from wxWidgets sampls, do you know any other program which uses wx and opengl?
Thanks!
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
About wxFormBuilder + wxGlCanvas, see here : http://forum.wxformbuilder.org/index.ph ... topic=36.0
In short, it's not officially supported, but you can do everything else in wxFB and then add the Gl canvas by hand.
In short, it's not officially supported, but you can do everything else in wxFB and then add the Gl canvas by hand.
-
- In need of some credit
- Posts: 9
- Joined: Tue Jul 31, 2007 5:01 pm
- Contact:
Actually, I have not quite figured it out yet myself. I'm doing the emulator in wx primarily because I'm making a "programmer's" emulator which will allow single stepping, access to all the CPU registers, RAM, the ability to change *ROM*, on the fly assembly, etc., so I need a ton of UI stuff.riruilo wrote: @matthew180 or any other: I'm curious, how do you design menus and UI? coding it or do you use any other program?
Thanks a lot.
The GLcanvas is only for the display and I'm thinking the debug window will be separate from the GLcanvas. I'm still not sure where I'm going to put the menu, toolbar, status bar, and other things. In the same window with the GLcanvas makes sense until you invoke the debug window.
Matthew
Interesting.Auria wrote:About wxFormBuilder + wxGlCanvas, see here : http://forum.wxformbuilder.org/index.ph ... topic=36.0
In short, it's not officially supported, but you can do everything else in wxFB and then add the Gl canvas by hand.
Bt the way, Is there any other program like wxFormBuilder (I don't care if I have to pay) with better opengl support?
(note: I'm going to use codeblocks)
Thanks a lot, all of you are very helpful for me.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Other GUI builders to check are wxSmith (inside Code::Blocks), wxGlade (somewhat outdated), and DialogBlocks (http://www.dialogblocks.com/, commercial) - i think windows wxDev-C++ includes a GUI builder for wx too.riruilo wrote:Interesting.Auria wrote:About wxFormBuilder + wxGlCanvas, see here : http://forum.wxformbuilder.org/index.ph ... topic=36.0
In short, it's not officially supported, but you can do everything else in wxFB and then add the Gl canvas by hand.
Bt the way, Is there any other program like wxFormBuilder (I don't care if I have to pay) with better opengl support?
(note: I'm going to use codeblocks)
Thanks a lot, all of you are very helpful for me.
-
- Experienced Solver
- Posts: 72
- Joined: Fri Feb 20, 2009 7:13 pm
- Location: $(#wx)\src