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

Author Topic: Where to put renderwindow  (Read 2688 times)

0 Members and 1 Guest are viewing this topic.

rasen58

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Where to put renderwindow
« 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");
« Last Edit: October 22, 2012, 04:48:15 am by rasen58 »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #1 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.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

rasen58

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #2 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);
         
         
       
}

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #3 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...
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

rasen58

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #4 on: October 22, 2012, 05:29:27 am »
Thank You! -_- I don't know how I didn't see that

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: Where to put renderwindow
« Reply #5 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... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rasen58

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #6 on: October 23, 2012, 04:12:47 am »
What doesn't make sense about it?

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Re: Where to put renderwindow
« Reply #7 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.
I use the latest build of SFML2

rasen58

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #8 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

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Where to put renderwindow
« Reply #9 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.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

 

anything