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

Pages: 1 [2] 3
16
Graphics / It seems that CircleShape works not so fast as it can
« on: October 12, 2015, 11:55:57 am »
I looked in the code of CircleShape and it seems that it uses not so fast algorithm to calculate circle points.
Here is the code from SFML 2.3.2:
Vector2f CircleShape::getPoint(std::size_t index) const
{
    static const float pi = 3.141592654f;

    float angle = index * 2 * pi / m_pointCount - pi / 2;
    float x = std::cos(angle) * m_radius;
    float y = std::sin(angle) * m_radius;

    return Vector2f(m_radius + x, m_radius + y);
}
 

here is a more fast algorithm:
private void DrawCircle(RenderWindow window, Vector2f pos, float radius, Color color)
{
    var list = new List<Vertex>();

    const int numSegments = 50;
    var theta = 2F * (float)Math.PI / numSegments;
    var s = (float)Math.Sin(theta);    //precalculate the sine and cosine
    var c = (float)Math.Cos(theta);
    var vector0 = new Vector2f(radius, 0F);  //we start at angle = 0
    for (var i = 0; i < numSegments; i++)
    {
        //apply the rotation matrix
        var vector1 = new Vector2f(c * vector0.X - s * vector0.Y, s * vector0.X + c * vector0.Y);
        list.Add(new Vertex(pos + vector0, color));
        list.Add(new Vertex(pos + vector1, color));
        vector0 = vector1;
    }

    window.Draw(list.ToArray(), PrimitiveType.Lines);
}
 

I taken this algorithm here: http://slabode.exofire.net/circle_draw.shtml
And it works just like a charm :)

17
Graphics / Is there any way to draw smooth shapes in SFML with no AA?
« on: October 12, 2015, 08:55:05 am »
I read that OpenGL has ability to draw smooth lines with disabled AA.
I found this settings:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
 

Can I use something like that with SFML?
The problem is that all shapes (especially circles) looks terribly with disabled AA...

18
Feature requests / Please add Color conversion/manipulation tool
« on: October 12, 2015, 04:22:05 am »
I think it will be useful to have color conversion and manipulation tool.
For example I need to change brightness of color, so I'm converting it to HSV format then change Value component and then converting back. I think it will be better to have standard class for such operations.

here is my code for HSV/RGB conversion:
        public static Color ToColor(float r, float g, float b)
        {
            return new Color((byte)(r * 255), (byte)(g * 255), (byte)(b * 255));
        }

        public static Color MakeDarken(Color color)
        {
            var rgb = new[] { color.R / 255F, color.G / 255F, color.B / 255F };
            var hsv = RgbToHsv(rgb);
            hsv[2] *= 0.8F;
            rgb = HsvToRgb(hsv);
            return ToColor(rgb[0], rgb[1], rgb[2]);
        }

        public static float[] RgbToHsv(float[] value)
        {
            var r = value[0];
            var g = value[1];
            var b = value[2];
            var min = r < g ? (r < b ? r : b) : (g < b ? g : b);
            var max = r > g ? (r > b ? r : b) : (g > b ? g : b);
            if (max == 0F)
            {
                // r = g = b = 0                // s = 0, v is undefined
                return new [] { -1F, 0F, max };
            }
            var delta = max - min;
            var v = max;
            var s = delta / max;
            var h = r == max ? (g - b) / delta :    // between yellow & magenta
                g == max ? 2F + (b - r) / delta :    // between cyan & yellow
                4F + (r - g) / delta;                // between magenta & cyan
            h *= 60F;                           // degrees
            h = h < 0 ? h + 360F : h;
            return new[] { h, s, v, };
        }

        public static float[] HsvToRgb(float[] value)
        {
            var h = value[0];
            var s = value[1];
            var v = value[2];
            if (s == 0)
            {
                return new[] { v, v, v }; // achromatic (grey)
            }
            h /= 60F;                   // sector 0 to 5
            var i = (int)Math.Floor(h);
            var f = h - i;                      // factorial part of h
            var p = v * (1F - s);
            var q = v * (1F - s * f);
            var t = v * (1F - s * (1F - f));
            switch (i)
            {
                case 0: return new[] { v, t, p };
                case 1: return new[] { q, v, p };
                case 2: return new[] { p, v, t };
                case 3: return new[] { p, q, v };
                case 4: return new[] { t, p, v };
                default: return new[] { v, p, q };
            }            
        }
 

19
DotNet / SFML.NET and CSFML 2.3
« on: October 12, 2015, 12:39:59 am »
I switched to use CSFML 2.3 with SFML.NET binding.
It seems that all works OK and it even don't crashed on app close under windows xp.

