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

Author Topic: simple question from a noob, why doesn't my window appear?  (Read 136 times)

0 Members and 1 Guest are viewing this topic.

alex_h

  • Newbie
  • *
  • Posts: 1
    • View Profile
simple question from a noob, why doesn't my window appear?
« on: December 22, 2024, 02:18:01 pm »
Hello, 

I'm starting to learn C++ and SFML.

I just start  a new program, no errors during compilation, but no window appears during the execution.
Normally, a window with red background should appear.
I don't understand why this isn't the case.

What am I doing wrong?
Thanks for your help !

This my code:

game.hpp

#ifndef GAME_HPP
#define GAME_HPP

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

class Game
{
private:
  sf::RenderWindow *window;

  void initWindow();

public:
  Game();

  virtual ~Game();

  void run();

  void update();
  void render();
};

#endif // GAME_HPP
 

game.cpp
#include "game.hpp"

Game::Game()
{
  this->initWindow();
};

Game::~Game()
{
  delete this->window;
};

// Private functions
void Game::initWindow()
{
  this->window = new sf::RenderWindow(sf::VideoMode(800, 600), "Game", sf::Style::Close | sf::Style::Titlebar);
}

// Public functions
void Game::run()
{
  while (this->window->isOpen())
  {
    this->update();
    this->render();
  }
}

void Game::update()
{
}

void Game::render()
{
  // Clear
  this->window->clear(sf::Color::Red);

  // Display
  this->window->display();
}
 

And on main
#include "game.hpp"

int main()
{
  Game game;
  game.run();

  return EXIT_SUCCESS;
}

 


 

anything