SFML community forums
Help => Graphics => Topic started by: takercena on April 12, 2012, 04:15:15 am
-
I am using rendertexture to stream pixels that are 30 fps. I am following this tutorial
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php#details
However, when I rescale it to higher view area from 640*480 to 1366 * 768, the video is very lag. How to solve this problem?
Second, how to perform anti aliasing on rendertexture?
-
However, when I rescale it to higher view area from 640*480 to 1366 * 768, the video is very lag. How to solve this problem?
Depends on what you do exactly, which we have no idea about.
Second, how to perform anti aliasing on rendertexture?
Anti-aliasing is not supported yet on render-textures, but you can smooth them.
-
Depends on what you do exactly, which we have no idea about.
The way I do it is first, in a loop, I am getting a RGBA feed from camera. Then, I am converting every pixels of one frame, update it to sf:texture(pixels) and finally draw it to window. Is this a correct way?
Is there any other method to perform anti aliasing that you can suggest?
-
The way I do it is first, in a loop, I am getting a RGBA feed from camera. Then, I am converting every pixels of one frame, update it to sf:texture(pixels) and finally draw it to window. Is this a correct way?
This is correct.
But you should show us how you get and convert pixels, it's easy to write inefficient code for this kind of stuff.
-
customTexture.create(640, 480);
window.create(sf::VideoMode(1366, 768, 32), "Rendering Camera", sf::Style::Default, windowSetting);
window.setActive();
customTexture.setSmooth(true);
customSprite.setTexture(customTexture);
customSprite.scale(2.13f,1.6f);
while(window.isOpen())
{
while(window.pollEvent(evt))
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{ window.close(); exit(1);}
if(evt.type = sf::Event::Closed)
window.close();
}
newCam->Update();
for(long int i = 0; i < 640*480; i++)
{
wRGBA[i].r = (unsigned char)newCam->getRGBA(i, 'r');
wRGBA[i].g = (unsigned char)newCam->getRGBA(i, 'g');
wRGBA[i].b = (unsigned char)newCam->getRGBA(i, 'b');
wRGBA[i].a = 255;
}
pixels = (sf::Uint8*)(wRGBA);
customTexture.update(pixels);
window.draw(customSprite);
window.display();
}
-
for(long int i = 0; i < 640*480; i++)
{
wRGBA[i].r = (unsigned char)newCam->getRGBA(i, 'r');
wRGBA[i].g = (unsigned char)newCam->getRGBA(i, 'g');
wRGBA[i].b = (unsigned char)newCam->getRGBA(i, 'b');
wRGBA[i].a = 255;
}
This code looks horribly slow: you're processing every component of every pixel individually, and the getRGBA function taking a pixel index and a char argument for the color component (!) is most likely slower than a direct access.
What API are these functions from?
-
The method is actually return XnRGB24Pixel (OpenNI). Since SFML won't accept RGB, I have to convert it to RGBA first before updating the texture.
-
True. Unfortunately, SFML doesn't accept other pixel formats, and I'm still not sure if I'll extend this in the future.
But what is the type of the newCam instance? Is it a class of yours? If so, can you show the implementation of the Update and getRGBA functions (inconsistent naming convention, by the way)?
-
Update is just an update once each frame (new data) is available and ready to be processed. If there is new data available, the color is retrieved using getRGBA(). http://openni.org/docs2/Tutorial/conc_updating_data.html
-
Where is getRGBA?
-
Where is getRGBA?
http://openni.org/docs2/Tutorial/struct_xn_r_g_b24_pixel.html. I just returning each color respectively.
-
But why a slow function call, instead of a fast direct access?
-
It just my naive implementation of OOP.
-
Well, here you need maximum performances, bothering with intermediate layers of OO just wastes CPU cycles.
And I personnally would find pixels[j].r clearer than newCam->getRGBA(i, 'r').