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

Author Topic: AntiaAliasing and Texture Smoothing  (Read 3644 times)

0 Members and 1 Guest are viewing this topic.

codicil793

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
AntiaAliasing and Texture Smoothing
« on: April 08, 2014, 08:14:43 am »
I am trying to draw this hexagon smoothly at any scale, but if it is scaled at all it gets messed up.

This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

using SFML.Window;
using SFML.Graphics;

namespace Project5
{
    class Class1
    {
        static void Main(string[] AssemblyLoadEventArgs)
        {
            RenderWindow rw = new RenderWindow(new VideoMode(400,400), "kkkk", Styles.Default, new ContextSettings(8,8,8));
            rw.Clear(Color.White);

            Sprite s = new Sprite(new Texture("Hexagon.png"));
            s.Texture.Smooth = true;

            //resize to 100x100
            FloatRect rb = s.GetGlobalBounds();
            s.Scale = new Vector2f(1 / (rb.Width / 100),1 / (rb.Height / 100));

            rw.Closed += delegate(object sender, EventArgs args)
            {
                rw.Close();
            };

            while (rw.IsOpen())
            {
                rw.DispatchEvents();
                rw.Draw(s);
                rw.Display();
            }
        }
    }

}
 

This is the output, and the png next to it:


Also, why is the hexagon squished? I scaled it evenly :-(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: AntiaAliasing and Texture Smoothing
« Reply #1 on: April 08, 2014, 08:21:04 am »
Did you try outputting the values or stepping through with the debugger?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

codicil793

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: AntiaAliasing and Texture Smoothing
« Reply #2 on: April 08, 2014, 08:25:50 am »
Yes, I cut that out since it wasn't necessary here. The drawn hexagon has a size of 100x100, according to GetGlobalBounds().

I have tried RectangleShape, ConvexShape, and Sprite, but all of them render the same.

Stepping through it I have done, but I don't see how that would solve the smoothing issue :-(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: AntiaAliasing and Texture Smoothing
« Reply #3 on: April 08, 2014, 08:48:42 am »
Does the window have the actual size? If the window size changes during runtime but you don't adjust the view, the content will get stretched.

You need to call Clear() for every frame, not just once, maybe that will already help, given that now things won't get drawn on top of each other.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

codicil793

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: AntiaAliasing and Texture Smoothing
« Reply #4 on: April 08, 2014, 09:00:06 am »
I moved the call to Clear() into the loop, but it still draws without the smoothing.

Also, the image is stretched even when the viewport is at 400x400, where I initially set it. I tried setting the window's Style to Styles.None but that didn't change anything, so it isn't accounting for the Frame in the size of the viewport.

If I know what is skewing it I can calculate and offset to correct it, or just program it correctly... Lol

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: AntiaAliasing and Texture Smoothing
« Reply #5 on: April 08, 2014, 09:10:17 am »
What's your GPU? And is your graphics driver uptodate?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

codicil793

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: AntiaAliasing and Texture Smoothing
« Reply #6 on: April 08, 2014, 06:53:28 pm »
I have a GeForce GT 650M. Downloaded the latest update but it still renders without smoothing.

omnomasaur

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • http://www.omnomasaur.com
Re: AntiaAliasing and Texture Smoothing
« Reply #7 on: April 10, 2014, 02:48:47 am »
I could be mistaken, but your hexagon is probably squished because hexagons aren't square, so resizing one into a square (100x100) will squish it. 

s.Scale = new Vector2f(1 / (rb.Width / 100),1 / (rb.Height / 100));

In this line you resize based on the original width/height in order to change them both to 100, but the x and y are being resized by separate factors due to the different original width and height.  Rather, resize them both based on the size of a single axis and it shouldn't squish. 

s.Scale = new Vector2f(1 / (rb.Width / 100),1 / (rb.Width / 100));

Only the width will be exactly 100 pixels now, but hexagons aren't square anyway. 

codicil793

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: AntiaAliasing and Texture Smoothing
« Reply #8 on: April 10, 2014, 05:40:36 am »
Of course, I have the math correct in the game in C# but didn't write it correctly here :-(. Thanks. Just need to figure why it isn't antialiasing properly. could someone try using the png I created and see if it is choppy on their system?

The png I'm using is attached.

 

anything