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

Author Topic: [SOLVED] window.draw(sprite) White Screen  (Read 3697 times)

0 Members and 2 Guests are viewing this topic.

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
[SOLVED] window.draw(sprite) White Screen
« on: March 03, 2018, 10:22:41 am »
Hello,

After searching the whole internet, I'm desperately asking for help.
While executing the code below, I'm getting a white screen instead of the texture!
What might be the cause?
I'm not destructing Texture anywhere, file is loaded into the texture...

Thank you anyway! :)

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

using namespace sf;

int main()
{

        VideoMode vm(1280, 720);

        RenderWindow window(vm, "TIMBER_VS17", Style::Default);

        Texture backgroundTexture;

        //DEBUG LOADING TEXTURE FROM FILE//
        if (!backgroundTexture.loadFromFile("graphics/background.jpg"))
        {
                std::cout << "LOG:\tCANNOT OPEN THE FILE\n";
        }
        else if (backgroundTexture.loadFromFile("graphics/background.jpg"))
        {
                std::cout << "LOG:\tFILE LOADED SUCCESSFULLY\n";
        }

        Sprite spriteBackground;
        spriteBackground.setTexture(backgroundTexture);
        spriteBackground.setPosition(0, 0);
       
        while (window.isOpen())
        {
                if (Keyboard::isKeyPressed(Keyboard::Escape))
                {
                        window.close();
                }
        }
       
        window.clear();

        window.draw(spriteBackground);

        window.display();

        return 0;
}
 
« Last Edit: March 03, 2018, 01:17:52 pm by iamsickinmymind »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: window.draw(sprite) White Screen
« Reply #1 on: March 03, 2018, 11:15:43 am »
Have a look at the first code snippet and look closely where draw(), clear() and display() are called ;) (inside or outside of the isOpen() loop)

https://www.sfml-dev.org/tutorials/2.4/graphics-draw.php


AlexAUT

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: window.draw(sprite) White Screen
« Reply #2 on: March 03, 2018, 01:17:41 pm »
Have a look at the first code snippet and look closely where draw(), clear() and display() are called ;) (inside or outside of the isOpen() loop)

https://www.sfml-dev.org/tutorials/2.4/graphics-draw.php


AlexAUT

I can't believe it how stupid I am! :) It seems that other pair of eyes can see things my won't :)
Thank you very much!

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [SOLVED] window.draw(sprite) White Screen
« Reply #3 on: March 03, 2018, 01:24:35 pm »
Happens to all of us from time to time  ::).

Placing the clear/draw/display into the event loop (pollEvent) is another common misstake  ;)


AlexAUT