Hello
I was doing some testing with SFML and when I tried to resize the viewport has not worked as she kept the old one.
The code is below:
using System;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;
namespace Example
{
class Program
{
static RenderWindow app;
static void OnClose(object sender, EventArgs e)
{
// Close the window when OnClose event is received
RenderWindow window = (RenderWindow)sender;
window.Close();
}
static void KeyPressed(object sender, KeyEventArgs key)
{
app.SetSize(800, 600);
app.DefaultView.Viewport = new FloatRect(0, 0, 800, 600);
}
static void Main(string[] args)
{
// Create the main window
app = new RenderWindow(new VideoMode(300, 200), "SFML window");
app.Closed += new EventHandler(OnClose);
app.KeyPressed += new EventHandler<KeyEventArgs>(KeyPressed);
// Create a graphical string to display
Font arial = new Font("C:/Windows/Fonts/arial.ttf");
Text text = new Text("Hello SFML.Net", arial);
// Start the game loop
while (app.IsOpened())
{
// Process events
app.DispatchEvents();
// Clear screen
app.Clear();
// Draw the string
app.Draw(text);
// Update the window
app.Display();
}
}
}
}
This same code in C + + work correctly ...
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow App(sf::VideoMode(300, 200), "SFML window");
// Create a graphical string to display
sf::Font Arial;
if (!Arial.LoadFromFile("C:/Windows/Fonts/arial.ttf"))
return EXIT_FAILURE;
sf::String Text("Hello SFML", Arial, 30);
// Start the game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
if (((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
{
App.SetSize(800,600);
App.GetDefaultView().SetFromRect(sf::FloatRect(0,0,800,600));
}
}
// Clear screen
App.Clear();
// Draw the string
App.Draw(Text);
// Update the window
App.Display();
}
return EXIT_SUCCESS;
}
PS: I am working with SFML2