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.


Topics - nogoodname

Pages: [1]
1
General / SFML CMake error
« on: November 10, 2019, 06:18:19 pm »
I'm trying to build SFML with CMake using this tutorial.

Now I've managed to make the makefile with CMake.

However if I tried to build SFML using the "mingw32-make install" command I get this error.

Code: [Select]
[  1%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.
obj
'C:\PROGRA~1\MinGW\MINGW' is not recognized as an internal or external command,
operable program or batch file.
src\SFML\System\CMakeFiles\sfml-system.dir\build.make:62: recipe for target 'src
/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj' failed
mingw32-make[2]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj]
Error 1
CMakeFiles\Makefile2:215: recipe for target 'src/SFML/System/CMakeFiles/sfml-sys
tem.dir/all' failed
mingw32-make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

2
General discussions / SFML Book order
« on: August 29, 2019, 12:20:57 am »
Hello, I would like to know which SFML book should I read first, and which order should I read them.

3
Graphics / A single draw call severely slows thing down
« on: July 30, 2019, 10:46:38 pm »
I'm currently trying to make a simple bullet hell game, and I've noticed that a single draw call slows things down a lot if there's a lot of vertices, and I'm not sure how to fix it.

I've made this simple sample version, to illustrate the issue.
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <chrono>
#include <iostream>
#include <memory>
static const sf::IntRect rect = {0,0,64,64};
static const sf::Vector2f initPos = {400,150};
class Bullet {
public:
    Bullet(sf::Vector2f vel_) : velocity{vel_} {
        vertices[0].texCoords = sf::Vector2f{0,0};
        vertices[1].texCoords = sf::Vector2f{64,0};
        vertices[2].texCoords = sf::Vector2f{64,64};
        vertices[3].texCoords = sf::Vector2f{0,64};
        for(size_t i=0; i<4; ++i)
            vertices[i].position = initPos + vertices[i].texCoords;
        vertices[4] = vertices[0];
        vertices[5] = vertices[2];
    }
    void update() {
        for(size_t i=0; i<6; ++i) {
            vertices[i].position += velocity;
        }
    }
    sf::Vertex* getVertices() {
        return vertices;
    }
private:
    sf::Vertex vertices[6];
    sf::Vector2f velocity;
};
int main() {
    constexpr size_t TOTAL_BULLETS = 20000;
    constexpr float pi = 4*std::atan(1);
    std::unique_ptr<Bullet> bullets[TOTAL_BULLETS];
    sf::VertexArray bulletVertices{sf::Triangles,TOTAL_BULLETS*6};
    sf::Texture tex;
    //tex.loadFromFile("bullets.png");
    for(size_t i=0; i<TOTAL_BULLETS; ++i) {
        float angle = 2*pi * static_cast<float>(i)/TOTAL_BULLETS;
        auto vel = sf::Vector2f{std::cos(angle),std::sin(angle)} * 1.0f;
        bullets[i] = std::make_unique<Bullet>(vel);
    }
    sf::RenderWindow window(sf::VideoMode(800,600), "Test");
    while( window.isOpen() ) {
        auto tp = std::chrono::steady_clock::now();
        sf::Event event;
        while( window.pollEvent(event) ) {
            switch(event.type) {
            case sf::Event::Closed:
                window.close();
            break;
            default:
            break;
            }
        }
        for(size_t j=0; j<TOTAL_BULLETS; ++j) {
            bullets[j]->update();
            auto vertice = bullets[j]->getVertices();
            for(size_t i=0; i<6; ++i)
                bulletVertices[j*6+i] = vertice[i];
        }
        window.clear();
        window.draw(bulletVertices,&tex); //This line slows things down a lot
        window.display();
        auto dur = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now()-tp);
        std::cout<<"Frame takes: "<< dur.count() <<"microseconds.\n";
    }
    return 0;
}
 

The main point of interest is line 64, which is:
window.draw(bulletVertices,&tex); //This line slows things down a lot
 
This draws 120,000 vertices, or 40,000 triangles. By commenting it out, I've noticed that the program becomes a lot faster. (When uncommented, the frame time is about 45,000 microseconds, and commenting makes it becomes about 5,000 microseconds.)

Pages: [1]
anything