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

Author Topic: sf::Window+the create function=errors?  (Read 4760 times)

0 Members and 1 Guest are viewing this topic.

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
sf::Window+the create function=errors?
« on: May 20, 2013, 05:57:59 pm »
Hello to all,
I'm new here  :) and I have a small issue with SFML. Let's say I make a function that draws all my stuff on the window. Good, but if I use sf::RenderWindow in main, I get an error stating that no window was created at the point of the draw function in my function.
In that case I thought of making a global sf:Window and create it inside main. All compiles well until it hits a draw function in main. It then says
error: 'class sf::Window' has no member named 'draw'|.
I'm using CodeBlocks on Windows 7.


All help apreciated.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: sf::Window+the create function=errors?
« Reply #1 on: May 20, 2013, 06:17:34 pm »
Use sf::RenderWindow instead of sf::Window.

Make also sure you re including and linking to SFML 2.0 and not 1.6 :)

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: sf::Window+the create function=errors?
« Reply #2 on: May 20, 2013, 06:30:52 pm »
Oh, I forgot to mention this...
It works if I use sf::RenderWindow globally, but I can't apply anti-aliasing to my program. I know that setSmooth works, but I want native anti-aliasing. Since sf::RenderWindow is called before I can make a sf::ContextSettings variable, I can't apply any setting to my window.
Sorry for not mentioning this earlier.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Window+the create function=errors?
« Reply #3 on: May 20, 2013, 07:07:49 pm »
Oh, I forgot to mention this...
It works if I use sf::RenderWindow globally, but I can't apply anti-aliasing to my program. I know that setSmooth works, but I want native anti-aliasing. Since sf::RenderWindow is called before I can make a sf::ContextSettings variable, I can't apply any setting to my window.
Sorry for not mentioning this earlier.

First do not ever use sf::RenderWindow globally, bad things can happen when you do this  ;)

Why can't you use code like this?
sf::ConextSettings contextsettings([...]);
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", &contextsettings);
 
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: sf::Window+the create function=errors?
« Reply #4 on: May 20, 2013, 08:18:41 pm »
As you said, using sf::RenderWindow globally isn't a good idea and that's the only way the drawing function will pick it up.

Also, n00b question, how can I set contextsettings' anti-aliasing level to, say 4, at declaration. I don't know much about Uint32 and it looks like that's what is used at declaration. I can change it in a function by typing contextsettings.antialiasingLevel=4, but I can't at declaration.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Window+the create function=errors?
« Reply #5 on: May 20, 2013, 08:56:42 pm »
Quote
As you said, using sf::RenderWindow globally isn't a good idea and that's the only way the drawing function will pick it up.

Using sf::RenderWindow globally is not the only way for you to use it in a function. If you think that, then there is something wrong with your function/class design. Try something like...

void DrawSomething(sf::RenderWindow& CurrentWindow)
{
      CurrentWindow.Draw(xxx);
};
 


Quote
I don't know much about Uint32 and it looks like that's what is used at declaration. I can change it in a function by typing contextsettings.antialiasingLevel=4, but I can't at declaration.

I think you should pickup some good reading material on C++ and pay close attention to the data types section. All a Uint32 means is that it is an unsigned integer that takes 32 bits of space in memory. The difference between unsigned and signed is that unsigned ints are >= 0 while signed ints can be negative or positive.

So that means if you look at the documentation you will see

Quote
sf::ContextSettings::ContextSettings    (    unsigned int     depth = 0,
      unsigned int     stencil = 0,
      unsigned int     antialiasing = 0,
      unsigned int     major = 2,
      unsigned int     minor = 0
   )    

Those are the default values. So if you want ant aliasing set to 4 you would use if everything else is default settings...

sf::ConextSettings contextsettings(0, 0, 4, 2, 0);
 
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: sf::Window+the create function=errors?
« Reply #6 on: May 20, 2013, 09:42:03 pm »
Thanks for telling me how to use my window in the draw function. I should've known how to do that.

But the part about the ContextSettings you wrote gives me an error.
I write this in the beginning of my main function:
sf::ContextSettings contextsettings(0, 0, 4, 2, 0);
sf::RenderWindow window(sf::VideoMode(200, 200), "Randum stuffz", &contextsettings);
 

And it spits out this:
Quote
error: invalid conversion from 'sf::ContextSettings*' to 'sf::Uint32 {aka unsigned int}' [-fpermissive]|

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Window+the create function=errors?
« Reply #7 on: May 20, 2013, 10:02:03 pm »
Please read the API documentation. This constructor has an argument between the title and the context settings.
Laurent Gomila - SFML developer

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: sf::Window+the create function=errors?
« Reply #8 on: May 20, 2013, 10:14:03 pm »
Fixed it.
Of course, I forgot the style. Also that '&' before contextsettings in RenderWindow had to be removed.

Thanks for the help.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Window+the create function=errors?
« Reply #9 on: May 20, 2013, 10:15:33 pm »
Yes my bad, I should have checked more closely what I posted. It shows that I don't do this C++ thing that often (give me my .NET  8))

sf::ContextSettings contextsettings(0, 0, 4, 2, 0);
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!",sf::Style::Default, contextsettings);
 
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything