Home > Mobile >  SFML image not showing
SFML image not showing

Time:05-06

I came across similar issue however it didn't help me so far: SFML loadFromFile not showing image

the issue:

Using debug build. The the program goes full screen however nothing is showing. The cursor also goes into a blue spinning state as if something is getting processed.

what I tried:

to make sure the debug libs and the release libs are not conflicting.

moving all the *-d-2.dll into a separate folder, and using system PATH variable to reference them.

moving all the *-d.lib and *-d.pdb into a separate folder and setting the linker to reference only that folder for libraries.

setting the additional dependencies to these only:

sfml-graphics-d.lib, sfml-window-d.lib,sfml-system-d.lib, sfml-network-d.lib, sfml-audio-d.lib

I tried adding ways to check for errors in code but have not gotten any errors.

#include "SFML/Graphics.hpp"
#include <iostream>

using std::cerr;

using sf::VideoMode;
using sf::RenderWindow;
using sf::Style::Fullscreen;
using sf::Keyboard;
using sf::Texture;
using sf::Sprite;
using sf::Shape;

int main()
{
    // create video mode object
    VideoMode *vm = new VideoMode(1920, 1080);
    if (vm == NULL) { cerr << "Video mode null\n"; exit(1); }
    // create window
    RenderWindow *window = new RenderWindow(*vm, "Timber!", Fullscreen);
    if (window == NULL) { cerr << "widnow is null\n"; exit(1); }

    // set up background
    // texture object
    Texture textureBackground;
    // load texture onto object
    if (!textureBackground.loadFromFile("../Graphics/background.png"))
    { cerr << "file loading failed!\n"; exit(1); }

    // create sprite object
    Sprite *spriteBackground = new Sprite();
    if (window == NULL) { cerr << "spriteBackground is null\n"; exit(1); }
    // set sprite to the background texture
    spriteBackground->setTexture(textureBackground);
    // set sprite position
    spriteBackground->setPosition(0, 0);

    // main game loop
    while (window->isOpen())
    {
        if (Keyboard::isKeyPressed(Keyboard::Escape))
        {
            window->close();
        }

        window->draw(*spriteBackground);

        // clear everything from last frame
        window->clear();

        // show what we drew
        window->display();
    }

    return 0;
}

CodePudding user response:

I'm not familiar with SFML. But when I tested your code, I got a black screen. The code in while (window->isOpen()){} might be the problem. Because I am able to load the image after replacing the while(){} in the link you posted. Have you tried the code in the link?

PS: I put all the required lib and dll aside the exe.

Used LIB:

sfml-window-d.lib
sfml-system-d.lib
sfml-graphics-d.lib

CodePudding user response:

Check this commit, I'm sure find something helpful https://github.com/anuraghit/timber-man/commit/d95418436894d7d22711dec175ec287efc00bfff#diff-c740d06c2060b02a56a855e4e4d29d1eae6454ec1ebb89d2029421b6de0e5594 also make sure your config is in x86

  • Related