Hello guys, I''ve actually been looking over a few things, and think there''s a package we can add to wxRuby, utilising Ruby code, and 1 additional extension. I think it would proabbly be best to add this package to wx_sugar for now, but the idea, is incorperating SDL into wxRuby through, what I like to call, wxSDL. I''ve seen a few posts on here from people who want to do Graphics Drawing for Games, and such. And with some review of previous efforts to incorperate SDL into wxWidgets through C++, I think this would be an excellent Idea in which to incorperate into our stuff. The basic idea behind it, is to utilize SDL for all the drawing functions, mainly geared towards drawing on a SDL Surface, then retriving the data from the SDL Surface (SDL_pixels, or utilizing Ruby/SDL SDLSurface#pixels), then creating an Wx::Image from that, then utitlizing Wx::Bitmap or even draw_image() to draw the Bitmap to the screen in the final displaying of the image data. I think this would be a great way to enhance wxRuby, and also show of ways in which to incorperate outside libraries into wxRuby, without having to nesscarly write an extension in which to do it. What do you guys think? Add as a library into wx_sugar, or create a Ruby Tutorial? L8ers, -- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-development/attachments/20080216/421a2aab/attachment.html
Hi Mario Mario Steele wrote:> The basic idea behind it, is to utilize SDL for all the drawing > functions, mainly geared towards drawing on a SDL Surface, then > retriving the data from the SDL Surface (SDL_pixels, or utilizing > Ruby/SDL SDLSurface#pixels), then creating an Wx::Image from that, > then utitlizing Wx::Bitmap or even draw_image() to draw the Bitmap to > the screen in the final displaying of the image data.Sounds interesting. I don''t know much about SDL - sounds like it overlaps with wxRuby quite a bit. Does it have much better/faster drawing routines? I guess the first step would be to write it up as a tutorial and then if there''s useful generic glue code to add, we could easily add it to wxSugar. cheers alex
Hey Alex, That''s actually what I''m working on right now, is to create a sample first, to prove the ideas behind it, utilizing Ruby/SDL, and wxRuby, to ensure that everything works. So far, I''m not quite there yet. But I will be working on it some more today to see if I can get it to work. L8ers, On 2/18/08, Alex Fenton <alex at pressure.to> wrote:> > Hi Mario > > Mario Steele wrote: > > The basic idea behind it, is to utilize SDL for all the drawing > > functions, mainly geared towards drawing on a SDL Surface, then > > retriving the data from the SDL Surface (SDL_pixels, or utilizing > > Ruby/SDL SDLSurface#pixels), then creating an Wx::Image from that, > > then utitlizing Wx::Bitmap or even draw_image() to draw the Bitmap to > > the screen in the final displaying of the image data. > Sounds interesting. I don''t know much about SDL - sounds like it > overlaps with wxRuby quite a bit. Does it have much better/faster > drawing routines? > > I guess the first step would be to write it up as a tutorial and then if > there''s useful generic glue code to add, we could easily add it to > wxSugar. > > cheers > alex > > > _______________________________________________ > wxruby-development mailing list > wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-development/attachments/20080219/f1a49297/attachment-0001.html
Hey Again. Alright, I''ve finally implemented a Demo of what I was looking at. And my god, does it make a difference. The sample that I created, basically is meant to be a per pixel drawing setup. I''ve worked it over, looking at a few things, and tested it against the original C++ Demo, that someone created for a way to implement SDL with wxWidgets. Now, the C++ Program has definate speed enhancements, and runs quite a bit faster, however, comparing my implementation of wxSDL that I created, compared to using a native wxBitmap setup, shows drastic changes. wxBitmap utilizing DC Drawing, is 100 times slower. The time it takes for wxBitmap to draw 1 frame, wxSDL has drawn atleast 15 to 30 frames. But compare that to the C++ Example, it''s proabbly running 50 or 60 FPS. So I can definatly see some advantages to creating a wxSDL library. I''m going to include the two samples for those who want to look at it. But I will also be posting them on the Wiki, with a full break down of the code, following much the same way as the original Example Tutorial followed. You can find the download of the C++ here: http://code.technoplaza.net/wx-sdl/part1/wx-sdl.zip There''s other advantages, as we can use SDL for playing Music and Videos as well. Might be a great replacement for MediaCtrl all together. Enjoy, and tell me what you guys think. L8ers, PS: wx-sdl requires Ruby/SDL in order to work. On 2/19/08, Mario Steele <mario at ruby-im.net> wrote:> > Hey Alex, > > That''s actually what I''m working on right now, is to create a sample > first, to prove the ideas behind it, utilizing Ruby/SDL, and wxRuby, to > ensure that everything works. So far, I''m not quite there yet. But I will > be working on it some more today to see if I can get it to work. > > L8ers, > > On 2/18/08, Alex Fenton <alex at pressure.to> wrote: > > > > Hi Mario > > > > Mario Steele wrote: > > > The basic idea behind it, is to utilize SDL for all the drawing > > > functions, mainly geared towards drawing on a SDL Surface, then > > > retriving the data from the SDL Surface (SDL_pixels, or utilizing > > > Ruby/SDL SDLSurface#pixels), then creating an Wx::Image from that, > > > then utitlizing Wx::Bitmap or even draw_image() to draw the Bitmap to > > > the screen in the final displaying of the image data. > > Sounds interesting. I don''t know much about SDL - sounds like it > > overlaps with wxRuby quite a bit. Does it have much better/faster > > drawing routines? > > > > I guess the first step would be to write it up as a tutorial and then if > > there''s useful generic glue code to add, we could easily add it to > > wxSugar. > > > > cheers > > alex > > > > > > _______________________________________________ > > wxruby-development mailing list > > wxruby-development at rubyforge.org > > http://rubyforge.org/mailman/listinfo/wxruby-development > > > > > > -- > Mario Steele > http://www.trilake.net > http://www.ruby-im.net > http://rubyforge.org/projects/wxruby/ > http://rubyforge.org/projects/wxride/ > http://rubyforge.org/projects/vwmc/ >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-development/attachments/20080219/79e54fc5/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: wx-sdl.rb Type: application/octet-stream Size: 2820 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-development/attachments/20080219/79e54fc5/attachment.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: wx-plain.rb Type: application/octet-stream Size: 2735 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-development/attachments/20080219/79e54fc5/attachment-0001.obj
> wxBitmap utilizing DC Drawing, is 100 times slower. The time it takes for wxBitmap to draw 1 frame, wxSDLI am getting 9-10 fps without any drawing. Have you tried opengl? teki
9-10 fps without any drawing? On 2/19/08, Bela Babik <teki321 at gmail.com> wrote:> > > wxBitmap utilizing DC Drawing, is 100 times slower. The time it takes > for wxBitmap to draw 1 frame, wxSDL > > I am getting 9-10 fps without any drawing. Have you tried opengl? > > teki > _______________________________________________ > wxruby-development mailing list > wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-development/attachments/20080219/dcc60a4a/attachment.html
This is the slow part: for y in 0.. at screen.h do for x in 0.. at screen.w do color = (y * y) + (x * x) + ticks @screen.putPixel(x,y,color) end end Check this: http://pastie.caboo.se/154642 On Feb 20, 2008 3:06 PM, Mario Steele <mario at ruby-im.net> wrote:> 9-10 fps without any drawing? > > > > On 2/19/08, Bela Babik <teki321 at gmail.com> wrote: > > > > > > > > > wxBitmap utilizing DC Drawing, is 100 times slower. The time it takes > for wxBitmap to draw 1 frame, wxSDL > > > > I am getting 9-10 fps without any drawing. Have you tried opengl? > > > > teki > > > > _______________________________________________ > > wxruby-development mailing list > > wxruby-development at rubyforge.org > > http://rubyforge.org/mailman/listinfo/wxruby-development > > > > > > > -- > Mario Steele > http://www.trilake.net > http://www.ruby-im.net > http://rubyforge.org/projects/wxruby/ > http://rubyforge.org/projects/wxride/ > http://rubyforge.org/projects/vwmc/ > _______________________________________________ > wxruby-development mailing list > wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development > >
Hi Mario Mario Steele wrote:> Alright, I''ve finally implemented a Demo of what I was looking at. > And my god, does it make a difference. The sample that I created, > basically is meant to be a per pixel drawing setup.Thanks for investigating this. I tried it and the speed-up is very impressive. I guess this is partly down to SDL being more efficient internally, and partly down to ruby/SDL being a thinner wrapper than that generated by SWIG for DC. I can see that SDL would make a good partner for certain applications - the event handling and controls on the Wx side, with SDL as a specialised drawing & collision canvas. I think this would be a worthy addition to the samples. I wonder whether we could create a dir in the main distro for samples which demonstrate using wxRuby with other libraries. Using Grid or a virtual ListCtrl with sqlite might be another. cheers alex
Hello Bela, Yes, I know this part is the slow part. I mentioned this when I stated that there is a slow down compared to the C++ Version of the code. Your basically assigning a Mathematical Value, that first needs to be evaluated, before the value is assign, then your doing this 320 by 200 times, which means that the mathematical expression (y*y) + (x*x) + ticks is being evaluated 64000 times, as well as the @screen.putPixel() method call. So in an interpreted realm, this is not the most co-efficient way in which to do these calculations. Still, utilizing SDL is still faster, then even Wx::MemoryDC. It would even be faster, if your mainly dealing with drawing shapes, and images onto the SDL Surface, compared to utilizing DC itself alone to write it. As Alex has said, SDL is a lite wrapper, compared with wxRuby which is heavily bogged down by SWIG Conversion stuff to convert Ruby objects into C++ Stuff. On 2/19/08, Bela Babik <teki321 at gmail.com> wrote:> > This is the slow part: > > for y in 0.. at screen.h do > for x in 0.. at screen.w do > color = (y * y) + (x * x) + ticks > @screen.putPixel(x,y,color) > end > end > > Check this: http://pastie.caboo.se/154642 > > > On Feb 20, 2008 3:06 PM, Mario Steele <mario at ruby-im.net> wrote: > > 9-10 fps without any drawing? > > > > > > > > On 2/19/08, Bela Babik <teki321 at gmail.com> wrote: > > > > > > > > > > > > > wxBitmap utilizing DC Drawing, is 100 times slower. The time it > takes > > for wxBitmap to draw 1 frame, wxSDL > > > > > > I am getting 9-10 fps without any drawing. Have you tried opengl? > > > > > > teki > > > > > > _______________________________________________ > > > wxruby-development mailing list > > > wxruby-development at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/wxruby-development > > > > > > > > > > > > > -- > > Mario Steele > > http://www.trilake.net > > http://www.ruby-im.net > > http://rubyforge.org/projects/wxruby/ > > http://rubyforge.org/projects/wxride/ > > http://rubyforge.org/projects/vwmc/ > > _______________________________________________ > > wxruby-development mailing list > > wxruby-development at rubyforge.org > > http://rubyforge.org/mailman/listinfo/wxruby-development > > > > > _______________________________________________ > wxruby-development mailing list > wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-development/attachments/20080220/5827cf32/attachment.html
Mario Steele wrote:> Hello Bela, > > Yes, I know this part is the slow part. I mentioned this when I > stated that there is a slow down compared to the C++ Version of the > code. Your basically assigning a Mathematical Value, that first needs > to be evaluated, before the value is assign, then your doing this 320 > by 200 times, which means that the mathematical expression (y*y) + > (x*x) + ticks is being evaluated 64000 times, as well as the > @screen.putPixel() method call. So in an interpreted realm, this is > not the most co-efficient way in which to do these calculations.Well, also you have set_pen, Pen.new, Colour.new etc within a tight loop. Pen.new in particular is an expensive operation and caching pens in this sort of scenario (as Jay McGavren found with Zyps) can really speed things up. It''s on the Feature Request list that this be done automatically. But all that aside, I think it is definitely also down to the greater speed of SDL vs wxWidgets, and the thinness of the wrapper, so worth pursuing and including alex