But there is strange behavior with mouse buttons.
With CSFML 2.2 I received RenderWindow.MouseButtonPressed but with CSFML 2.3 it didn't works.
I added trace into Window.CallEventHandler and found that CSFML 2.3 sends EventType.MouseButtonReleased only.
Is there is any change in mouse event processing? or it's just a bug?

20
I found some strange behavior with View zooming.
I'm using empty scene with a grid rendered with Vertices for testing.
When I starting app it has default zoom 1,35 and app consumes < 1% CPU (most of the time 0%, sometimes 1%).

But when I change zooming there is some strange happens at threshold between value 3,1046 and 3,1726.
When I reach its threshold CPU usage jumping up to 26% (100% load of single CPU core) and remains at that level on any zoom which is higher that this threshold.
If I change zoom back, CPU load jumps down to 0%.

What happens? Why there is so abrupt increasing of CPU load?
I think zoom should not affect it. At least not so brokenly.

I measured it with VSyncEnabled and SetFrameLimit(0).
I tested with no VSync and it seems that this threshold doesn't affect fps. But what happens with CPU load?
It happens with window size 800x800. When I change window size threshold also shifted.

For example with window size 400x400:
Zoom   CPU load
6,2112    0%
6,3452    26% (100% load of single CPU core)

Window size 900x900:
Zoom   CPU load
2,7601    0%
2,8201    26%

I'm using SFML.NET binding with CSFML 2.2 and SFML 2.2 on Windows 7 x64 and nVidia GeForce 460, driver version 10.18.13.5390

I tried to comment grid rendering, so render loop consists of render debug text only and this issue disappears.
I can zoom out up to the value 55 and CPU load stay on 0%...

Render grid code is the following:
        private void RenderGrid()
        {
            var alpha = 0.2F * _camera.Scale;
            alpha = alpha < 0F ? 0F : alpha;
            alpha = alpha > 1F ? 1F : alpha;
            var color = new Color(0x00, 0x00, 0x00, (byte)(255 * alpha));

            const float step = 50F;
            var size = (Vector2f)_window.Size / _camera.Scale + new Vector2f(step, step) * 2F;
            var offset = _camera.Center - size / 2F - new Vector2f(step, step);
            var vertices = new List<Vertex>();
            for (var y = step - (offset.Y % step); y < size.Y; y += step)
            {
                var sx = offset.X + 0.5F;
                var sy = offset.Y + y + 0.5F;
                vertices.Add(new Vertex(new Vector2f(sx, sy), color));
                vertices.Add(new Vertex(new Vector2f(sx + size.X, sy), color));
            }
            for (var x = step - (offset.X % step); x < size.X; x += step)
            {
                var sx = offset.X + x + 0.5F;
                var sy = offset.Y + 0.5F;
                vertices.Add(new Vertex(new Vector2f(sx, sy), color));
                vertices.Add(new Vertex(new Vector2f(sx, sy + size.Y), color));
            }
            _window.Draw(vertices.ToArray(), PrimitiveType.Lines);
        }
 

_camera.Scale is used in the following way:
            _viewWorld.Size = (Vector2f)_window.Size;
            _viewWorld.Zoom(1F / _camera.Scale);
            _viewWorld.Center = _camera.Center;
            _window.SetView(_viewWorld);
 

Actually I mention values which is assigned to view.Zoom. i.e.:  Zoom = 1F / _camera.Scale;

I tried to hardcode alpha channel of color:
            var alpha = 1F;
            alpha = alpha < 0F ? 0F : alpha;
            alpha = alpha > 1F ? 1F : alpha;
 

But it didn't affect the issue...

I measured vertex count which triggers jump of CPU load and it seems that it's constant. CPU load jumps from 0% to 26% when vertex count grows from 204 to 208 and it independent from window size...

I tested memory allocation for vertex list by allocating fixed size array for 500 vertices, but it not affect the result. CPU load jumps from zero to the maximum when vertex count is more than 204...

Finally I tested if the issue really affected by zoom. To do it I replaced zoom with fixed value 3F. And actually zoom doesn't affect the issue. It depends on vertex count only.

So, CPU load jumps when line count is higher than 204/2=102 lines.
Why?

21
DotNet / Keyboard.Key.Tilde is not recognized under linux
« on: October 06, 2015, 10:37:27 pm »
I'm using Key.Tilde (key "`") to open console in my game.
But when I run it under linux, this key doesn't work.
I logged Window.OnKeyPressed event and found that it receives Key.Unknown if user pressed Key.Tilde.
So it seems like bug...

