G
G
Gotenks2019-02-01 22:40:17
C++ / C#
Gotenks, 2019-02-01 22:40:17

What is each function responsible for?

I apologize in advance for stupid questions, it is important for me to understand what is happening in my code.
The situation is such that it is not always clear to me from the documentation what it says. It is often written in a language that is difficult for a beginner, and if, in addition, in English, then it is difficult to understand anything at all.

The code
#include "pch.h"
#include <iostream>
#include <SFML\Graphics.hpp>

int main()
{
  sf::RenderWindow window(sf::VideoMode(720, 500), "Prompt");
  sf::Texture OneWindow;
  OneWindow.loadFromFile("Fon.jpg");
  
  sf::Sprite OW;
  OW.setTexture(OneWindow);
  OW.setPosition(0, 0);
  while (window.isOpen())
  {
    sf::Event event;
    while (window.pollEvent(event))
    {
      if (event.type == sf::Event::Closed)
        window.close();
    }
    window.clear();
    window.draw(OW);
    window.display();
  }
}

I'm wondering why if you remove the 24th line from this code, then this happens
Effect?
5c549fa64d969863658200.png
What is she responsible for?
We're sort of like drawing a window in the 23rd line, aren't we?
Why do we need line 22? If you remove it, then nothing seems to change.
And why without an event loop (line 17) do we constantly load a window? That is, I hover over the window and it shows like this window is loading, it is loading endlessly ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2019-02-01
@Gotenks

Well, again, we climb into the Internet, into the documentation...
display displays on the screen everything that was "drawn" during the rendering process. For example, we have several stages of "drawing", and we need to show only the final result.

void sf::Window::display ( )
Display on screen what has been rendered to the window so far.
This function is typically called after all OpenGL rendering has been done for the current frame, in order to show it on screen.
clear clears the "drawing" area. Otherwise, everything will be drawn on top of the previous picture. Imagine that you are drawing a second hand on a clock, and the old hand image is not erased.
void sf::RenderTarget::clear ( const Color & color = Color(0, 0, 0, 255) )
Clear the entire target with a single color.
This function is usually called once every frame, to clear the previous contents of the target.
Event handling is already a feature of WinApi. Each user object in Windows has an event queue, and the code must have a function for processing them, if you do not "consume" events (such as keystrokes, cursor movement), the queue "clogs" and such a rigmarole occurs with the loading icon.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question