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

Pages: [1] 2
1
Solved. It was a mismatch between the backing enum types for sf::BlendMode::Factor vs my beef representation, the correct type was uint32.

Hey! I'm currently doing SFML bindings in the beef programming language and I've run into a bit of a problem when trying to call sfRenderWindow_drawSprite() and passing in RenderStates with a null shader handle.

ShaderHandle & TextureHandle are just pointer-sized opaque handles

[CRepr, Ordered]
public struct RenderStates
{
    public BlendMode Mode;
    public Matrix3x3 Matrix; //sfTransform
    public TextureHandle TextureH;
    public ShaderHandle ShaderH;

   public this(BlendMode mode, Texture texture, Shade shader, Matrix3x3? matrix)
   {
        Mode = mode;
        TextureH = texture.[Friend]_handle;
        ShaderH = shader.[Friend]_handle;
        Matrix = matrix ?? Matrix3x3.Identity;  
   }
}

public static void Main()
{
        using(let window = new RenderWindow(VideoMode(800, 600), "Title")) {
                window.ClosedEvent.Add(scope (w) => {
                        window.Close();
                });

                var texture = scope Texture("resources/beef.png");
                var sprite = scope Sprite(texture);
                var renderStates = RenderStates(BlendMode.Alpha, texture, null, null);

                while (window.IsOpen())
                {
                        window.ClearColor(Color.CornflowerBlue);
                        window.DispatchEvents();
                        //window.DrawSprite(sprite, renderStates); ACCESS VIOLATION
                        window.Display();
                }
        }
}
 

2
DotNet / Re: Texture CoordinateType enum missing from SFML.Net?
« on: March 15, 2018, 05:25:16 pm »
Well, solved it. I don't understand why it would make any difference though, since Texture is just a public field..

But

_states = new RenderStates(texture); //This works, texture shows up correctly

_states.Texture = texture; //This does not work, doesn't show up at all
 

Looking through RenderStates.cs atm and I can't really see the issue.

EDIT:
Alright I see it now, I wasn't paying attention earlier, it's a silly thing really.

I'm initializing the RenderStates with the default empty constructor which means the transform and blendmode aren't set properly.

3
DotNet / Re: Texture CoordinateType enum missing from SFML.Net?
« on: March 15, 2018, 04:11:02 pm »
I don't think there should be an issue with the texture reference, it's not null when I pass it into the RenderState instance so unless it gets nulled internally there, references wouldn't be the issue.

This is the result if I omit the RenderState when I do a draw call: https://puu.sh/zIbeO/cf40eaa6ca.png
And this is what it looks like if I pass it in: https://puu.sh/zIchk/94cc0835aa.png

Which makes me think I got the texture coords wrong. But the texture is just a black image, no transparency or anything so I'd think it would still show something on screen, unless I'm doing something wrong when I assign the texture coordinates to the vertices, which I probably am, because I don't know if the TexCoord field on the Vertex struct takes normalized coords or pixels.

4
DotNet / Re: Texture CoordinateType enum missing from SFML.Net?
« on: March 15, 2018, 02:43:33 pm »
I posted the relevant pieces in the first post where I assign the texture coords of the vertices, but I'll drop the entire thing here if its easier :): https://pastebin.com/WNfqEa5i

EDIT:
This is just where I pass in the texture, source / destination rects for batching
_spriteBatch.Begin(_states);
for (int y = 0; y < 1080 / 16; y++) {
        for (int x = 0; x < 1920 / 16; x++) {
                _spriteBatch.Batch(_texture, new IntRect(new Vector2i(0, 0), new Vector2i(16, 16)), new FloatRect(new Vector2f(x * 16, y * 16), _size), Color.Red);
        }
}
_spriteBatch.End();
 

5
DotNet / Re: Texture CoordinateType enum missing from SFML.Net?
« on: March 15, 2018, 02:26:08 pm »
I'm using SFML 2.2, just downloaded the binaries from the bindings page.

https://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php According to docs it should be in 2.0 too.

And I'm not doing any explicit GL calls, I just pass a vertex array and a render state into the Draw method of a RenderWindow. If I omit the render state the quads show up properly(assuming I pass a color), else the quads are just transparent.