Update: also the same issue with Key.Quote and all symbols which is entered with Shift key, for example: +_)(*&^%$#@!

22
Window / [SOLVED] High CPU usage in idle mode
« on: October 05, 2015, 02:32:11 am »
I found something strange with window behavior.
I'm playing a bit with render loop which gives for about 1100 FPS.
I set VerticalSyncEnabled(true) with expecting that CPU usage will drop down below 1%...
But it is still 30-40%!!!  :o
I'm running application on 4-core processor.
So it means that my application eats 2 cores with 100% load!
WTF?!!

I opened SysInternals Process Explorer and it shows that the main loop eats the first core for 100% and some thread (which most of the time working inside nvidia driver, as I know, such call-stack looks like D3D::Present call) eats the second core for 100%.

So, it seems that SFML actually doesn't use WaitForVBlank and running some kind of spin lock loop with scanning VBlank, isn't it?

How can I fix it? I want to reduce CPU usage with using VBlankSync...

The second issue which I found is that my app hung when I open call-stack in SysInternals Process Explorer.
And it is still in hung state even if I close Process Explorer.
What happens? Some kind of deadlock?

23
Graphics / jelly physics deformations with sfml, is it possible
« on: October 01, 2015, 11:06:36 am »
I want to achieve effect, something like this:

Is it possible?
How to implement it? Probably there is need to use shaders for transformations?

24
Graphics / Render colored text
« on: September 30, 2015, 04:47:33 am »
I'm implemented a game console, such as used in Doom, Quake, Stalker, Crysis and other 3D shooters.
It's very useful for debugging and works fast enough, but there is a little question about rendering colored texts.
I'm using colored text output to make it more readable.
For simplification purposes, I'm using special text codes to switch current text color. For exampe:
"$1Hello $2world!"
It will be rendered as white "Hello" and blue "world".
To render such texts I'm split it into several parts for each color and then render it with calling Text.GetLocalBounds to measure it's size.

So, the question - is there any better way to render text which consists of sub-strings with different colors?

25
Window / Is there any way to handle clipboard texts?
« on: September 30, 2015, 03:27:25 am »
I'm using TextEntered event to handle user input.
But what about clipboard? I mean shortuts such as Ctrl+C/Ctrl+V, Ctrl+Insert/Shift+Insert.
Is there any way to obtain/set clipboard content with SFML?

26
Graphics / sf::Text performance
« on: September 29, 2015, 08:32:34 pm »
I have some issues with render text performance.
So, could someone suggest me the best approaches to improve performance for text rendering?

I need to render object names which should fit to the object size. And each object has it's own size which may be varied in very different range. The total object count and it's sizes is changed in realtime and sometimes it changes very quickly (it may be significantly diferrent on two followed frames). Usually I have 200-500 objects on the screen  whhich should be rendered with name.

So my current best approach is to initialize single Text object, assign the font (because the font and color is always the same). And then render it in a loop with calculating CharacterSize from object size.
I tried to render text within separate loop to avoid context switch frome shape to the text. It was recommended in another topic. But as a result I got a lower performsnce. So, it's not a good solution.
May be there is another way to implement such functionality? Something like render text into texture on text change, using text scaling or something like that?

27
System / joystick issue on windows
« on: September 26, 2015, 09:34:16 pm »
I'm not using joystick at all, but my SFML app reads registry values related to joystick.
There a lot of registry requests every second.
In Process Monitor it looks like spamming.
How can I disable it to avoid unwanted access to the disk?

28
DotNet / [SOLVED] How to use SFML.NET on linux/mono?
« on: September 26, 2015, 09:25:27 pm »
Hi guys,

Can anyone help me to run my application on linux mono.
Does SFML.NET supports it? What I need to setup in order to use SFML.NET on linux?
Thanks

29
Graphics / CircleShape performance
« on: September 23, 2015, 03:37:45 pm »
I caught some performance issues with CircleShape.
When the total count of circles grows up to 1000 per frame, the performance slows down dramaticaly. When it's count grows up to 2000, I get 5-10 fps... :(
I run profiler and it shows that SFML consumes for about 80% of time in drawing circles...

Could you please suggest any optimization techniques to improve performance?
I added condition to render rectangles instead of circles when it's physical size is lower than 3-4 pixels. It helps very well (fps increased for 1,5 times), but it's not enough. I need more optimizations. Any ideas are welcome.
Thanks

30
Audio / Does SFML support playing realtime raw sample stream?
« on: September 23, 2015, 02:18:59 pm »
I need to play raw sound stream which is produced in realtime.

Actually, I wrote some interactive engine which produces realtime raw audio & video streams.
The content is interactive, so buffering is possible for a very short time - 50-100 ms.
Currently I'm using Direct3D and DirectSound directly.
But it's hardly linked with Windows, and I want to porting it into Linux and iOS.

I tested SFML and its really simple and beautiful :)
So, I'm thinking about using SFML...
Does SFML support such functionality?

Pages: 1 [2] 3
anything