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

Author Topic: I am getting only white screen when rendering  (Read 6971 times)

0 Members and 1 Guest are viewing this topic.

Viped

  • Newbie
  • *
  • Posts: 3
    • View Profile
I am getting only white screen when rendering
« on: November 20, 2014, 03:48:32 pm »
Hi all,

I am getting only white screen when rendering "outside" of main loop. I have Renderer class where I have render method and I pass sf::renderWindow by reference to there.

Renderer.cpp
#include "Renderer.h"

#include <iostream>

Renderer::Renderer() {
        sf::Texture tex;
        if (!tex.loadFromFile("background.png")) {
                std::cout << "Error loading file \"background.png\"" << std::endl;
        }

        _background.setTexture(tex);
        std::cout << _background.getTexture() << std::endl;
}

void Renderer::Render(sf::RenderWindow &window) {

        window.clear();
        window.draw(_background);
        window.display();
}

Renderer.h
#ifndef __ImpossiblePlatformer_Renderer_h__
#define __ImpossiblePlatformer_Renderer_h__

#include "SFML\Graphics.hpp"

class Renderer {

public:
        Renderer();
        void Render(sf::RenderWindow &window);

private:
        sf::Sprite _background;
};

#endif

And lastly main.cpp
#include "SFML\Graphics.hpp"

#include "Constants.h"
#include "EventHandler.h"
#include "Renderer.h"
#include <iostream>

int main() {

        sf::RenderWindow window(sf::VideoMode(1280, 720), "Impossible platformer VERSION");

        EventHandler eh;
        Renderer renderer;

        while (window.isOpen()) {
                eh.LoopAllKeyEvents(window);

                renderer.Render(window);
        }

        return 0;
}
« Last Edit: November 20, 2014, 04:08:42 pm by eXpl0it3r »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Viped

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: I am getting only white screen when rendering
« Reply #2 on: November 20, 2014, 04:26:26 pm »
Nice. Thanks. That even makes sense now.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: I am getting only white screen when rendering
« Reply #3 on: November 20, 2014, 05:17:00 pm »
By the way:

#ifndef __ImpossiblePlatformer_Renderer_h__
These identifiers are forbidden by the C++ standard. Everything beginning with 2 underscores or underscore and capital letter is reserved for the implementation.

#include "SFML\Graphics.hpp"
You should use forward slashes for portable code, and <> brackets for libraries.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: I am getting only white screen when rendering
« Reply #4 on: November 20, 2014, 05:35:05 pm »
That's not even all. Any identifier containing two consecutive underscores is reserved IIRC, and there are a few other obscure cases as well; but I can't remember them - it's been a while since I last checked the standard.

Viped

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: I am getting only white screen when rendering
« Reply #5 on: November 21, 2014, 08:36:42 am »
Thanks for all the suggestions. I haven't really ever coded anything in C++, but because it's industry standard I decided to give it a try, so all tips are more than welcome.

 

anything