Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Texture CoordinateType enum missing from SFML.Net?  (Read 4261 times)

0 Members and 1 Guest are viewing this topic.

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
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);
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #1 on: March 15, 2018, 02:05:47 pm »
You'd only need that if you do custom OpenGL calls and use sf::Texture::bind().

Where did you get the .NET-binding binaries? They might simply not be up to date with SFML 2.4.2.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #3 on: March 15, 2018, 02:29:58 pm »
Well I've no idea what your code is, so your description doesn't help much. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #4 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();
 
« Last Edit: March 15, 2018, 02:46:51 pm by Enok »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #5 on: March 15, 2018, 03:33:40 pm »
I don't exactly see the problem right now, maybe it's related somehow to C# reference handling?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #6 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.

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Texture CoordinateType enum missing from SFML.Net?
« Reply #7 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.
« Last Edit: March 15, 2018, 05:57:05 pm by Enok »

 

anything