SFML community forums
Help => Graphics => Topic started by: Ashenwraith on April 17, 2010, 07:49:33 am
-
Hi, I need to transform (scale) an image that will then be saved, but I don't want to draw the sprite and copy the screen pixels.
Is there a way to scale/transform an image without drawing it?
-
Only in SFML 2.
-
Great, that's what I'm using.
Is that Sprite::GetPixel?
Does Sprite need a GetPixelPtr?
-
You have to use sf::RenderImage. It's a kind of RenderWindow that draws to an image.
-
How do I attach it to a sprite without a screen/window?
-
Have you read the documentation first? :P
-
Yes, the doc told me:
sf::Image img;
static_cast<sf::RenderImage>(img);
:wink:
I've just been looking in the src, I have to rebuild the doc with something. I thought the doc was not complete?
What's wrong with this:
sf::Image img(w,h,sf::Color(0,0,0,0));
sf::Sprite sprt(img);
sf::RenderTarget RT;
sf::Renderer rendr(RT);
rendr.SetTexture(img);
sf::RenderImage RI;
RI.create(w,h,32);
sprt.Render(RT,rendr);
img=sprt.GetImage();
img.SaveToFile("img.png");
-
Yes, the doc told me:
sf::Image img;
static_cast<sf::RenderImage>(img);
:wink:
Hum... I really don't think so.
I've just been looking in the src, I have to rebuild the doc with something. I thought the doc was not complete?
The documentation for the sf::RenderImage class is complete. You don't have to build it with doxygen, you can just read it in the header file RenderImage.hpp.
What's wrong with this
Almost everything :lol:
This is the example which is in the documentation:
// First of all: make sure that rendering to image is supported
if (!sf::RenderImage::IsAvailable())
return -1;
// Create a new render-window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Create a new render-image
sf::RenderImage image;
if (!image.Create(500, 500))
return -1
// The main loop
while (window.IsOpened())
{
// Event processing
// ...
// Clear the whole image with red color
image.Clear(sf::Color::Red);
// Draw stuff to the image
image.Draw(sprite); // sprite is a sf::Sprite
image.Draw(shape); // shape is a sf::Shape
image.Draw(text); // text is a sf::Text
// We're done drawing to the image
image.Display();
// Now we start rendering to the window, clear it first
window.Clear();
// Draw the image
sf::Sprite sprite(image.GetImage());
window.Draw(sprite);
// End the current frame and display its contents on screen
window.Display();
}
-
I didn't know you hid tutorials in the headers...
Thanks man, got it workin no prob after that! :D
-
I didn't know you hid tutorials in the headers...
This is just the API documentation. The tutorials for SFML 2 are not written yet ;)
-
It's kind of hard to find which headers/files have example documentation
Can you create a link section or highlight the color a certain way maybe?
-
It's kind of hard to find which headers/files have example documentation
You don't have to "find" anything. When you use a class you just have to look at its header to see its documentation. All SFML public classes are documented (except drawable classes that I'm currently updating). There's one block of comments for evey function, and one big block for the global documentation of the class at the bottom of the header file. That's all.
And if you're lost in the headers you can still generate a clean HTML/CHM output with doxygen.
Can you create a link section or highlight the color a certain way maybe?
Sorry I don't understand. What do you mean?