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

Pages: [1] 2 3 ... 24
1
General / Re: Migrating to SFML 3.0 - No sfml-main[-d].lib?
« on: February 17, 2025, 07:01:23 am »
Unlike earlier SFML versions, SFML 3 is provided (and built by default) as static libraries only, not dynamic.
You'll need to change the settings (CMake) and build SFML yourself to get dynamic libraries.

2
Window / Re: Window Poll Event Mechanics
« on: February 01, 2025, 07:59:52 am »
One event can't contain info for several different events. So only one of those ifs will be true for any call to processMenuInputs.

Under the hood, Event::TextEntered happens when SFML receives a WM_CHAR message from Windows. Event::KeyPressed happens when WM_KEYDOWN is received.

When you press a key, the WM_KEYDOWN message is sent. SFML gets it, and calls TranslateMessage (a windows function) which tries to generate a WM_CHAR message and add it to the end of the message queue. So you will always get Event::KeyPressed first, then maybe an Event::TextEntered next time you poll.
(Not all key presses can be converted to text. For example pressing an arrow key or function key won't result in a TextEntered)

3
Graphics / Re: [SOLVED] setTextureRect() not behaving as intended
« on: January 30, 2025, 04:57:23 am »
Strange. Without the size it should be picking this constructor:
explicit Texture(const std::filesystem::path& filename, bool sRgb = false);
But as long as you have it working. :)

4
Graphics / Re: setTextureRect() not behaving as intended
« on: January 30, 2025, 02:50:38 am »
The problem is the last parameter to the texture constructor:
chkIdleText("/Users/me/Documents/Projects/chk/build/bin/chicken_idle.png", false, sf::IntRect({0, 0}, {32, 32}))
The last parameter is which part of the image to load. When you say sf::IntRect({0, 0}, {32, 32}), that means don't load the entire image, just load the first frame. If you make it:
chkIdleText("/Users/me/Documents/Projects/chk/build/bin/chicken_idle.png", false)
then it should work.

5
Graphics / Re: Draw calls for text and performance
« on: January 21, 2025, 12:53:59 am »
If things aren't changing much, you could render rectangles and text into a render texture, then reuse that to render to the screen. This would let you replace any number of draw calls with just 1. But of course if things are moving independent of each other then you'd have to keep regenerating the render texture and lose the benefit.

6
Graphics / Re: [2.6]C# bindings and Text allocation
« on: January 13, 2025, 04:09:48 pm »
I called it a leak but it may be possible that, due to the small size of the strings, the GC never triggers.
I did a memory profile (using a time limited trial of .Net Memory Profiler) of a C# ray tracer I wrote.
What was interesting was that it showed the garbage collector was only triggering when deleted but not collected memory reached around 120MB. Then it would do a garbage collection, and start again. The garbage collector memory usage looked like a saw tooth wave.

So the collection is delayed until the collector thinks it needs to, it will look like a memory leak in between collections.

I was able to double the performance of the raytracer by changing the ray intersect function to use an out parameter instead of a return, which made the garbage collector activate less often. This is because the out parameter overwrote an existing variable while the return meant a temporary object.

7
Graphics / Re: Rendering Indic Scripts Correctly/Ligatures
« on: January 09, 2025, 12:24:26 am »
Does the Pokemon SDK use SFML?
From the repository readme:
"We wrote a graphic engine called LiteRGSS using SFML, which allows a better mastering of the Graphic part of PSDK like adding Shaders, turning some graphic process to C++ side etc..."

8
General / Re: Cannot Compile with Latest Version
« on: January 01, 2025, 02:18:57 pm »
Easiest way to go without caring about cmake is to go to the main sfml download page: https://www.sfml-dev.org/download/sfml/3.0.0/#all-os
On there are prebuilt versions of SFML for windows (visual studio or gcc), linux and macos.
THese archives contain just the headers and libraries. If you set up the include paths and link the libs, it should be possible to build even from just a command line.

The main downside (and the reason the cmake template is usually recommended) is that GCC in particular is very sensitive to version differences. If you aren't using the identical version to the prebuilt libraries, it can fail. The cmake version makes sure everything is built the same. But as long as you use the compiler listed on the download page, it should work.

(Cmake is great to use for cross platform projects. But my personal game things are only for windows, so it gets in the way more than it helps, for my particular use case)

9
General / Re: Cannot Compile with Latest Version
« on: January 01, 2025, 01:13:14 am »
Ah, that's making sense now. The FindSFML.cmake file is coming from the Daylight project, not your install of SFML. Daylight was written for a version of SFML from 11 years ago (I'm guessing SFML 2.1 or 2.0) and provided its own FindSFML.

Generally I don't use SFML in the usual way. I grab the latest source, run cmake-gui (on Windows) over it to build everything, then I copy out the headers and libs and avoid cmake after that, manually linking it into the engine I built. I've never actually used cmake to set up a new sfml project. :) So I can't give much advice on cmake builds on a mac.
The Daylight project doesn't look too big. My guess would be to first get a default SFML project compiling using the tutorial eXpl0it3r linked to for getting started with cmake. Once that's building fine, take the files from the Daylight and add them in. It's going to need changes, SFML 3.0 changed a lot, code from 2.1 or earlier definitely won't work as is.

10
General / Re: Cannot Compile with Latest Version
« on: January 01, 2025, 12:14:47 am »
(A couple of other posts came in while I was writing this, so point 1 already mentioned)
There's a few issues here.
First, it's not a good idea to use the 2.6 tutorial page for 3.0. SFML 3.0 has changed quite a bit and its code isn't compatible. There are tutorials for 3.0 here: https://www.sfml-dev.org/tutorials/3.0/

