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 - s4game

Pages: [1]
1
Window / Class for multi-layer sprites rendering
« on: July 05, 2024, 11:14:11 am »
Hello there
I've been trying to create a solution for the ability to regulate at which layer the sprite will be drawn. Basically I created a class that does the same thing as sf::RenderWindow does, except setting the priority in the rendering.
Here is how it looks:

winhndl.h:
#pragma once
#include <SFML/Graphics.hpp>
#include <vector>

class WindowHandler
{
private:
    sf::RenderWindow win;
    std::vector<sf::Drawable> buffer[5];
public:
    WindowHandler(const sf::RenderWindow& window);

    void draw(const sf::Drawable& targ, int priority); // 0 - top priority, 4 - bottom priority
    void render();
    void setView(const sf::View& camera);
};
 



winhndl.cpp:
#include "winhndl.h"

WindowHandler::WindowHandler(const sf::RenderWindow& window)
{
    win.create(window.getSystemHandle(), window.getSettings());
}

void WindowHandler::draw(const sf::Drawable& targ, int priority)
{
    buffer[priority].push_back(targ);
}

void WindowHandler::render()
{
    win.clear();
    for(int i = 4; i >= 0; i--)
    {
        for(const auto& t : buffer[i])
        {
            win.draw(t);
        }
        buffer[i].clear();
    }
    win.display();
}

void WindowHandler::setView(const sf::View& camera)
{
    win.setView(camera);
}
 


But when I build the project I am met with the two errors:
Quote
invalid new-expression of abstract class type 'sf::Drawable'
Quote
static assertion failed: result type must be constructible from input type

I am not even sure if I have chosen the right datatype for buffer array. I have been stuck on this problem for a few days now.

Thanks in advance

2
General / [SOLVED] How to add new class files to CMakeLists
« on: June 16, 2024, 09:00:28 pm »
Hello,
I have been getting fails every time CMake builts the project:
Quote
[main] Building folder: sfml-cmake all
[build] Starting build
[proc] Executing command: D:\Prgrams\CMake\bin\cmake.EXE --build d:/VcProj/sfml-cmake/build --config Debug --target all --
[build] [1/2  50% :: 1.086] Building CXX object CMakeFiles/main.dir/src/main.cpp.obj
[build] [2/2 100% :: 2.083] Linking CXX executable bin\main.exe
[build] FAILED: bin/main.exe
[build] C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C "cd /D D:\VcProj\sfml-cmake\build && D:\Prgrams\CMake\bin\cmake.exe -E copy D:/VcProj/sfml-cmake/build/_deps/sfml-src/extlibs/bin/x64/openal32.dll D:/VcProj/sfml-cmake/build/bin && cd D:\VcProj\sfml-cmake\build" && C:\msys64\ucrt64\bin\c++.exe -g  CMakeFiles/main.dir/src/main.cpp.obj -o bin\main.exe -Wl,--out-implib,libmain.dll.a -Wl,--major-image-version,0,--minor-image-version,0  _deps/sfml-build/lib/libsfml-graphics-s-d.a  _deps/sfml-build/lib/libsfml-window-s-d.a  _deps/sfml-build/lib/libsfml-system-s-d.a  -lopengl32  -lwinmm  -lgdi32  _deps/sfml-src/extlibs/libs-mingw/x64/libfreetype.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/main.dir/src/main.cpp.obj: in function `main':
[build] D:/VcProj/sfml-cmake/src/main.cpp:9: undefined reference to `Game::update()'
[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/VcProj/sfml-cmake/src/main.cpp:10: undefined reference to `Game::render()'
[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/VcProj/sfml-cmake/src/main.cpp:7: undefined reference to `Game::isRunning()'
[build] collect2.exe: error: ld returned 1 exit status
[build] ninja: build stopped: subcommand failed.
[proc] The command: D:\Prgrams\CMake\bin\cmake.EXE --build d:/VcProj/sfml-cmake/build --config Debug --target all -- exited with code: 1
[driver] Build completed: 00:00:02.171
[build] Build finished with exit code 1

But I figure that since my code uses classes from external files, it can only result in a failed build. So the only problem I'm left with is how do I link new CPP and header files to the CMakeLists.txt?

For the reference, here are the contents of main.cpp:
Quote
#include "game.h"

int main()
{
    Game game;

    while(game.isRunning())
    {
        game.update();
        game.render();
    }
 
}



Configuration:
  • Windows 10
  • C++ MinGW 13.1.0
  • CMake template from github
  • VS Code

Thanks in advance

3
General / Cannot Launch or Debug but can Compile [SOLVED]
« on: June 09, 2024, 11:44:38 am »
Hi,

  • Windows 10
  • VS Code
  • C++ MinGW 13.1.0
  • SFML 2.6.1
  • Makefile


I can compile and execute the app all fine, but when I try to launch or debug the cpp file (by CTRL+F5), VS Code always gives me the same error:
Quote
SFML/Graphics.hpp: No such file or directory

I have tried changing the libs to their debug versions, but to no avail.


main.cpp:
Quote
#include <SFML/Graphics.hpp>

int main()
{
    //...

    return 0;
}



tasks.json:
Quote
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\Prgrams\\MinGW\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}


Makefile:
Quote
all: compile linkdebug

compile:
   g++ -c main.cpp -I"D:\Prgrams\SFML\SFML-2.6.1\include" -DSFML_STATIC

link:
   g++ main.o -o main -L"D:\Prgrams\SFML\SFML-2.6.1\lib" -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lfreetype -lwinmm -lgdi32 -mwindows

linkdebug:
   g++ main.o -o main -L"D:\Prgrams\SFML\SFML-2.6.1\lib" -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d -lopengl32 -lfreetype -lwinmm -lgdi32 -mwindows

clean:
   rm -f main *.o



Thanks in advance

Pages: [1]
anything