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

Author Topic: Control RenderWindow from another function.  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

waco001

  • Newbie
  • *
  • Posts: 1
    • View Profile
Control RenderWindow from another function.
« on: March 22, 2013, 08:20:22 pm »
Hi guy,  this may sound as a really simple question, but I have SFML 1.6 and I want to control my RenderWindow from another function...

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;



int main()
{

    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Guessing Game");
    App.SetFramerateLimit(60); //Set FPS limit to 60 FPS
    //Variables
    bool atmainmenu = true;
    //End Variables

    // Start main loop
    while (App.IsOpened())
    {
        printmessage(atmainmenu);
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::M)){

            }
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F)){

            }
        }
        // Display window on screen
        App.Display();

    }
    return EXIT_SUCCESS;
}

void printmessage(bool atmainmenu)
{
    if(atmainmenu){
        //$$$$$$$################# HERE <----
    }
}
 

That is my code, but I want to control 'App' from atmainmenu. Is there anything I have to do? thanks :D

waco001

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Control RenderWindow from another function.
« Reply #1 on: March 22, 2013, 09:39:34 pm »
I know it may seem harsh, but you should really spend a bit of time reading through this: http://www.cplusplus.com/doc/tutorial/

If you don't grasp basic C++, it is not recommended to try SFML yet.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Ruckamongus

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Control RenderWindow from another function.
« Reply #2 on: March 22, 2013, 09:43:03 pm »
I know it may seem harsh, but you should really spend a bit of time reading through this: http://www.cplusplus.com/doc/tutorial/

If you don't grasp basic C++, it is not recommended to try SFML yet.

Specifically, look at references and pointers; both are valid ways to pass the window around. (References being the more "C++" approach and pointers being the more "C" approach.)