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

Author Topic: Is there a GetError() in sfml?  (Read 10367 times)

0 Members and 1 Guest are viewing this topic.

nomonkeybusiness

  • Newbie
  • *
  • Posts: 11
    • View Profile
Is there a GetError() in sfml?
« on: February 24, 2009, 01:32:45 pm »
Hi all! I'm new to the forum, and new to SFML.
I am studying at Gotland University, where I study to become a game programmer. I have previously used SDL to build games, and I think I have a decent knowledge of C++.
Anyhow. I am just getting started with SFML, and I'm wondering wether there is a function similar to SDL's "SDL_GetError()" wich returns a const char*, containing a description of the last error that occured. So..is there?
Thanks

/Christoffer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Is there a GetError() in sfml?
« Reply #1 on: February 24, 2009, 02:10:26 pm »
Nope
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Is there a GetError() in sfml?
« Reply #2 on: February 24, 2009, 02:49:46 pm »
Errors are written on the standard error output (std::cerr).
Laurent Gomila - SFML developer

nomonkeybusiness

  • Newbie
  • *
  • Posts: 11
    • View Profile
Is there a GetError() in sfml?
« Reply #3 on: February 24, 2009, 03:57:59 pm »
Yes, i just noticed, thank you ;)

nomonkeybusiness

  • Newbie
  • *
  • Posts: 11
    • View Profile
Is there a GetError() in sfml?
« Reply #4 on: February 24, 2009, 04:00:14 pm »
While we're on the subject of comparing SDL and SFML.
I'm building a basic framework, and I'm having a "drawImage()" in my cRenderTools class.
Is there any way of obtaining the renderwindow to draw on, from an outside class without having to send it there via function arguments?
Like sdl's SDL_GetVideoSurface() ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Is there a GetError() in sfml?
« Reply #5 on: February 24, 2009, 04:15:17 pm »
Quote
Is there any way of obtaining the renderwindow to draw on

And which one is it? In SFML you can have multiple render windows at the same time.
Laurent Gomila - SFML developer

nomonkeybusiness

  • Newbie
  • *
  • Posts: 11
    • View Profile
Is there a GetError() in sfml?
« Reply #6 on: February 24, 2009, 04:17:32 pm »
Oh. Didn't know that. Well, it seems kind of...not good to initialize a new renderwindow for the purpose of drawing stuff on, so a would like to obtain the main renderwindow, the one that I initialize in my cApp-class.

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Is there a GetError() in sfml?
« Reply #7 on: February 25, 2009, 08:46:47 am »
Quote
...not good to initialize a new renderwindow for the purpose of drawing stuff on, so a would like to obtain the main renderwindow, the one that I initialize in my cApp-class.


1. Make your own renderwindow derived singleton class for main render target and use something like this: MainRenderWnd::getInstance().whatever()
2. Use global variable if you are stuck at C style.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Is there a GetError() in sfml?
« Reply #8 on: February 26, 2009, 08:39:07 am »
Quote from: "dunce"
1. Make your own renderwindow derived singleton class for main render target and use something like this: MainRenderWnd::getInstance().whatever()
2. Use global variable if you are stuck at C style.

Uhm.. In my opinion both suggestions aren't really good. Singletons should be used *extreme* rarely. It's better to give references to a RenderTarget  instead making everything dependent on that one singleton.
And second, do never ever use global variables. I'd be fine if C++ didn't allow them. ;)

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Is there a GetError() in sfml?
« Reply #9 on: February 26, 2009, 02:19:32 pm »
Quote from: "Tank"

And second, do never ever use global variables. I'd be fine if C++ didn't allow them. ;)


And global accessor?
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Is there a GetError() in sfml?
« Reply #10 on: February 26, 2009, 11:51:23 pm »
Global accessors are global variables wrapped into an accessor function. :) Why don't just encapsulate stuff into something where it belongs to? Nothing needs to be "just there".

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Is there a GetError() in sfml?
« Reply #11 on: February 27, 2009, 02:18:20 pm »
And how will you desing a game with Graphics. Audio, Network, Game engine without global accessor? All objects need to use these module and the simplest (and fastest) way to do that is via global accessor.

"Global" -> "Static" don't exist for nothing.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Is there a GetError() in sfml?
« Reply #12 on: February 28, 2009, 01:59:02 am »
Quote from: "Daazku"
And how will you desing a game with Graphics. Audio, Network, Game engine without global accessor? All objects need to use these module and the simplest (and fastest) way to do that is via global accessor.
The fastest, no. The simplest, yes. But only in the short term. The dependencies you create can become your doom. For example graphics: You don't need them everywhere. Not at all. You can let a single or a few classes handle graphics and call their methods with logic parameters. Creating a sf::Sprite and instantly drawing it everywhere something needs to be drawn might be the wrong way...

Quote from: "Daazku"
"Global" -> "Static" don't exist for nothing.
Not for nothing. But backward compatibility is one of the reasons.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Is there a GetError() in sfml?
« Reply #13 on: February 28, 2009, 01:04:20 pm »
I would instead keep global variables in a namespace, you know like for things that don't need to be objects.

Like an ImageManager, though it needs two dynamic arrays to keep track of image and the name of image. Those I would keep global but only the functions within the namespace would be allowed to use them.

Like I have a "private" function in the namespace called "AllocData" that is not declared in the header file and it allocates the arrays. And thne the only function used outside is "sf::Image * GetImage(const char * name)". If your not going to use global here, would you instead place them in the GetImage function as a static variable?

I would say global variables is just a taboo by teachers and books. It's still Not everything needs to be objects, it only makes the application slower, so if it can be designed as not an object would be faster and better.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Is there a GetError() in sfml?
« Reply #14 on: February 28, 2009, 03:22:03 pm »
Quote
"Global" -> "Static" don't exist for nothing.

Statics don't imply being global, at least not being in any global namespace.

IMHO Nexus is absolutely right. You create a lot of dependencies, thus writing code that is far away from being modular. This is something that's often done wrong with games, in my opinion. Why should classes like "Weapon" or "Player" draw themselves? You should rather write classes that *use* those, e.g. for displaying or sending stuff over the network.

Quote
I would instead keep global variables in a namespace, you know like for things that don't need to be objects.

Nothing "needs" to be an object, but it's just more logical, especially in terms of object oriented programming. Why doesn't your ImageManager belong to something more specific? Like a Game class or Gamestate class or whatever? I can't understand why resource managers are just "there" and don't belong to anything. That's a reason why I dislike singletons, and your design is a kind of singleton.

Quote
I would say global variables is just a taboo by teachers and books. It's still Not everything needs to be objects, it only makes the application slower, so if it can be designed as not an object would be faster and better.

There's a reason why teachers and books (also good books, for example by Bjarne Stroustrup) teach you that you shouldn't use such designs. There's also a reason why you shouldn't use "goto". Mostly people just don't know the reason and think it's only a "programmer taboo", but it isn't.
Not everything should belong to an object, that's true, but only for modularity reasons. For example, you should not write overloading functions for operator<< using ofstreams as a member. And please show up where your method is somewhat faster than *elegant* C++ code. The difference is neglectable. And if you've got a reason to produce more dirty code, you can still do that when performance penalties occure, but not by pre-optimization.

 

anything