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

Author Topic: Window won't show when passed from struct  (Read 1425 times)

0 Members and 1 Guest are viewing this topic.

Chay Hawk

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Email
Window won't show when passed from struct
« 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();
    }
}
 

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Window won't show when passed from struct
« Reply #1 on: August 18, 2014, 06:16:50 am »
At first glance, you're never calling create on the window.

Chay Hawk

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Email
Re: Window won't show when passed from struct
« Reply #2 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)'|

Chay Hawk

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Email
Re: Window won't show when passed from struct
« Reply #3 on: August 18, 2014, 06:30:47 am »
nevermind I got it, finally after 45 minutes.

 

anything