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

Pages: 1 2 3 [4] 5 6 ... 226
46
General / Re: Can't change shape's attributes outside of int main()
« on: February 14, 2024, 01:00:07 am »
Glad you got it to work!  :)

First thing to note is that SFML objects shouldn't be global. It's not clear whether you mean this or not.
e.g. this is BAD:
sf::RenderWindow window;
int main()
{
}
The objects should be created inside the main function:
int main()
{
    sf::RenderWindow window;
}
It's still okay to create an object elsewhere as long as it still called by main:
sf::RenderWindow* createRenderWindow()
{
    sf::RenderWindow* pWindow = new sf::RenderWindow;
    return pWindow;
}
int main()
{
    sf::RenderWindow* pWindow = createRenderWindow();
}
Note that a pointer was used here for simplicity but this is not the safest way to do it. Use a smart pointer if you do it this way.

It's usually better to create them and then pass them:
void createRenderWindow(sf::RenderWindow& window)
{
    window.create(sf::VideoMode(960u, 540u), "");
}
int main()
{
    sf::RenderWindow window;
    createRenderWindow(window);
}

You don't need to pass objects back if you're using them temporarily:
void loadAFontButThenThrowItAway()
{
    sf::Font font;
    font.loadFromFile("fonts/arial.ttf"); // I am not checking whether it loads or not for simplicity and since it does not really matter here but you should always do that!
}
int main()
{
    loadAFontButThenThrowItAway();
}


With all that said, another thing to consider is that SFML needs to be included before using an object so, if you're doing something in a separate file, you'll likely need to include SFML headers from that file too.

47
General / Re: Can't static link SFML
« on: February 13, 2024, 06:32:14 pm »
Hello
Hello! :)

linking the SFML library statically in Visual Studio 2022
I downloaded the WinLibs MSVCRT 13.1.0
The WinLibs are for the MinGW compiler. Since you're using the latest version of Visual Studio, those are not needed and the download 'does not need to match 100%'.
With the rest of the information of your configuration, can we presume that you downloaded this one: "Visual C++ 17 (2022) - 32-bit"?

In addition, don't forget to define the SFML_STATIC macro in Preprocessor Definitions (when building statically).

48
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 13, 2024, 06:21:38 pm »
Polygon requires anti-clockwise due to the calculations testing angles based on inside/outside. It could be adjusted to work with clockwise by swapping angles and sides but the ability to do both is extra calculations for both ways. However, Polygon can reverse them for you so you can provide them as clockwise and reverse them.
Maybe a future update would have the ability to do both by traversing the points in both directions.
Polygon's next update will have colour and texture; that's already ready but I'm looking into other methods and mesh refinement as well as other improvements.
An outline was considered for polygon but since it exports its positions, this can be generated super-easy, especially with Spline (also Selba Ward), which takes those exported positions directly.

With your implementation, remember that resizing the window doesn't automatically resize the view. Maybe that is involved.
https://www.sfml-dev.org/tutorials/2.6/graphics-view.php#showing-more-when-the-window-is-resized

I can't really say why your tone is shifting. I wonder if it may be because it's on a different part of the display and the angle of viewing is different...

And yes, every complex shape can be represented by triangles.
If you have any vertex array shape (not the points or lines primitives) then you can easily extract its triangles:
https://github.com/SFML/SFML/wiki/Source%3A-Triangles-Extractor

49
Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 12, 2024, 09:04:50 pm »
It's important to realise that Selba Ward's Polygon can do this shape automatically, by the way (both triangulation methods work):

However, the order of vertices are VERY important. They absolutely must be in a consistent order around around the perimeter and in an anti-clockwise/counter-clockwise direction. It's best not to duplicate vertices too.
(if they are in the wrong order, you can tell Polygon to reverse their order: reverseVertices)
NOTE: I added the wireframe in the example to show how Polygon triangulated it but it's wasn't a part of the actual Polygon. However, a recent Polygon update allows these wireframes automatically.

50
General discussions / Re: iOS and ANdroid support?
« on: February 08, 2024, 03:35:58 pm »

51
General / Re: Can't get SFML on VS 2022
« on: February 08, 2024, 03:32:56 pm »
As a default, the compiled executables are in folder in the solution root (note: not the project; all projects compile to the same folders).
x86 (32-bit) compilations will be under the configuration-type folder (e.g. Debug, Release)
x64 (64-bit) compilations will be under the folder x64 and then under the configuration-type folder (so, x64/Debug, x64/Release).

This is the default so is a good place to look. You can, however, alter these per project or even per configuration but it's not often necessary to do so.

52
It's common to see operator < being used when sorting is involved as that's how most sorting decides on the order: "is it less than? yes, then it goes first."

You are using std::set and this stores things in order. Your set has sf::Colors. The question is: how do you sort colours? The set will be asking the same question: "is this colour less than that colour? if yes, it goes first". But wait! How can an sf::Color be "less" than another sf::Color?

You can still do it in a set but you will need extra work. For example, you could put each colour in a struct and define its < operator, then use that struct in the set. You could also add to the struct a value that would allow you to give values to each colour, allowing them to be in a specific order.

However, I think it's unlikely you actually want to order the colours so maybe the unordered version of the set is what you actually want:
https://en.cppreference.com/w/cpp/container/unordered_set

With that said, if you're just storing them, would just a standard vector not be sufficient?