6
DotNet / Texture CoordinateType enum missing from SFML.Net?
« on: March 15, 2018, 01:59:53 pm »
Like the title, this: https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Texture.php#aa6fd3bbe3c334b3c4428edfb2765a82e

seems to be missing from the .NET-binding.

What's the default coordinate type? Working on a sprite batcher and the textures aren't being displayed so I assume I got the coordinates wrong (since the quads display correctly with color).

Relevant code:
var item = new BatchItem();
item.Update(x, y, width, height, color, new Vector2i(source.Left, source.Top));
 

public void Update(float x, float y, float width, float height, Color color, Vector2i textureCoords)
{
                       
        TopLeft.Position = new Vector2f(x, y);
        TopLeft.Color = color;
        TopLeft.TexCoords = new Vector2f(textureCoords.X, textureCoords.Y);

        TopRight.Position = new Vector2f(x + width, y);
        TopRight.Color = color;
        TopRight.TexCoords = new Vector2f(textureCoords.X + width, textureCoords.Y);

        BottomRight.Position = new Vector2f(x + width, y + height);
        BottomRight.Color = color;
        BottomRight.TexCoords = new Vector2f(textureCoords.X + width, textureCoords.Y + height);

        BottomLeft.Position = new Vector2f(x, y + height);
        BottomLeft.Color = color;
        BottomLeft.TexCoords = new Vector2f(textureCoords.X, textureCoords.Y + height);
}
 

7
DotNet / Re: sfmlnet-graphics-2.dll - System.AccessViolationException
« on: November 25, 2014, 07:15:44 pm »
Try newer csfml-*.dll files. You can get them here: http://www.nightlybuilds.ch/project/show/4/CSFML/

Haha, I did do that some minutes ago and I was just about to write that I had it up and running properly when you wrote. :D

Anyhow, it's working, thank's for the quick response yo.

8
DotNet / sfmlnet-graphics-2.dll - System.AccessViolationException
« on: November 25, 2014, 06:16:16 pm »

I compiled the latest source from github and this happens when I use the Sprite class.
Specifically when I try to draw the sprite. If I comment that part out, it'll run without any problems.


namespace ForScience
{
    class Program
    {
        static void Main(string[] args)
        {

            using(var rWindow = new RenderWindow(new VideoMode(800, 600), "For science!", Styles.Close))
            {
                Sprite spr = new Sprite(new Texture("spr_cannon_barrel.png"));

                rWindow.Closed += (sender, e) =>
                {
                    rWindow.Close();
                };

                while(rWindow.IsOpen)
                {
                    rWindow.DispatchEvents();
                    rWindow.Clear(new Color(248, 240, 255));
                    rWindow.Draw(spr);
                    rWindow.Display();
                }

            }  
       
        }
    }
}
 

The image is copied to build directory along with the extlibs and all libs are properly referenced.

9
DotNet / Re: Set sprite origin.
« on: November 20, 2014, 05:25:45 pm »
The hell.. I'm gonna compile the latest source and try again..

10
DotNet / Re: Set sprite origin.
« on: November 20, 2014, 03:07:24 pm »
This is what it looks like when I just draw the sprite.


This is what it looks like with player.Origin = new Vector2f(50,50);



Game.cs
namespace PointAndClick
{
    class Game
    {

        Player player = new Player();



        public void LoadContent()
        {
            player.Texture = new Texture(Converter.ToSFTexture(Resources.spr_cannon_barrel));
            player.Origin = new Vector2f(50, 50);
        }

        //Physics, move stuff.
        public void FixedUpdate(TimeSpan deltaTime)
        {

        }

        //Draw stuff, check for input
        public void Update(RenderWindow rWindow)
        {
            rWindow.Clear(new Color(25,18,63));
            player.Draw(rWindow);
            rWindow.Display();
        }

        public static void UnloadContent()
        {

        }
    }
}
 
Player.cs
namespace PointAndClick
{
    public class Player
    {
        private Sprite sprite = new Sprite();

