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

Author Topic: Window won't display what I code  (Read 3119 times)

0 Members and 1 Guest are viewing this topic.

$lark_sh

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Window won't display what I code
« on: June 17, 2023, 10:16:48 pm »
The window stopped rendering updates made to the code. Here's the code:
#include <SFML/Graphics.hpp>

int main() {
        // create window
        sf::RenderWindow window(sf::VideoMode(900, 500), "SFML EXP");

        sf::CircleShape circle(60);
        circle.setFillColor(sf::Color::Green);
        circle.setOutlineThickness(3);
        circle.setOutlineColor(sf::Color::White);
        circle.setPosition(sf::Vector2f(400, 150));
       
        sf::RectangleShape rect(sf::Vector2f(180, 100));
        rect.setFillColor(sf::Color::Red);
        rect.setOutlineThickness(3);
        rect.setOutlineColor(sf::Color::White);
        rect.setPosition(sf::Vector2f(250, 250));

        sf::ConvexShape triangle;  // convex shape - any shape that has all its vertices pointing outwards
        triangle.setPointCount(3);
        triangle.setPoint(0, sf::Vector2f(450, 200));
        triangle.setPoint(1, sf::Vector2f(350, 330));
        triangle.setPoint(2, sf::Vector2f(550, 330));
        triangle.setFillColor(sf::Color::Cyan);
        triangle.setOutlineThickness(3);
        triangle.setOutlineColor(sf::Color::Magenta);
        // when window is open
        while (window.isOpen()) {
                sf::Event event;
                // look for events
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::EventType::Closed) {
                                window.close();
                        }
                }
                // render loop
                window.clear(sf::Color::Black);
                window.draw(circle);
                //window.draw(rect);
                //window.draw(triangle);
                window.display();
        }
}
 
Look how even after I comment out drawing the rect and triangle the window displays them and changes to the shapes positions also doesn't work they just render at the points I previously assigned them, Here's the image:
apparently I can't upload an image even though it's got the mona lisa icon saying insert image here... Sorry

Thank you for your attentiion !!
« Last Edit: June 17, 2023, 10:26:14 pm by $lark_sh »

Me-Myself-And-I

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Window won't display what I code
« Reply #1 on: June 18, 2023, 05:27:10 am »
You might be having a problem that I commonly have.I don't know the cause of this but if its the problem I think it is you should be able to solve the problem by either deleting the main.o file and rebuilding the whole project.You might be able to fix it by just rebuilding regardless of the .o file.There probably is a better solution but its something you could try.

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Window won't display what I code
« Reply #2 on: June 18, 2023, 07:30:03 am »
If you are using Visual Studio, go into options page and check here:


If these are set wrong, then running a project won't rebuild the project automatically.
Usually VS will pop up a dialog when you try to run but there's an error, asking if you want to run the last working version instead. One option there is to run the old version and never ask again, which changes one of the settings in the picture above.

If you aren't using Visual Studio, it might be something like one of the files has a wrong timestamp so the build system thinks it is newer than the changed source.

$lark_sh

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Window won't display what I code
« Reply #3 on: June 18, 2023, 09:11:54 am »
If you are using Visual Studio, go into options page and check here:


If these are set wrong, then running a project won't rebuild the project automatically.
Usually VS will pop up a dialog when you try to run but there's an error, asking if you want to run the last working version instead. One option there is to run the old version and never ask again, which changes one of the settings in the picture above.

If you aren't using Visual Studio, it might be something like one of the files has a wrong timestamp so the build system thinks it is newer than the changed source.

My VS build settings are same as that image. But, the problem still persists  :(

$lark_sh

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Window won't display what I code
« Reply #4 on: June 18, 2023, 09:22:59 am »
You might be having a problem that I commonly have.I don't know the cause of this but if its the problem I think it is you should be able to solve the problem by either deleting the main.o file and rebuilding the whole project.You might be able to fix it by just rebuilding regardless of the .o file.There probably is a better solution but its something you could try.

Yeah that seems to work for me. Thank you! But my concern is, if this is a recurring issue then working on a project for ex. a game, would be quite the task.