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

Pages: [1]
1
In the documentation, they recommand to not have too many textures because of performance, not because of possible hardware limitations. Switching between textures is very expensive, that's why if you have quite a lot of them you better pack them in a texture atlas. A lot of games do that.

2
DotNet / Re: SFML and event management (unexpected behavior)
« on: March 14, 2017, 12:36:57 pm »
Actually you are right, messages are normally queued, but not WM_MOUSEMOVE, because it is a special case :

See this answer :
http://stackoverflow.com/questions/17512457/missing-mouse-movement-messages-in-win32#answer-17515095

3
DotNet / SFML and event management (solved)
« on: March 14, 2017, 12:11:36 am »
Consider the following (very simple) SFML app.
It creates a render window, poll events and print to console each mouse move position:

public static void Main()
{                      
        RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
       
        window.MouseMoved += (sender, e) => {
                Console.WriteLine(e.X + " " + e.Y);
        };
                       
        // Start the game loop
        while (window.IsOpen())
        {
                window.DispatchEvents();                                               
                window.Clear();                        
                window.Display();
                //System.Threading.Thread.Sleep(1000);
        }
}

Imagine we remove the line in comment (Thread.Sleep(...)).
Now the display in the console is very laggy (which is expected).

However it only prints one mouse position per second. I would rather expect that it would wait one second, then print a bunch of mouse positions (actually all the ones send to the window while sleeping), then wait one second , then print some messages and so on.

I have taken a look at source code (both C++ and C# github repos) and AFAIK SFML behavior is to pump all messages from the window (using PeekMessageW()) then store in it's own queue (a C++ vector) and dispatch them one by one. So I don't understand behavior that I got. I expect Console.WriteLine() to be called several times between two Thread.Sleep().

4
Some feed back : the dev machine i'm using (a macbook laptop) use WinXP (under VirtualBox) :

- SFML 2.1 : works perfectly
- SFML 2.2 : white squares for all sprites (no textures)
- SFML 2.4 : crash at load : Unable to load DLL 'csfml-graphics-2'  Invalid access to memory location

Under VirtualBox + Win7 , or Win7 native (no virtualization), all SFML versions works perfectly.

It seems Windows XP compatibility was broken between 2.1 and 2.2.

5
Thanks for your help. I did the following :

1) I downloaded latest C# source code from SFML.Net github repository and compiled it (32-bit / release). I copied dll's from SFML.Net-master\lib\x86 folder to my project and referenced those assemblies.

2) I downloaded CSFML 2.4 package from here  : http://www.sfml-dev.org/download/csfml/ (32-bit C++)
I copied dll's to the same folder as my project binary executable.

Now, when I start the application it fails on the first line :

RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");



System.DllNotFoundException: Unable to load DLL 'csfml-graphics-2': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)
   at SFML.Graphics.RenderWindow.sfRenderWindow_createUnicode(VideoMode Mode, IntPtr Title, Styles Style, ContextSettings& Params)
   at SFML.Graphics.RenderWindow..ctor(VideoMode mode, String title, Styles style, ContextSettings settings)
   at SFML.Graphics.RenderWindow..ctor(VideoMode mode, String title)
   at Test.Program.Main()

As explained above, "csfml-graphics-2.dll" exists in project executable.
It seems some incompatible binding between DLL's.

6
I have a perfectly working application made with SFML.Net 2.1. I have decided to migrate to 2.2.

However, after the migration I have noticed the following : ALL sprites are now displayed as white rectangles (no more textures)

I have reduce program to the bare minimum and problem still occurs :

public static void Main()
{
        RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
       
        window.Closed += OnClosed;
        Sprite spr = new Sprite(new Texture(@"test.png"));     
                       
        while (window.IsOpen)
        {
                window.DispatchEvents();                                                       
                window.Clear();                                
                window.Draw(spr);
                window.Display();
        }
}
   

Issue is not related to test.png file : if it was not there it would throw an exception.

Compiling the exact same program under SFML 2.1 (expect minor changes like window.Open vs window.Open()) => it works perfectly (sprites are displayed as they should).

At runtime, the following errors are sometimes shown when using SFML 2.2 :

Code: [Select]
OpenGL Warning: SHCRGL_GUEST_FN_WRITE_READ (36) failed with ffffffdb ffffffea   

Code: [Select]
Unhandled Exception: System.AccessViolationException: Attempted to read or write
 protected memory. This is often an indication that other memory is corrupt.
   at SFML.Graphics.Sprite.sfRenderWindow_drawSprite(IntPtr CPointer, IntPtr Spr
ite, MarshalData& states)
   at SFML.Graphics.Sprite.Draw(RenderTarget target, RenderStates states)
   at SFML.Graphics.RenderWindow.Draw(Drawable drawable)
   at Test.Program.Main() in Program.cs:line 22
   