        //Transform
        public Vector2f Position { get { return this.sprite.Position; } set { this.sprite.Position = value; } }
        public Vector2f Scale    { get { return this.sprite.Scale;    } set { this.sprite.Scale = value;    } }
        public float Rotation    { get { return this.sprite.Rotation; } set { this.sprite.Rotation = value; } }

        public Texture Texture { get { return this.sprite.Texture; } set { this.sprite.Texture = value; } }
        public Vector2f Origin { get { return this.sprite.Origin;  } set { this.sprite.Origin = value;  } }
       
        public void Draw(RenderWindow rWindow)
        {
            rWindow.Draw(this.sprite);
        }
    }
}
 


11
DotNet / Re: Set sprite origin.
« on: November 20, 2014, 02:57:28 pm »
It doesn't do anything. It doesn't change the origin, nothing happens. There's no difference with or without it. No matter what numbers I type in, the sprites origin is always in the top-left.

12
DotNet / Set sprite origin.
« on: November 20, 2014, 02:41:13 pm »
Hello.

Setting the sprite origin doesn't seem to work.

I can't really see what I'm doing wrong here, everything else works just fine. I can't set the Origin even if I do it directly to the sprite itself, rather than using properties.

        public void LoadContent()
        {
            player.Origin = new Vector2f(player.Scale.Y, player.Scale.Y) / 2;
        }
 

        public Vector2f Origin { get { return this.sprite.Origin;  } set { this.sprite.Origin = value;  } }
 

13
DotNet / Re: Check if mousebutton was clicked (pressed, then released)
« on: November 17, 2014, 12:43:48 pm »
I took 2 sips of my coffee and now I function properly again. I always do this, lel. I ask for a solution, then I solve it 2 minutes later, hehe.

Code: [Select]
        private static bool curState;
        private static bool MouseClicked(Mouse.Button Button)
        {
            if (Mouse.IsButtonPressed(Button))
                curState = true;

            if (curState)
            {
                if (!Mouse.IsButtonPressed(Button))
                {
                    curState = false;
                    return true;
                }
                else
                    return false;
            }
            else
                return false;
        }

14
DotNet / Check if mousebutton was clicked (pressed, then released)
« on: November 17, 2014, 12:33:49 pm »
Hello.

I'm having a bit of a problem here with a Method. See, I need this method to return true only when the mousebutton was pressed and then released.

Code: [Select]

        private static bool MouseClicked(Mouse.Button Button)
        {
            if (Mouse.IsButtonPressed(Button))
            {
                if (!Mouse.IsButtonPressed(Button))
                    return true;
                else
                    return false;
            }
            else
                return false;
        }


I know why the above code fails to do what I want, it's quite simple, it's running through a loop and so, the mouse-clicking has to be pretty damn precise(read lucky) in order for the method to return true..

Now, I'm at a total loss here tbh, I'm not quite sure how this could be solved. Any ideas? 

15
Graphics / Re: Sprites doesn't render properly
« on: April 27, 2014, 06:15:21 am »
I did like so instead:

sf::Texture texture[16];

texture[i].loadFromFile(filePath + id);

mazeSprite[i].setTexture(texture[i]);
 

This code
         sf::Sprite mazeSprite[arraySize];
         sf::Texture texture[arraySize];

        //Runs once
        void engine::initialize()
        {
                std::string filePath = "C:/users/enok/desktop/sprites/cube";

                float x = 10, y = 10;

                for (int i = 0; i < arraySize; i++)
                {
                        std::string id = std::to_string(static_cast<long long>(i)) + ".png";

                        if(!texture[i].loadFromFile(filePath + id))
                        {
                                std::cout << "NOPE" << std::endl;
                        }

                        mazeSprite[i].setTexture(texture[i]);
                        mazeSprite[i].setTextureRect(sf::IntRect(10,10,32,32));
                        mazeSprite[i].setPosition(x,y);

                        x += 32;

                        std::cout << filePath + id << std::endl;
                }
        }
 

Gives me this result http://puu.sh/8pGd9.png

But only when I run it with release, not debug. If I try debug, I get access violation writing location.

Additional dependencies:(Debug) sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;

Pages: [1] 2