Second, the FindSFML.Cmake issue. That file was removed from SFML in March 2018. It was part of SFML 2.4 and earlier. So you are actually using an outdated version of SFML.
If you got SFML from Github, you will need to change the branch you are on. The error said you are on SFML 1.x, which is from 14 years ago.
I tried following the linux install step from the 2.6 tutorial and it gave me SFML 2.5. No findsfml was there. (Note:  I did this on an ARM based device, maybe an x64 would give me the right version? I'm not a Linux developer)

Third, you are following a linux tutorial but your screenshot says apple clang. Isn't that part of xcode for macos? I'm REALLY not a mac developer so I could be wrong on that. Maybe one of the SFML tutorials on macos would be more successful?

11
Window / Re: Key repeats still occur even when set to false
« on: December 31, 2024, 06:16:26 am »
One thing to fix is your key check is outside of the event loop, so it will miss keys if several events arrive in the one update. Otherwise you are checking the last event received, not every event received.
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            if (event.type == sf::Event::KeyPressed) {
                if (event.key.code == sf::Keyboard::Left) {
                    sprite.move(-30.f, 0.f);
                }
                if (event.key.code == sf::Keyboard::Right) {
                    sprite.move(30.f, 0.f);
                }
            }
        }

12
Graphics / Re: Help with general approach
« on: December 28, 2024, 11:01:10 pm »
This sounds like what would traditionally be called metaballs.

How I'd go about it is using shaders with a technique called SDF (Signed Distance Field). Basically it's a mathematical way of determining if a pixel is inside or outside of a shape, and how far. For example if you get an answer of 4, that means 4 pixels away from a shape, 0 means on the surface and -3 would be 3 pixels inside.
That makes it very easy to draw outlines.
The great thing about SDFs is you can combine them and distort them, such as adding the effect you want.

Have a look here for the formulas. They are actually quite small.
https://iquilezles.org/articles/distfunctions2d/  - look at the 2D circle function near the top.
https://iquilezles.org/articles/distfunctions/ - look at the smoothUnion function near the bottom. This page is 3D, but some of the functions like smoothUnion work the same, they deal with distances instead of coordinates.

I made a little shadertoy (great website, by the same guy as the articles I linked above) example.
Go to shadertoy.com and enter this text into the source box:
// Distance to a circle
float sdCircle( vec2 p, float r )
{
    return length(p) - r;
}

// Smoothly combine 2 shapes using their distances.
float opSmoothUnion( float d1, float d2, float k )
{
    float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );
    return mix( d2, d1, h ) - k*h*(1.0-h);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Shadertoy passes in pixels instead of UV like normal shaders, so divide by res to get a 0 to 1.0 range.
    vec2 uv = fragCoord/iResolution.xy;

    // Circle positions and radii.
    vec2 c1 = vec2(0.3,0.3);
    vec2 c2 = vec2(0.6,0.4);
    float r1 = 0.15;
    float r2 = 0.15;
   
    // Distances to the circles. The function wants circle relative positions, so do uv - circle pos.
    float d1 = sdCircle(uv-c1, r1);
    float d2 = sdCircle(uv-c2, r2);
   
    // Combine the two distances to do a smooth union. d is now the distance to either shape, including the smooth part between.
    float d = opSmoothUnion(d1,d2,0.15);

    // Set the colour to be dark green for the background, white inside of the circles and black around the edge.
    vec3 col = vec3(0,0.5,0);  // background is default
    if(d<-0.01)
        col=vec3(1,1,1); // inside of circles
    else if(d<=0.0)
        col=vec3(0,0,0); // in the edge

    // Output to screen
    fragColor = vec4(col,1.0);
}

That won't be 100% SFML shader compatible (should be almost right though), but will let you experiment with the look of the technique.


13
Audio / Re: Link Errors with sfml-audio-s.lib in version 3.0.0
« on: December 28, 2024, 07:50:34 am »
The static versions of SFML don't include their dependencies, you need to link them manually.
https://www.sfml-dev.org/faq/build-use/#link-static
This means you have to also link libraries like flac, openal, vorbis, etc.

Also make sure you add SFML_STATIC to your preprocessor settings for the project, otherwise static libraries can't be linked correctly.

14
Graphics / Re: Vertex Array inconsistency across GPUs?
« on: December 14, 2024, 07:46:19 am »
Quads need to be triangulated (split into two triangles along the diagonal) by the GPU drivers before they can be rendered. There's two ways to do this (split along vertices 0 and 2 or 1 and 3). These two different ways give the two images you posted.
As far as I can see online, OpenGL doesn't define which way it will be split, so its up to the driver.
Quads were deprecated from OpenGL 16 years ago and OpenGLES doesn't have them.

To have a consistent appearance across all hardware and drivers, use two triangles instead.

15
Graphics / Re: [SOLVED] Unabled to load file problem - loadFromFile.
« on: December 06, 2024, 12:11:41 am »
Your output directory (where the .exe file is put) is $(SolutionDir), the location of the .sln file.
Your working directory (where it will look for asset/labyrinth.png) is $(ProjectDir), the location of the .vcxproj file.
So sounds like your asset directory isn't in the project directory where Visual Studio has been told to look for it.
(I always either change $(ProjectDir) to $(TargetDir), which looks where the .exe was put, or in code I find the exe path and change working directory to it)

Pages: [1] 2 3 ... 24
anything