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

Author Topic: Nothing drawing to screen  (Read 3307 times)

0 Members and 1 Guest are viewing this topic.

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
Nothing drawing to screen
« on: July 02, 2016, 04:46:22 pm »
I think somethings wrong with my Game loop.   I set everything up as it should be; Clear screen, Draw stuff, Display but it doesn't seem to be working.  I'm trying to work with classes, not going so well. It runs, the window opens and clears to white or whatever I set it to. 



cbEngine.cpp
#include "cbEngine.h"

cbEngine::cbEngine(int screenWidth, int screenHeight)
: mWindow(sf::VideoMode(screenWidth, screenHeight, 32), "App")

{


}

cbEngine::~cbEngine()
{
    //dtor
}

sf::RenderWindow& cbEngine::getWindow()
{
    if (runonce == true){
    std::cout << "Window Created" << std::endl;
    }

   return  mWindow;
}
sf::Event& cbEngine::getEvent(){
    return e;
}
void cbEngine::eventLoop(sf::RenderWindow &window, sf::Event event){
    if(runonce == true){
    std::cout << "Event Loop Initialized" << std::endl;
}
    while(window.pollEvent(event)){
        if(event.type == sf::Event::Closed){
            window.close();
            std::cout << "Window Exited by User." << std::endl;
        }

    }
}
void  cbEngine::runGame(sf::RenderWindow &window){
    stateManager sManager; //Create instance of stateManager class
    splashScreen splaScreen;
    splaScreen.setText();
    test.setFillColor(sf::Color::Red);
    test.setScale(sf::Vector2f(80,80));
    while(window.isOpen()){
            if (runonce == true){
            std::cout << "Window open" << std::endl;
            }
            //---Do Only if Debugging---//
    // Check to see if runonce is true; if true output to console that game is starting. //
    while (debug == true){
        if (runonce != false){
            std::cout << "Starting game..." << std::endl;
            runonce = false;
        }
        break;
    }
    // End of Debug Section //

    // Loop Structure 1.Clear window (Color = black) 2. Call stateManager 3. Display window //
    eventLoop(window, e); // Call event loop Initialize it with window and Event object
    window.clear(sf::Color::White); //Clear window black
    //sManager.selectState(getWindow());// Section not working WIP
    window.draw(test);
    window.display(); // Display everything to screen
    }
}




 
cbEngine.h
class cbEngine
{
private:

        //Declare Core Variables
        sf::RenderWindow mWindow;  //Create Base window object
        sf::Event e; // Initialize system event object
        bool runonce = true; // Boolean for running testing conditions only once (otherwise they'd run non stop alongside window.)
        bool debug = 1; //If Debug True certain conditions will be met and testing variables will be output to screen(Exclusive to Engine class)
        sf::RectangleShape test;  //Rectangleshape test
public:
        cbEngine(int screenWidth, int screenHeight); // Initialize Engine with integer screenWidth, screenHeight
        virtual ~cbEngine();
        //Declare core functions//
        //----------------------//
        sf::RenderWindow &getWindow();  //Returns main copy of window object
        sf::Event &getEvent();  //Returns main copy of event object
        void runGame(sf::RenderWindow &window); // Game Loop Runs through logic and displays everything to window
        void eventLoop(sf::RenderWindow &window, sf::Event event); //Runs through events


        //---End Declaration---//

    protected:

    private:
};

#endif // CBENGINE_H
 

#include "includes.h"

int main(){

    cbEngine Engine(800, 600);

    std::cout << "Main" << std::endl;
    Engine.runGame(Engine.getWindow());


    return 0;
}
« Last Edit: July 02, 2016, 05:05:46 pm by Sianide »
Noob C++ Programmer.

Erdrick

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
    • Email
Re: Nothing drawing to screen
« Reply #1 on: July 02, 2016, 04:59:31 pm »
Hi,

The code example you provided seems to be incomplete, what does your main cpp look like and what are you trying to draw?


I see you are trying to draw test, but what is test?
window.draw(test);
 

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
Re: Nothing drawing to screen
« Reply #2 on: July 02, 2016, 05:07:04 pm »
Hi,

The code example you provided seems to be incomplete, what does your main cpp look like and what are you trying to draw?


I see you are trying to draw test, but what is test?
window.draw(test);
 

The test variable is a sf::RectangleShape.  I've tried drawing text too.  I added code to set it and posted all of the cbEngine.cpp file.
Noob C++ Programmer.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Nothing drawing to screen
« Reply #3 on: July 02, 2016, 05:29:45 pm »
A rectangle shape's initial size is 0x0 and you are only setting the scale as far as we can see so you're scaling something that doesn't have any size so it will always have no size.

I get the feeling that this thread - in particular, this post - is going to be useful for you to get your problem fixed.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
Re: Nothing drawing to screen
« Reply #4 on: July 02, 2016, 05:33:20 pm »
Aha!  :-[ fixed it... I was indeed using the wrong set function for setting the size.
Noob C++ Programmer.