SFML community forums

Help => Graphics => Topic started by: rasen58 on October 22, 2012, 04:44:00 am

Title: Where to put renderwindow
Post by: rasen58 on October 22, 2012, 04:44:00 am
I need to use my sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Title"); in multiple cpps, so I should put it in a header right? and then make an init function that I call as the first thing in main()?

So i tried making a private variable in the header file class, sf::RenderWindow App;
but then how would I add the video mode and title after that in the cpp?

Also, i tried to use the Create function, but it gave me an error that said "no instance of overloaded function sf::RenderWindow::Create matches the argument list" I used App.Create((sf::VideoMode(800, 600, 32), "Asteroid Dodger");
Title: Re: Where to put renderwindow
Post by: masskiller on October 22, 2012, 05:09:10 am
Can't really tell why that happens, since this:

Quote
App.Create((sf::VideoMode(800, 600, 32), "Asteroid Dodger");


Should work well, maybe just for the sake of it, but can you give a bigger piece of code, maybe we could help with a bit more of information.
Title: Re: Where to put renderwindow
Post by: rasen58 on October 22, 2012, 05:21:15 am
init.h
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"

class init
{
public:
        init();
       
private:
        sf::View view;
        sf::RenderWindow App;//(sf::VideoMode(800, 600, 32), "Asteroid Dodger");

}

init.cpp
#include "init.h"

init::init()
{
        //(sf::VideoMode(800, 600, 32), "Asteroid Dodger");
        App.Create((sf::VideoMode(800, 600, 32), "Asteroid Dodger");
       
         

         //view(sf::FloatRect(0.0f, 0.0f, App.GetWidth() + 0.0f, App.GetHeight() + 0.0f));
         view.SetFromRect(sf::FloatRect(0.0f, 0.0f, App.GetWidth() + 0.0f, App.GetHeight() + 0.0f));
         App.SetView(view);
         
         
       
}
Title: Re: Where to put renderwindow
Post by: masskiller on October 22, 2012, 05:24:42 am
Quote
App.Create ( (sf::VideoMode(800, 600, 32), "Asteroid Dodger");

I would like it if it wasn't this. You have an extra parenthesis in that line of code... That shouldn't even compile, which could explain the error you are getting...
Title: Re: Where to put renderwindow
Post by: rasen58 on October 22, 2012, 05:29:27 am
Thank You! -_- I don't know how I didn't see that
Title: Re: Where to put renderwindow
Post by: eXpl0it3r on October 22, 2012, 08:04:57 am
I adivse you to read some more about OOP, because your current code doesn't make any sense... ;)
Title: Re: Where to put renderwindow
Post by: rasen58 on October 23, 2012, 04:12:47 am
What doesn't make sense about it?
Title: Re: Where to put renderwindow
Post by: OniLinkPlus on October 23, 2012, 04:39:08 am
Well, first of all, that's not a complete code sample. By itself, what you posted is completely useless.

Also, you're using a class where just a function would do. Or even better, just put it in main where it belongs.
Title: Re: Where to put renderwindow
Post by: rasen58 on October 30, 2012, 01:36:55 pm
But if I put it in main, I can't use it in my other class where I need it
Title: Re: Where to put renderwindow
Post by: masskiller on October 30, 2012, 02:49:19 pm
You don't really need it there, else you would just need one whole bunch of functions in order to pass drawables in to the window loop then, it's very unpractical... You can handle game states as a wholly different class for ease of use once everything is more complete, but until then keep everything at a state where it is easily testable and not the contrary.