SFML community forums

Help => Window => Topic started by: Chay Hawk on August 18, 2014, 06:11:19 am

Title: Window won't show when passed from struct
Post by: Chay Hawk on August 18, 2014, 06:11:19 am
I am trying to put my window in a struct, I made this file as a test as my other file was huge, the program compiles but the window never appears, what's going wrong?

#include <iostream>
#include <SFML/Graphics.hpp>

using namespace std;

struct Str
{
    Str(sf::RenderWindow& window, sf::VideoMode& vidM);

    sf::RenderWindow& window;
    sf::VideoMode& vidM;
};

Str::Str(sf::RenderWindow& window, sf::VideoMode& vidM): window(window), vidM(vidM)
{

}

void MAIN(Str &str);

int main()
{
    sf::RenderWindow win;
    sf::VideoMode vMode;

    Str str(win, vMode);

    MAIN(str);
}

void MAIN(Str &str)
{
    str.window;
    str.vidM.height = 800;
    str.vidM.width = 600;
    str.window.setTitle("Window");

    while(str.window.isOpen())
    {
        str.window.clear();
        sf::Event event;
        while(str.window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                {
                    str.window.close();
                }
            }
        }
        str.window.display();
    }
}
 
Title: Re: Window won't show when passed from struct
Post by: dabbertorres on August 18, 2014, 06:16:50 am
At first glance, you're never calling create on the window.
Title: Re: Window won't show when passed from struct
Post by: Chay Hawk on August 18, 2014, 06:22:59 am
ah, i see, so what do I put in it? when I try to do:

str.window.create(str.vidM(700, 800), str.window.setTitle("window"));

It gives me errors

C:\Users\thund_000\Desktop\Pass Render Wimdpw\main.cpp|34|error: no match for call to '(sf::VideoMode) (int, int)'|
Title: Re: Window won't show when passed from struct
Post by: Chay Hawk on August 18, 2014, 06:30:47 am
nevermind I got it, finally after 45 minutes.