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

Pages: [1]
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 / 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);
}
 

3
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.

4
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;  } }
 

5
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? 

6
Graphics / Sprites doesn't render properly
« on: April 27, 2014, 05:28:25 am »
Hello, I'm having a bit of a problem here and I can't quite see why.

I have a folder that contains 16 images and I want to render them to the screen and spread them out.




This is how I load them. I want all items to show up, but instead only 1 item shows up in 16 different positions...


sf::Sprite mazeSprite[16];

initialize()
{
      sf::Texture texture;
      std::string filePath = "C:/users/enok/desktop/sprites/cube";

      float x = 10, y = 10;

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

                texture.loadFromFile(filePath + id);

                mazeSprite[i].setTexture(texture);
                mazeSprite[i].setTextureRect(sf::IntRect(10,10,32,32));
                mazeSprite[i].setPosition(x,y);
                x+= 20;
                std::cout << filePath + id << std::endl;
      }

}
 

this is the same sprite lined up 16 times.
http://puu.sh/8p4jz.png


This is the render() function

rWindow.clear();

                for(int i = 0; i <= 15; i++)
                {
                        rWindow.draw(mazeSprite[i]);
                }
                rWindow.display();
 

Pages: [1]