cpluspluscom/ChessPlusPlus

JSON and proper way to load resources

jaredready opened this issue · 13 comments

So, I'm not sure how best to add resources into the grapics.json file. And then once they're there, what's the best to load said resources? I see there's TextureManager and ResourceManager classes, are we supposed to use those? Is using direct SFML to load resources not the right way?

This is in reference to #65

I'll write up a tutorial in the next few hours that everyone can use for future reference.

-Stephen Hall

On Dec 23, 2013, at 10:25 PM, "Jared Ready" notifications@github.com wrote:

So, I'm not sure how best to add resources into the grapics.json file. And then once they're there, what's the best to load said resources? I see there's TextureManager and ResourceManager classes, are we supposed to use those? Is using direct SFML to load resources not the right way?


Reply to this email directly or view it on GitHub.

See this:
https://gist.github.com/Thumperrr/bd3b872038e2eb05796d#file-chesspp_graphics-md

It might be worth putting that into the repo somewhere. I'm out of time for now, though.

LB-- commented

We have a wiki for a reason:
https://github.com/cpluspluscom/ChessPlusPlus/wiki/Graphics-and-You
Also, you put cpp and not C++ after the triple ticks for C++ syntax highlighting ;)

EDIT: Oh, and JSON supports spaces! Away with your ugly underscores :)

Ah, thanks LB.
And yeah, my GitHub flavored markdown is rusty.
I'll leave this issue open for ResidentBiscuit to close, in the event that questions are still unanswered.

Alright so here's what I have, it's not working though. Images are not getting loaded, Just getting the 'missing' image instead.

graphics.json

{
    "chesspp":
    {
        "logo":    "res/img/logo.png",
        "menu":
        {
            "background":   "res/img/main_menu_background.png"
        },
...

StartMenuState

StartMenuState::StartMenuState(Application &app, sf::RenderWindow &display) : AppState(display), app(app)
    {
        // Load and initialize resources
        menuBackgroundTexture = TextureManager::instance().load(gfx_config.spritePath("chesspp", "menu", "background"));
        menuBackground.setTexture(menuBackgroundTexture);

        logoTexture = TextureManager::instance().load(gfx_config.spritePath("chesspp", "logo"));
        logo.setTexture(logoTexture, true);
...

Any idea what I'm doing wrong here?

  • Are the images in the location you say they are?
  • Is the program running at all? I.e., are you seeing white blocks instead of the images?
  • Are your textures references to an sf::Texture?
  • Check the log, in it contains information about what textures are loaded successfully and what ones aren't. Might shed light on why.

you can also check src/gfx/graphics.cpp to see how that deals with images.

It's just displaying the 'missing' X instead of my images.

My sf::Textures are not references. Didn't see they were supposed to.

On Tue, Dec 24, 2013 at 9:58 AM, Thumperrr notifications@github.com wrote:

  • Are the images in the location you say they are?
  • Is the program running at all? I.e., are you seeing white blocks
    instead of the images?
  • Are your textures references to an sf::Texture?
  • Check the log, in it contains information about what textures are
    loaded successfully and what ones aren't. Might shed light on why.


Reply to this email directly or view it on GitHubhttps://github.com//issues/66#issuecomment-31176132
.

LB-- commented

You can't copy textures, you need to take the return of .load() by reference.

Got this working. Made a note on the wiki. The spritePath() method already
appends a "chesspp" to the beginning of the path, so if you pass that in
also you get an invalid path.

On Tue, Dec 24, 2013 at 10:27 AM, LB-- notifications@github.com wrote:

You can't copy textures, you need to take the return of .load() by
reference.


Reply to this email directly or view it on GitHubhttps://github.com//issues/66#issuecomment-31177096
.

I think having spritePath() append "chesspp" to the beginning is counterintuitive and introduces hidden behavior that can be confusing. I'll open an issue for this.

LB-- commented

@Thumperrr it's in the chesspp namespace, if it were in the global namespace it would be counter-intuitive. But we can discuss in the issue.

Even so we should specify it in a call to spritePath. see #67

As far as I'm aware, this issue has been resolved, so i'll go ahead and close it.