Sunday, July 27, 2008

Saya-VE with SDL, experiment 1

I pasted and adapted some code from the wx-sdl project (see link in previous entry) into Saya. I created a new class called SDLPanel (original, heh?), and used it instead of a common wxPanel.

So far, here's how the painting works:

1) Check if the panel has an active SDL_Surface object
// can't draw if the screen doesn't exist yet
if (!m_Screen) {
return;
}
2) Lock the SDL_Surface. This thing is thread-safe!
// lock the surface if necessary
if (SDL_MUSTLOCK(m_Screen)) {
if (SDL_LockSurface(m_Screen) > 0) {
return;
}
}

3) Create an in-memory bitmap (a wxImage) based on a SDL_Surface's memory. Once you got the image, you create a wxBitmap based on the wxImage. I really hope this isn't double-memory copying and that the wxImage uses the actual memory.
// create a bitmap from our pixel data
wxBitmap bmp(wxImage(m_Screen->w, m_Screen->;h,
static_cast{unsigned char *}(m_Screen->pixels), true));

(NOTE: I use braces instead of less than and greater than because the code
is altered by blogger's html tidying routines)
4) Now that we created the bitmap, we can safely unlock the SDL_Surface.
   // unlock the screen
if (SDL_MUSTLOCK(m_Screen)) {
SDL_UnlockSurface(m_Screen);
}
5) The painting is done with standard techniques:
   // paint the screen
wxBufferedPaintDC dc(this, bmp);

For our purposes, the SDL_Surface can be a software bitmap without 3D acceleration, residing in the computer's RAM. In other words, it's a plain and simple memory buffer.

And I had to load a full-fledged multimedia library for a simple in-memory bitmap!?!? C'mon!! But hey, it works :D

Here's the screenshot (note: the little color lines actually vary in real-time, it's cool).


Sweet, isn't it? Too bad I'll have to change the code back to keep working on this.

But from this we can incorporate the VideoOutputDevice class so we can actually display clips and images. This will be a major breakthrough in our editor.

2 comments:

Matthew D. Miller said...

I have used Ubuntu and solely free software for three years now (I had a Windows XP/Fedora Core dual boot for two years before that). Cinelerra is the only free software NLE with the capability I need, but its interface is so terrible that it is painful to use. I just discovered your blog today, but I'm really excited about your project. I'll be subscribing to your blog, so I can follow your progress.

I think a project like this is sorely overdue. There needs to be a free software NLE that is both powerful and user-friendly. I would love to help out in anyway possible. I know Perl and Common Lisp (and some Python) but no C++, so I probably wouldn't be any help programming.

rick_777 said...

Thanks! I really appreciate the feedback. Feel free to comment on the blog anytime.