Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SFML2]RenderWindow.DefaultView.ViewPort not Working  (Read 2899 times)

0 Members and 1 Guest are viewing this topic.

felipehenrique

  • Newbie
  • *
  • Posts: 8
    • View Profile
[SFML2]RenderWindow.DefaultView.ViewPort not Working
« on: January 10, 2011, 06:33:18 am »
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:
Code: [Select]
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 ...
Code: [Select]
#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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SFML2]RenderWindow.DefaultView.ViewPort not Working
« Reply #1 on: January 10, 2011, 08:24:44 am »
Read the doc, the viewport is expressed in factors in the range [0 .. 1], not in pixels.

Your C++ code changes the view's source rectangle, not the viewport.
Laurent Gomila - SFML developer