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

Author Topic: Help with renderWindow not displaying  (Read 1582 times)

0 Members and 1 Guest are viewing this topic.

Tall

  • Newbie
  • *
  • Posts: 8
    • View Profile
Help with renderWindow not displaying
« on: May 01, 2017, 10:34:20 pm »
Hi guys, i need help with my project, the renderWindow is not showing anything.

if you need i can post the headers too.

main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Display.h"
#include "Obj.h"
using namespace std;

int main()
{
        Display app;
        Obj obj;

        app.window.setFramerateLimit(60);

        while (app.window.isOpen())
        {
                app.eventsCheck();
               
                app.clear();

                //Game
                obj.logic();
                obj.output();
                obj.draw(app.window);

                app.display();
        }

        return 0;
}
 

display.cpp
#include "Display.h"



Display::Display()
{
        window.create(sf::VideoMode(800, 600), "Ai", sf::Style::Default);
}

void Display::display()
{
        window.display();
}

void Display::clear()
{
        window.clear(sf::Color::White);
}

void Display::eventsCheck()
{
        while (window.pollEvent(event))
        {

                if (event.type == sf::Event::Closed)
                        window.close();
        }
}
 

obj.cpp
#include "Obj.h"

Obj::Obj()
{
        pos.x = 100;
        pos.y = 100;
        cell.scale(sf::Vector2f(1, 1));
        cell.setFillColor(sf::Color::Black);
        cell.setPosition (pos);

        if (!font.loadFromFile("arial.ttf"))
                std::cout << "Errore durante il caricamento del font" << std::endl;

        posOut.setCharacterSize(30);
        posOut.setColor(sf::Color::Black);
        posOut.setPosition(sf::Vector2f(2, 1));
}

void Obj::draw(sf::RenderWindow &window)
{
        window.draw(cell);
        window.draw(posOut);
}

void Obj::logic()
{
}

void Obj::output()
{
        ss << "x." << pos.x << " y." << pos.y;
        posOut.setString(ss.str());
}
 

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Help with renderWindow not displaying
« Reply #1 on: May 01, 2017, 11:21:50 pm »
Is "cell" an sf::RectangleShape object? If so, do you ever set its size?

is "posOut" an sf::Text object? If so, do you ever set its font?

Tall

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Help with renderWindow not displaying
« Reply #2 on: May 02, 2017, 03:41:29 pm »
Quote
Is "cell" an sf::RectangleShape object? If so, do you ever set its size?

is "posOut" an sf::Text object? If so, do you ever set its font?

ty, i totaly forgot to set size