1
General discussions / New graphics API ready
« on: December 03, 2011, 05:16:17 pm »
I really miss the sf::Sprite::GetSize() and Resize() functions
Did you remove them just for tidiness?
![Sad :(](https://www.sfml-dev.org/forums/Smileys/default/sad.gif)
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
if (FT_Load_Char(face, codePoint, FT_LOAD_FORCE_AUTOHINT) != 0)
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(200, 100, 32), "SFML Window", sf::Style::Default, sf::ContextSettings(32));
sf::Font font;
font.LoadFromFile("verdana.ttf");
sf::Text text("Test abcdefghijkl\nABCDEFGHIJKL\n1234567890",font,12);
// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.GetEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
// Escape key : exit
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
window.Close();
}
window.Clear();
window.Draw(text);
// Finally, display the rendered frame on screen
window.Display();
}
return EXIT_SUCCESS;
}
rim.Draw(spr);
rim.Display();
sf::Sprite rimspr;
rimspr.SetImage(rim.GetImage());
App.Draw(rimspr);
App.Display();
#include <SFML/Graphics.hpp>
int main()
{
// 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
sf::Text text("String test", sf::Font::GetDefaultFont(), 12);
//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);
// Uncomment this line to draw text directly
// window.Draw(text);
// End the current frame and display its contents on screen
window.Display();
}
return 0;
}
Drawing only the visible tiles is straight-forward, even with zooming. As long as you don't use rotation, the view is just an aligned rectangle, just like your tiles (I assume you have an axis-aligned grid of tiles).
#include <SFML/Graphics.hpp>
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Load the sprite image from a file
sf::Image Image;
Image.SetSmooth(false);
if (!Image.LoadFromFile("gui_button_c.png"))
return EXIT_FAILURE;
// Create the sprite
sf::Sprite Sprite(Image);
Sprite.SetSubRect(sf::IntRect(2,0,3,23));
Sprite.Resize(300,23);
Sprite.SetPosition(0.f, 0.f);
// 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 screen
App.Clear(sf::Color::White);
// Display sprite in our window
App.Draw(Sprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}