53
DotNet / Re: Mouse Scroll Direction
« on: February 07, 2024, 10:39:12 pm »
Does this mean you have two wheels or maybe a multi-directional ball/wheel?

No, many mouses (that i know) support pressing your mouse wheel to the side to scroll sideways
1. I have only one mouse wheel, so I don't need to check which wheel is being scrolled (for now).
This is exactly what I meant by multi-directional wheel.
Up and down scrolling is a wheel scroll and left and right will likely be a separate wheel scroll. This would mean that it would be giving the information to the driver (and then to your OS and then to you via SFML) as two separate wheels.
This brings me to believe it would be a good idea to the check which wheel.

In addition, are you certain that the only time this function is called is when the event type is correct?
Assuming you mean Project.ZoomView(), yes that is only called from that event, since it is a binding for the EventHandler Class (Which contains the event handling functions).
No, actually. Project.ZoomView was not to what I was referring.
Rather, the code that called OnMouseScroll.
I'm guessing (because this is C#) that this is called by the action of a mouse scroll so it should be okay but I would wonder if other SFML event types are getting passed into OnMouseScroll as it doesn't actively check its type to make sure and using the event if it's the incorrect type can "give bad values" - to state it casually.

54
DotNet / Re: Mouse Scroll Direction
« on: February 07, 2024, 05:21:28 pm »
I have an issue with my mouse that sometimes scrolls in the wrong direction. This is just a bad mouse though; it's certainly not SFML. It's probably not this though.

You mentioned scrolling up, down, left and right.
Does this mean you have two wheels or maybe a multi-directional ball/wheel?
Note that, per wheel, it can only go in one direction: positive or negative.
It also doesn't look like you're checking which wheel is being scrolled.

In addition, are you certain that the only time this function is called is when the event type is correct?

55
General / Re: Can't get SFML on VS 2022
« on: February 07, 2024, 05:13:34 pm »
Remember that those properties are "per project" and have to set each time so if you've start a new project since setting the properties, you'll need to set them again.

For your issue, I'd be checking the headers/include directory to make sure they are where you told VS they are (in your project properties).

Note that you if you set these properties for one configuration (release, for example) then they won't be set for the other (debug, for example). You can set multiple configurations at once but remember that some properties need to be set differently for each configuration.

Are you using double-quotes or angle brackets for your inclusion?

56
This is pretty impressive. Nice work! :o

I see you're also encountering the age-old SFML issue of textured quads rotating in 3D space. ;D
Because they're treated as triangles and not as quads, the textures have no knowledge of the point from the other triangle so cannot interpolate as if perspective. You can see this (it's subtle) in your videos. I've managed to find a couple of solutions to this (subdivision or shader per quad) but I've not ventured into large-scale applications of this so I wish you luck with that! Obviously shader per quad could be excessive (one draw call per quad and can't easily be drawn behind everything else) and subdivision can stack the number of those triangles up very quickly!
My examples (as part of Selba Ward) of those two methods are here: Sprite 3D (subdivision) and Elastic Sprite (perspective shader) and you may find them useful while looking for your own solution
It genuinely might be better to get better looking coloured objects than using textured quads but it depends on your intent (or just your interest of looking for problems to solve!)

57
It's also worth noting that the Render Window is global. SFML resources should never* be global objects.

*However, pointers are okay as long as they're initialized as a null pointer. This is because you decide when to create the object meaning that they get called after main has started in a similar way to if it was created from inside main. (you can basically create it as the first line of main)

58
Graphics / Re: RectangleShape.getPosition always returns 0 for value
« on: February 07, 2024, 04:37:53 pm »
I'm not sure if there are extra settings for the window i have to set up if i'm on a Mac, but it seems odd to me that it reports the mouse position as (0, 2100) in the up left corner, which normally would be (0, 0)

How are you receiving these mouse co-ordinates? Events (check that you're using the right part of the union) or real-time values (remember to add the window as a parameter to make it local co-ordinates).

I mention the local co-ordinates even though I believe all Mac apps are technically full screen (I think... right?) because it might be affected by a multiple monitor set-up.

59
General / Re: I'm losing my mind implementing a fixed frame rate.
« on: February 07, 2024, 04:28:36 pm »
No, you're right.
The previous position can be created and copied from the current position at the start of each loop as I suggested here as it's a small variable; it can be const actually!
The Kairos example, however, is based on the idea that when it is scaled up, most likely would be better to be created once.
For example, if, instead of a single position, you were to store every position of everything as well as everything's rotation, colour, size and many other things (including things involving statistics or other information) in one place (as you likely would when using the "time state" idea), this should probably be only created once and updated often. (you would have two of these objects: current and previous; maybe three with one having all interpolated values for that frame)

Since you already found Kairos, why are you not using it? ;)

60
Graphics / Re: RectangleShape.getPosition always returns 0 for value
« on: February 04, 2024, 01:03:56 pm »
There is no code here that actually alters "box" so it's not clear as to if there's an issue elsewhere.

Could printf be an issue here?

Consider adding brackets to your bool assignments as it's not perfectly clear the intention of the code.

SFML has in-built rectangle testing:
bool isIn = box.getGlobalBounds().contains(mPos);

I notice that mPos is integers so it's likely that this is a pixel location (mouse, probably?). Remember to convert this position to the view before using in world co-ordinates:
sf::Vector2f position(window.mapPixelToCoords(mPos));

Pages: 1 2 3 [4] 5 6 ... 226