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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JLesage

Pages: [1]
1
General / Re: C++/SFML: display several shapes simultaneously on screen
« on: February 22, 2024, 09:14:16 pm »
I also don't know why certain expressions like vecRec aren't displayed in the code on the forum.



2
General / Re: C++/SFML: display several shapes simultaneously on screen
« on: February 22, 2024, 09:06:49 pm »
I made some change in the code, but the shapes are moving...

#include <SFML/Graphics.hpp>

#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

#include <iostream>

using std::vector;

using std::cout;
using std::cin;
using std::endl;



int main()
{



    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");

    vector<sf::RectangleShape> vecRec(25);

    srand(time(NULL));




    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }


        window.clear();

        for(int i=0; i<vecRec.size();i++){

            int r= rand()%255+1; int g= rand()%255+1; int b= rand()%255+1;
            sf::Vector2f recSize(rand()%40+20, rand()%40+20);
            sf::Vector2f recPos(rand()%760+1, rand()%560+1);

            vecRec[i].setSize(recSize);
            vecRec[i].setPosition(recPos);
            vecRec[i].setFillColor(sf::Color(r,g,b));
            window.draw(vecRec[i]);
        }

        window.display();
    }

    return 0;
}


 


3
General / Re: C++/SFML: display several shapes simultaneously on screen
« on: February 22, 2024, 08:47:08 pm »
Thank you for the reply @kojack. Can you give an example with code, please?

4
General / C++/SFML: display several shapes simultaneously on screen
« on: February 22, 2024, 11:05:51 am »
Hello. I'm a beginner in c++ and I'm learning SFML. I have coded a small program to simultaneously display several shapes of different size, color and position on the screen, but I don't understand why there is just one shape that is displayed when the code is executed. Please help me.

#include <SFML/Graphics.hpp>

#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

#include <iostream>

using std::vector;

using std::cout;
using std::cin;
using std::endl;



int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");

    vector<sf::RectangleShape> vecRec(25);

    srand(time(NULL));

    int r, g, b = rand()%255+1;

    sf::Vector2f recSize(rand()%40+20, rand()%40+20);
    sf::Vector2f recPos(rand()%760+1, rand()%560+1);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();


        sf::RectangleShape rec;
        rec.setFillColor(sf::Color(r,g,b));
        rec.setSize(recSize);
        rec.setPosition(recPos);
        vecRec.push_back(rec);

        /*for(auto& r: vecRec){
            window.draw(r);
        }*/


        for(int i=0; i<vecRec.size();i++){
            window.draw(vecRec[i]);
        }


        window.display();
    }

    return 0;
}
 

5
Graphics / Re: SFML text display problem under Linux
« on: May 10, 2023, 02:22:15 pm »
Thanks for the reply, @eXpl0it3r.

6
Graphics / SFML text display problem under Linux
« on: May 09, 2023, 01:07:26 pm »
Hello. I am learning C++ and SFML under Linux(Pop!_OS 22.04 LTS). I run some code ()to display some text on my window, I have no error when running, but the text does not display. Please help me.

Note: I did the library inclusions and the constants declaration in another file(.hpp).

#include "main.hpp"
 
#include <iostream>
 
sf::Font font;
 
int main(){
 
 
    void gestionEntrees(sf::Event, sf::RenderWindow &window);
 
    void chargerPolice();
 
   
    sf::Text txt;
    txt.setFont(font);
    txt.setString("Hello, World.");
    txt.setCharacterSize(26);
    txt.setFillColor(sf::Color::Blue);
    txt.setStyle(sf::Text::Bold | sf::Text::Underlined);
 
   
 
    sf::RenderWindow window(sf::VideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32), "Mon premier jeu", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);
 
    window.setVerticalSyncEnabled(true);
 
    while(window.isOpen()){
 
        sf::Event event;
        while(window.pollEvent(event)){
            // fermeture de la fenĂȘtre lorsque l&#39;utilisateur le souhaite
            gestionEntrees(event, window);
             
        }
 
       
        window.clear(sf::Color::White);
 
         
       
        window.draw(txt);
 
         
        window.display();
 
    }
 
    return 0;
 
}
 
 
void gestionEntrees(sf::Event event, sf::RenderWindow &window){
    if (event.type == sf::Event::Closed)
        window.close();
}
 
//Load font
void chargerPolice(){
    if (!font.loadFromFile("/usr/share/fonts/opentype/noto/NotoSansCJK-Black.ttc"))
        throw("Erreur de chargement de police");
}
 

7
Window / Title bar display and closing problem
« on: May 06, 2023, 02:05:05 pm »
I'm a beginner in C++ and SFML for game creation under linux(Pop!_OS 22.04 LTS). I tested the code on the official SFML website, everything seems to work but the title bar doesn't display; it's the same with other codes. I need your help, please. Here is an example of a code I tested:
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
 
 
int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML works!", sf::Style::Titlebar);
    sf::Event ev;
 
    while(window.isOpen()){
       
        while(window.pollEvent(ev)){
 
            switch(ev.type){
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::KeyPressed:
                    if(ev.key.code == sf::Keyboard::Escape){
                        window.close();
                        break;
                    }
                default:
                    break;
            }
             
        }
 
        //Render
        window.clear(sf::Color::Blue);
        window.display();
    }
 
    return 0;
}

Pages: [1]
anything