Hi,
I'm trying to use SFML with a webcam library (videoInput), but copying data (pixels) from camera buffer to image seems to be very slow - the video is no more than 5fps :-/ The same code written in Allegro runs few times faster. Is it some way to fasten it up? I'm using SFML v.1.6.
Code:
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// Create the main rendering window
App.Create(sf::VideoMode(800, 550, 32), "SFML Graphics");
cam1.Init(640,480);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Clear the screen (fill it with black color)
App.Clear();
cam1.Draw(&App);
// Display window contents on screen
App.Display();
App.SetFramerateLimit(60);
}
return EXIT_SUCCESS;
}
And webcam functions:
int CCamera::Init(int width, int height)
{
if (!VI.setupDevice(device, width, height)) return 1;
VI.setIdealFramerate(device, 25);
w = VI.getWidth(device);
h = VI.getHeight(device);
size = VI.getSize(device);
buffer = new unsigned char[size];
buffer2= new unsigned char[w*h*4];
image.Create(w, h, sf::Color(230, 230, 230));
image.SetSmooth(false);
sprite.SetImage(image);
return 0;
}
void CCamera::Draw(sf::RenderWindow * app)
{
if(VI.isFrameNew(device))
{
//Here I take the buffer of RGB values
VI.getPixels(device, buffer, true, true);
int z=0;
//Transform it into ARGB
for (int u=0; u<w*h*3; u+=3)
{
buffer2[z]=buffer[u];
buffer2[z+1]=buffer[u+1];
buffer2[z+2]=buffer[u+2];
buffer2[z+3]=255;
z+=4;
}
// And this is the problem - loading seems to be so slow
image.LoadFromPixels(w,h,buffer2);
}
app->Draw(sprite);
}