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 ... 223
General / Re: Can't change shape's attributes outside of int main()
« on: February 15, 2024, 02:13:28 am »
Yes, using the example I posted in my most recent reply, you can see that you can pass the object to the function, modify it, and then when you return to main, it will be changed.

Note - VERY IMPORTANT - that you must pass by reference* to be able to modify it. If you pass it by value, it will make a copy, modify the copy and then the copy is lost when the function ends.

* if you don't know what this means, it's part of C++ and means that you can act directly upon the actual passed object rather than a copy. That's what the "&" is for next to the parameter type in my example. See https://en.cppreference.com/w/cpp/language/reference for more information of references.

General / Re: Can't change shape's attributes outside of int main()
« on: February 14, 2024, 11:48:16 pm »
That piece of code is not being called by anything; it's not enclosed.

When the app is started, the first code to be executed is main().
At no point can main call this command.

It brings me to my first example: avoid using objects globally (as is your sf::CircleShape).
However, "global code" is impossible. When should it be executed?

If you want to call a separate piece of code, you can create a function:
#include <SFML/Graphics.hpp>

void setCircleFillColor(sf::CircleShape& circle)
    circle.setFillColor(sf::Color(150, 150, 150));

int main()
    sf::CircleShape shape(200);
    shape.setPosition(sf::Vector2f(5, 5));
Note that the code is enclosed in a function and that function is called from main.

Another option is to enclose it in a class. Note that the class would need to be instantiated (an objected created of it) and that would be within main (or one of its functions).

Graphics / Re: setFrameLimit - curious effect
« on: February 14, 2024, 08:43:23 pm »
setFramerate() sleeps the thread.
This helps with "over-producing" with no limit and can reduce power used. However, it's not strictly set to that rate.
Once a thread is "slept", it has the possibility of "over-sleeping" as there's no real way of insisting on coming back by a specific time (accurately); this is dependent on operating system's task scheduler.

So, I'd guess that the framerate limit is sleeping during each frame and then the operating system is keeping it a little longer than your hoped-for length of time before returning it.

I would expect it to be faster (shorter frame time) without a framerate limit.

General / Re: Can't change shape's attributes outside of int main()
« on: February 14, 2024, 08:35:02 pm »
I think I was slightly confused by your mention of it working only in main.

Could you provide a small example* code of what you mean?
*A complete and minimal example would be great if possible.

Graphics / Re: LineStrip VertexArray and ConvexShape problem
« on: February 14, 2024, 04:32:55 pm »
I'm glad you've at least tried Selba Ward; it is there for people to use!

I mentioned Spline only as a simple and easy way to draw a polygon's outline. Simply export Polygon's positions and set all Spline's positions from that export. Remember to close the Spline. You can also use a thickness for Spline so the outline is no longer infinitely thin (and drawn as a pixel thickness). You can also round the corners. Note that Spline creates the entire polyline as a single object and draws it with a single draw call whereas drawing multiple sf::RectangleShapes (one for each edge) is one draw per edge. FYI, Selba Ward's Line can also draw a simple line with or without thickness and also used to use sf::RectangleShape internally but was replaced by custom vertex array. Still, Spline's better ;)

Another thing to note is that if anything in Selba Ward isn't generic enough to be useful in multiple scenarios, I'd like to consider updates and improvements, and if anything is completely missing from Selba Ward, I consider adding it.
Selba Ward is still improving and Polygon is actually pretty new so somethings are yet to come.

My responses were to help with the creation of the object that you were having trouble with. Hope you at least got that shape made! Note that I didn't mention Selba Ward at first and tried to explain how to create the object yourself. :)

My point about any complex being able to be represented by triangles still stands. However, this is separate from being able to triangulate from a given set of points. Does the "butterfly shape" have holes? Polygon can handle holes but must be informed where they are; hole vertices must also be in opposite (clockwise) direction. In addition, the triangulation method must be set to "EarClip" rather than the more simple "BasicEarClip" to be able to handle the holes. Note that Polygon can only handle "simple polygons"; that is, a polygon that never crosses itself. Holes are technically not part of a "simple polygon" but Polygon converts it into a simple polygon first (as a bonus!).

If you could provide the vertices for the "butterfly shape" and an image of what it should look like, I'd like to do some tests.

It's worth noting that Polygon is designed to be a way to provide a filled polygonal area from a set of points representing its boundary. It's not, however, designed to have visual effects that manipulate those points (such as corner rounding). Those effects should be done separately and given to Polygon to create the shape. In fact, Spline can do this; it can handle Bezier curves and can export its interpolated position so a curved boundary could be created in Spline and then passed to Polygon to create the shape.
It was considered to have a base for both Spline and Polygon as they have similar concepts but decided against so that each Selba Ward drawable can be used independently.

Reading what you wrote about the "butterfly shape" again, I realise that you are creating a polygon where edges cross. This is not a simple polygon and cannot be handled automatically by Polygon. It breaks the rule that vertices must be passed in the same direction. The "butterfly" has vertices in both clockwise and anti-clockwise directions.
Probably better to not have allowed a polygon definition to do this than to try to fix it when the mistake is made.
This could be considered "ill-formed" as it has a "twisted" and not flat face. In fact, if that shape (like a bow-tie, I'm imagining) is required, it can be created; the point in the centre should be included since it exists. It would basically be 6 vertices (5 different ones) which would be the rectangle (in anti-clockwise direction) with the centre vertex between the two vertices of each opposing edge (either top and bottom or left and right).
It could be thought of this way: why is a shape with 2 triangles trying be defined without giving one of the points of each triangle?

Pre-processing can "fix" this. It can already be done before giving the points to Polygon (by specifying them correctly) but features that check and/or adjust for this could be included in Polygon at a later time.

As an aside, Polygon should, in the future, also be able to use monotone triangulation (uses scanline).

I hope I've addressed your questions and helped with your issues. If I missed anything, feel free to let me know.
Also, I'm open to ideas for Polygon and also, more generally, Selba Ward.

EDIT (2024/02/15):
Selba Ward's Polygon can now (as of v1.4), in fact, also work points that are in a clockwise order!
And more!
For more info, see this: https://github.com/Hapaxia/SelbaWard/pull/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;

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()

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.

General / Re: Can't static link SFML
« on: February 13, 2024, 06:32:14 pm »
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).

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.

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:

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.

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

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.

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:

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

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.

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?

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?

Pages: [1] 2 3 ... 223