I use SFML.Net 2.2 32-bit version from here : http://www.sfml-dev.org/download/sfml.net/ + CSFML 2.2 from here : http://www.sfml-dev.org/download/csfml/



7
If both circles have same radius (as in your example) this is even simpler :

vector2f d = spriteA.position - spriteB.position;
float distance = sqrt(d.x * d.x + d.y * d.y);
bool collide = distance < (radius * 2.0f);

8
Graphics / Re: How to draw a line strip that has some thickness
« on: March 06, 2017, 12:33:29 am »
I really recommend to read this thread : https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader#23286000001269127

This helped me a lot. To implement this I used a class that inherit from Drawable and has TrianglesStrip as PrimitiveType (as Laurent suggested).

I copy paste summary of the thread here, in case it would disappear :

The line always starts with a segment :


The line is defined by :
Vector2f line = p1 - p0;
Vector2f normal = Vector2f( -line.y, line.x).normalized();

The boundaries of the segment can be found this way :
Vector2f a = p0 - thickness * normal;
Vector2f b = p0 + thickness * normal;
Vector2f c = p1 - thickness * normal;
Vector2f d = p1 + thickness * normal;

Two joined segments :


The goal is to find m and -m :
Vector2f tangent = ((p2-p1).normalized() + (p1-p0).normalized()).normalized();
Vector2f miter = Vector2f( -tangent.y, tangent.x ); //normal of the tangent

The length of the miter can be found by projecting it on one of the normals, using the dot product :
float length = thickness / miter.dot( normal )

Then, the miter points can be found by :
Vector2f m1 = p1 - length * miter;
Vector2f m2 = p1 + length * miter;

9
Graphics / Re: How to draw a line strip that has some thickness
« on: March 04, 2017, 05:49:44 pm »
A TriangleStrip is exactly what you need. You can have a look at the example in the tutorial.

Thank you a lot, I manage to get what i need using TriangleStrip and the tutorial you provided.

10
Graphics / Re: How to draw a line strip that has some thickness
« on: March 04, 2017, 02:24:27 pm »
So if i want to draw a line with let's say 20 points, I have to draw 19 rectangles ?

11
Graphics / How to draw a line strip that has some thickness
« on: March 04, 2017, 11:19:42 am »
I would like to draw a line made of several points (more than 2) and that have some thickness (aka width).

How can I do that in SFML ?

Here is my actual code (C#) :
Vertex[] line =
{
        new Vertex(new Vector2f(10.0f, 10.0f)),
        new Vertex(new Vector2f(150.0f, 150.0f)),
        new Vertex(new Vector2f(300.0f, 60.0f))
};

window.Draw(line, PrimitiveType.LinesStrip);

12
General / Re: Which SFML package to install from NuGet ?
« on: February 27, 2017, 01:17:19 am »
I found the answer :
- "SFML.Net" package => this is for C# / .NET
- the other packages (sfml-system, sfml-window, ...) => C++.

13
Graphics / Re: How to check if a sprite is visible within a view ?
« on: February 17, 2017, 04:18:32 pm »
@JayhawkZombie :
Thanks.

I have solved the problem for checking the if the mouse cursor is inside view (but not for the sprite) :

IntRect viewport = window.GetViewport(myView);
Vector2i mousePosition = ...
if (viewport.Contains(mousePosition))
{
  //...
}




14
General / Which SFML package to install from NuGet ?
« on: February 17, 2017, 02:48:56 pm »
When I search "SFML" on NuGet I got the following packages :

- "SFML.Net" (2.1.5) By Laurent G

However there is also the following ones :

sfml-system
sfml-window
sfml-graphics
sfml-audio
sfml-network

They are also by Laurent G. but version is 2.4.0

Should I install "SFML.Net" package (which is outdated) or the individual (more recent) packages (only the one I need) ?
If it's better to install the individual packages, what is the purpose of "SFML.Net" package ?


15
Graphics / How to check if a sprite is visible within a view ?
« on: February 17, 2017, 11:30:07 am »
Hi all,
I am a beginner with SFML and have a question.

Let's say I have a game with a scrollable view.

Is there a simple way using SFML to check if a given sprite (eg : an enemy) is visible within a view ? By visible I mean the sprite can be seen with the current scroll values, not that it is occluded by another sprite.

I have same problem with mouse : how to check that a the mouse cursor is inside a view ?

Pages: [1]