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

Author Topic: My window doesnt have a color  (Read 5437 times)

0 Members and 2 Guests are viewing this topic.

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
My window doesnt have a color
« on: February 18, 2015, 08:19:00 pm »
I know i have posted VERY similar code before, but i accidently deleted the project i was working in, so i had to redo the tutorial. Also, the error is completely different from what i can tell.

Bascially, when i try to make the screen red, its white instead, like if i didnt give it a color.

Game.cpp
#include "stdafx.h"
#include "Game.h"

Game::Game()
{
        sf::RenderWindow _mainWindow(sf::VideoMode(1024, 768, 32), "Pang!");
        _gameState = uninitialized;
        start();
}
void Game::start(void)
{
        if(_gameState != uninitialized)
                return;

        _gameState = Game::playing;

        while(!isExiting())
        {
                gameLoop();
        }

        _mainWindow.close();
}
bool Game::isExiting()
{
        if(_gameState == exiting)
        {
                return true;
        }
        else
        {
                return false;
        }
}
void Game::gameLoop()
{
        sf::Event currentEvent;
        while(_mainWindow.pollEvent(currentEvent))
        {
                switch(_gameState)
                {
                case playing:
                        _mainWindow.clear(sf::Color::Red);
                        _mainWindow.display();

                        if(currentEvent.type == sf::Event::Closed)
                        {
                                _gameState = exiting;
                        }
                }
        }
}

Game.h
#include "stdafx.h"

class Game
{
public:
        Game();
        void start();
private:
        bool isExiting();
        void gameLoop();

        enum GameState{uninitialized, showingSplash, paused, showingMenu, playing, exiting};

        GameState _gameState;
        sf::RenderWindow _mainWindow;
};

When i debug, it stops at
while(_mainWindow.pollEvent(currentEvent))

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: My window doesnt have a color
« Reply #1 on: February 18, 2015, 08:46:23 pm »
Looks like you never changed the value of _gameState to playing.

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: My window doesnt have a color
« Reply #2 on: February 18, 2015, 08:49:08 pm »
I'm not sure if this is directly related to your problem, but your gameloop seems a bit weird to me. Right now you are only clearing and displaying the window if an event happens. Perhaps you want something like this instead?

Code: [Select]
while(_mainWindow.pollEvent(currentEvent))
{
   if(currentEvent.type == sf::Event::Closed)
   {
      _gameState = exiting;
   }
}

switch(_gameState)
{
   case playing:
      _mainWindow.clear(sf::Color::Red);
      _mainWindow.display();
}

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: My window doesnt have a color
« Reply #3 on: February 19, 2015, 11:48:22 am »
I'm not sure if this is directly related to your problem, but your gameloop seems a bit weird to me. Right now you are only clearing and displaying the window if an event happens. Perhaps you want something like this instead?

Code: [Select]
while(_mainWindow.pollEvent(currentEvent))
{
   if(currentEvent.type == sf::Event::Closed)
   {
      _gameState = exiting;
   }
}

switch(_gameState)
{
   case playing:
      _mainWindow.clear(sf::Color::Red);
      _mainWindow.display();
}
Its supposed to be like that. Later, when i get further in the tutorial, i will do different stuff.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: My window doesnt have a color
« Reply #4 on: February 19, 2015, 12:18:23 pm »
It's not only weird or something one can change "later", but it's simply wrong. Rendering doesn't belong into the event loop, so don't do it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: My window doesnt have a color
« Reply #5 on: February 19, 2015, 01:16:19 pm »
It's not only weird or something one can change "later", but it's simply wrong. Rendering doesn't belong into the event loop, so don't do it.
Ok, thanks for telling me. However, it still doesnt change the color. Its as white as it always was.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: My window doesnt have a color
« Reply #6 on: February 19, 2015, 01:24:25 pm »
Looks like you never changed the value of _gameState to playing.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: AW: Re: My window doesnt have a color
« Reply #7 on: February 19, 2015, 01:29:40 pm »
Looks like you never changed the value of _gameState to playing.
1. I never saw that post.
2.
void Game::start(void)
{
    if(_gameState != uninitialized)
        return;

    _gameState = Game::playing; //I did actually, and changing it to _gameState = playing didnt work either

    while(!isExiting())
    {
        gameLoop();
    }

    _mainWindow.close();
}
I have the debugger to back me up. When it comes to the switch statement, it tells me that gamestate indeed is playing.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: My window doesnt have a color
« Reply #8 on: February 19, 2015, 02:29:19 pm »
Since you have the debugger running, does it reach the clear statement?

Is your graphics driver installed/uptodate?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: My window doesnt have a color
« Reply #9 on: February 19, 2015, 02:34:26 pm »
Since you have the debugger running, does it reach the clear statement?

Is your graphics driver installed/uptodate?
Yes, it reaches the clear statement AND the display.

Since ive had it show me a red screen before, i would assume that they are uptodate.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: My window doesnt have a color
« Reply #10 on: February 19, 2015, 02:50:48 pm »
Don't assume, check...

Also what did you change if it worked before?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: My window doesnt have a color
« Reply #11 on: February 19, 2015, 04:44:22 pm »
Don't assume, check...

Also what did you change if it worked before?
Drives updated, still as white as ever. The only thing i recall changing is using the constructor to create the window instead of
_mainWindow.create(stuff);

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: My window doesnt have a color
« Reply #12 on: February 19, 2015, 04:55:48 pm »
Provide a minimal and compilable example of your updated code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: My window doesnt have a color
« Reply #13 on: February 19, 2015, 05:13:29 pm »
You meant from the code that i posted above? I thought you meant the one i tried a week or so ago that i posted somewhere around this forum.
Gave comments to the lines that changed.
#include "stdafx.h"
#include "Game.h"

Game::Game()
{
        sf::RenderWindow _mainWindow(sf::VideoMode(1024, 768, 32), "Pang!");
        _gameState = uninitialized;
        start();
}
void Game::start(void)
{
        if(_gameState != uninitialized)
        {
                return;
        }

        _gameState = playing;

        while(!isExiting())
        {
                gameLoop();
        }

        _mainWindow.close();
}
bool Game::isExiting()
{
        if(_gameState == exiting)
        {
                return true;
        }
        else
        {
                return false;
        }
}
void Game::gameLoop() //Where the actual change happened
{
        sf::Event currentEvent;
        while(_mainWindow.pollEvent(currentEvent)) //No longer contains the rendering
        {
                if(currentEvent.type == sf::Event::Closed)
                        {
                                 _gameState = exiting;
                        }
        }
        switch(_gameState) //Note that i moved this from the while loop
        {
                case playing:
                _mainWindow.clear(sf::Color::Red);
                _mainWindow.display();
        }
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: My window doesnt have a color
« Reply #14 on: February 19, 2015, 05:16:33 pm »
It's not compilable by others on this forum.
Alternatively you could just run an example from SFML. If that works, your code must be bugged.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything