Graphics anti-aliasing in NME

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Graphics anti-aliasing in NME

David Peek
Greetings list,

Just wondering if there's a way to anti alias drawing API calls (drawCircle, drawRoundRect etc) in NME. I found an earlier message on the list that went unanswered, and dug around the NME source looking for SDL configuration and the like... unfortunately my c++ is letting me down.

Thanks :)
David
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

davidedc
Hi David,

Which target? It's weird because I had the opposite problem on iPhone, where I wanted sdl to draw non-anti aliased and I couldn't find a way to.

Did you try setting the stage quality to low?

Davide

On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:

> Greetings list,
>
> Just wondering if there's a way to anti alias drawing API calls (drawCircle, drawRoundRect etc) in NME. I found an earlier message on the list that went unanswered, and dug around the NME source looking for SDL configuration and the like... unfortunately my c++ is letting me down.
>
> Thanks :)
> David
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

Joshua Harlan Lifton
The unanswered post David refers to may have been mine. I'm targeting
the iPad. Changing the stage quality didn't have any effect - there's
no anti-aliasing for any of the quality settings. Davide, which
revisions of nme and sdl-static are you using? I'm using the latest
versions of trunk. Want to trade problems?

On Sun, Jun 26, 2011 at 5:18 AM, Davide Della Casa <[hidden email]> wrote:

> Hi David,
>
> Which target? It's weird because I had the opposite problem on iPhone, where I wanted sdl to draw non-anti aliased and I couldn't find a way to.
>
> Did you try setting the stage quality to low?
>
> Davide
>
> On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:
>
>> Greetings list,
>>
>> Just wondering if there's a way to anti alias drawing API calls (drawCircle, drawRoundRect etc) in NME. I found an earlier message on the list that went unanswered, and dug around the NME source looking for SDL configuration and the like... unfortunately my c++ is letting me down.
>>
>> Thanks :)
>> David
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

davidedc
Hi,

yes, either something changed in how graphics is done via SDL (I'm 3 months late on the SVN) or your graphics is done by OpenGL rather than SDL.

If you are drawing to a bitmap, then you are using the SW rendering in SDL, in that case I don't know the solution, and things obviously changed a lot because I had the opposite problem.

If you are not drawing on a bitmap, then OpenGL(ES) (not SDL) is doing the graphics for you via HW, in that case I see why you are getting aliased graphics (that's how the iPad and iPhone GPUs work by default), and I made a patch here in mid March to get iPhone/iPad to do multisampling http://code.google.com/p/nekonme/issues/detail?id=54 . Sorry I didn't get around to including it in SVN.

Warning: multisampling hammers the FPS big time (cause it's almost like filling x2 or x4 pixels). Unfortunately from the research I've done this seems the only way people get anti-aliasing done in OpenGLES. On the plus side, if your aliasing is noticeable, hopefully it's because your graphics is pretty steady on the screen, so maybe FPS is not a big deal.

If you need good fps, you can try to "blur" it with "fainter" primitives below your foreground primitives. That doubles the geometry data, so it can be problematic too.

Another option is to pixel-shift your primitives slightly every other frame of +1, +1 (or variations). That's king of cheap and dirty, but could work well.

Another option that I wanted to try but I didn't (but it should be easy) is to NOT use the full retina display (so, to fall back to lower resolution) but enabling multisampling. So you lighten the fill on one side and "balance" it with the multisampling. So in that way you'd have coarser graphics, but with antialiasing and probably good FPS. Probably would work badly with text.

Hope this helps,
Davide

On Sun, Jun 26, 2011 at 1:46 PM, Joshua Harlan Lifton <[hidden email]> wrote:
The unanswered post David refers to may have been mine. I'm targeting
the iPad. Changing the stage quality didn't have any effect - there's
no anti-aliasing for any of the quality settings. Davide, which
revisions of nme and sdl-static are you using? I'm using the latest
versions of trunk. Want to trade problems?

On Sun, Jun 26, 2011 at 5:18 AM, Davide Della Casa <[hidden email]> wrote:
> Hi David,
>
> Which target? It's weird because I had the opposite problem on iPhone, where I wanted sdl to draw non-anti aliased and I couldn't find a way to.
>
> Did you try setting the stage quality to low?
>
> Davide
>
> On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:
>
>> Greetings list,
>>
>> Just wondering if there's a way to anti alias drawing API calls (drawCircle, drawRoundRect etc) in NME. I found an earlier message on the list that went unanswered, and dug around the NME source looking for SDL configuration and the like... unfortunately my c++ is letting me down.
>>
>> Thanks :)
>> David
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

Gamehaxe
Hi,
Funny you should mention this, because I've just been adding OpenGL AA.
So far it is only for SDL targets, but I hope to do the others  
(android,ios)
soon.
Currently, the best way to do this might be to use "cacheAsBitmap".
The will use the software renderer to render a texture, then use the  
texture.
This will also fix radial gradients. It depends on how much your
objects move/rotate.  It may actually be a performance win if the
objects are relatively static.

Hugh


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

davidedc
Ha! In fact Zjnue and I were just watching in realtime the multisampling work you just submitted.

Hopefully the iPhone patch could be useful then. If I have the time/can figure out how you've organized the flags I'll put my patch in place in a "clean" way, so far it works with #defines, which is kind of bad.

Cheers,
Davide

On Sun, Jun 26, 2011 at 3:23 PM, Gamehaxe <[hidden email]> wrote:
Hi,
Funny you should mention this, because I've just been adding OpenGL AA.
So far it is only for SDL targets, but I hope to do the others (android,ios)
soon.
Currently, the best way to do this might be to use "cacheAsBitmap".
The will use the software renderer to render a texture, then use the texture.
This will also fix radial gradients. It depends on how much your
objects move/rotate.  It may actually be a performance win if the
objects are relatively static.

Hugh


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

Gamehaxe
In reply to this post by davidedc
Hi,
To get "crisp" lines in opengl, you have to consider 1/2 pixel alignment.
When you draw lines your vertices specify the centre of your line.
However, opengl samples the "Infinite Cartesian Plane" at the centres
of pixels, ie (0.5,0.5)  (1.5, 0.5), (2.5,0.5) ....
So, if you draw a line form (0,0) to (10,0) the line will start halfway
between the (0.5,-0.5) and the (0.5,0.5) pixels - therefore it will be
"half grey" on two lines.
When using the software renderer, there is some code that says
"Bump horizontal and vertical lines so they lie on pixel centres".
The solution for opengl (also works on software) is to draw your  
lines(rectangles)
with a half-pixel offset, ie:
(0.5,0.5) .. (10.5,0.5)

Hugh


> Hi David,
>
> Which target? It's weird because I had the opposite problem on iPhone,  
> where I wanted sdl to draw non-anti aliased and I couldn't find a way to.
>
> Did you try setting the stage quality to low?
>
> Davide
>
> On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:
>
>> Greetings list,
>>
>> Just wondering if there's a way to anti alias drawing API calls  
>> (drawCircle, drawRoundRect etc) in NME. I found an earlier message on  
>> the list that went unanswered, and dug around the NME source looking  
>> for SDL configuration and the like... unfortunately my c++ is letting  
>> me down.
>>
>> Thanks :)
>> David
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

davidedc
Is that true for iPhone / iPad too?
Cause I didn't see that behaviour there.

D

On Sun, Jun 26, 2011 at 3:33 PM, Gamehaxe <[hidden email]> wrote:
Hi,
To get "crisp" lines in opengl, you have to consider 1/2 pixel alignment.
When you draw lines your vertices specify the centre of your line.
However, opengl samples the "Infinite Cartesian Plane" at the centres
of pixels, ie (0.5,0.5)  (1.5, 0.5), (2.5,0.5) ....
So, if you draw a line form (0,0) to (10,0) the line will start halfway
between the (0.5,-0.5) and the (0.5,0.5) pixels - therefore it will be
"half grey" on two lines.
When using the software renderer, there is some code that says
"Bump horizontal and vertical lines so they lie on pixel centres".
The solution for opengl (also works on software) is to draw your lines(rectangles)
with a half-pixel offset, ie:
(0.5,0.5) .. (10.5,0.5)

Hugh


Hi David,

Which target? It's weird because I had the opposite problem on iPhone, where I wanted sdl to draw non-anti aliased and I couldn't find a way to.

Did you try setting the stage quality to low?

Davide

On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:

Greetings list,

Just wondering if there's a way to anti alias drawing API calls (drawCircle, drawRoundRect etc) in NME. I found an earlier message on the list that went unanswered, and dug around the NME source looking for SDL configuration and the like... unfortunately my c++ is letting me down.

Thanks :)
David
--
haXe - an open source web programming language
http://haxe.org

--

haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

Gamehaxe
In reply to this post by davidedc
Hi,
Yes, if you could put your patch in using the new flags, that would be  
great.
I'm still thinking whether or to to change it dynamically - and if
not, then how to allow it to be a user setting (restart required)
rather than a compile time setting.
My current plan is to add something to the nmml.

Hugh

> Ha! In fact Zjnue and I were just watching in realtime the multisampling
> work you just submitted.
>
> Hopefully the iPhone patch could be useful then. If I have the time/can
> figure out how you've organized the flags I'll put my patch in place in a
> "clean" way, so far it works with #defines, which is kind of bad.
>
> Cheers,
> Davide
>
> On Sun, Jun 26, 2011 at 3:23 PM, Gamehaxe <[hidden email]> wrote:
>
>> Hi,
>> Funny you should mention this, because I've just been adding OpenGL AA.
>> So far it is only for SDL targets, but I hope to do the others
>> (android,ios)
>> soon.
>> Currently, the best way to do this might be to use "cacheAsBitmap".
>> The will use the software renderer to render a texture, then use the
>> texture.
>> This will also fix radial gradients. It depends on how much your
>> objects move/rotate.  It may actually be a performance win if the
>> objects are relatively static.
>>
>> Hugh
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

Gamehaxe
In reply to this post by davidedc
Hi,
The stage quality setting affects the line AA (rather than the "solid AA",  
ie rectangles)

There is some code that looks like this:

    if (mQuality>=sqBest)
      glEnable(GL_LINE_SMOOTH);
    else
      glDisable(GL_LINE_SMOOTH);

The default stage quality starts lower on mobile devices.

Anyway, you should use the half-pixel offsets otherwise you are placing
the line exactly in the middle of two centres.  In this case, you are
leaving it up to opengl to choose which of the two to use.

Hugh



> Cause I didn't see that behaviour there.
>
> D
>
> On Sun, Jun 26, 2011 at 3:33 PM, Gamehaxe <[hidden email]> wrote:
>
>> Hi,
>> To get "crisp" lines in opengl, you have to consider 1/2 pixel  
>> alignment.
>> When you draw lines your vertices specify the centre of your line.
>> However, opengl samples the "Infinite Cartesian Plane" at the centres
>> of pixels, ie (0.5,0.5)  (1.5, 0.5), (2.5,0.5) ....
>> So, if you draw a line form (0,0) to (10,0) the line will start halfway
>> between the (0.5,-0.5) and the (0.5,0.5) pixels - therefore it will be
>> "half grey" on two lines.
>> When using the software renderer, there is some code that says
>> "Bump horizontal and vertical lines so they lie on pixel centres".
>> The solution for opengl (also works on software) is to draw your
>> lines(rectangles)
>> with a half-pixel offset, ie:
>> (0.5,0.5) .. (10.5,0.5)
>>
>> Hugh
>>
>>
>>  Hi David,
>>>
>>> Which target? It's weird because I had the opposite problem on iPhone,
>>> where I wanted sdl to draw non-anti aliased and I couldn't find a way  
>>> to.
>>>
>>> Did you try setting the stage quality to low?
>>>
>>> Davide
>>>
>>> On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:
>>>
>>>  Greetings list,
>>>>
>>>> Just wondering if there's a way to anti alias drawing API calls
>>>> (drawCircle, drawRoundRect etc) in NME. I found an earlier message on  
>>>> the
>>>> list that went unanswered, and dug around the NME source looking for  
>>>> SDL
>>>> configuration and the like... unfortunately my c++ is letting me down.
>>>>
>>>> Thanks :)
>>>> David
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>
>>> --
>>>
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

davidedc
Ah I see.

I couldn't get any kind of smooth directives to work on the iOS GPUs (I guess it's really a low-power GPU thing, looking at the forums), that's why I resorted to the full-screen multisampling patch (and couldn't use caching because Processing doesn't support that model out of the box, I'd have to build some transparent caching mechanism for shapes that show up a lot, that would be a smart thing to do actually).

D


On Sun, Jun 26, 2011 at 3:50 PM, Gamehaxe <[hidden email]> wrote:
Hi,
The stage quality setting affects the line AA (rather than the "solid AA", ie rectangles)

There is some code that looks like this:

  if (mQuality>=sqBest)
    glEnable(GL_LINE_SMOOTH);
  else
    glDisable(GL_LINE_SMOOTH);

The default stage quality starts lower on mobile devices.

Anyway, you should use the half-pixel offsets otherwise you are placing
the line exactly in the middle of two centres.  In this case, you are
leaving it up to opengl to choose which of the two to use.

Hugh




Cause I didn't see that behaviour there.

D

On Sun, Jun 26, 2011 at 3:33 PM, Gamehaxe <[hidden email]> wrote:

Hi,
To get "crisp" lines in opengl, you have to consider 1/2 pixel alignment.
When you draw lines your vertices specify the centre of your line.
However, opengl samples the "Infinite Cartesian Plane" at the centres
of pixels, ie (0.5,0.5)  (1.5, 0.5), (2.5,0.5) ....
So, if you draw a line form (0,0) to (10,0) the line will start halfway
between the (0.5,-0.5) and the (0.5,0.5) pixels - therefore it will be
"half grey" on two lines.
When using the software renderer, there is some code that says
"Bump horizontal and vertical lines so they lie on pixel centres".
The solution for opengl (also works on software) is to draw your
lines(rectangles)
with a half-pixel offset, ie:
(0.5,0.5) .. (10.5,0.5)

Hugh


 Hi David,

Which target? It's weird because I had the opposite problem on iPhone,
where I wanted sdl to draw non-anti aliased and I couldn't find a way to.

Did you try setting the stage quality to low?

Davide

On 26 Jun 2011, at 08:18, David Peek <[hidden email]> wrote:

 Greetings list,

Just wondering if there's a way to anti alias drawing API calls
(drawCircle, drawRoundRect etc) in NME. I found an earlier message on the
list that went unanswered, and dug around the NME source looking for SDL
configuration and the like... unfortunately my c++ is letting me down.

Thanks :)
David
--
haXe - an open source web programming language
http://haxe.org


--

haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Graphics anti-aliasing in NME

nerik
This post has NOT been accepted by the mailing list yet.
Hi there,

Well it's basically an up. Is the patch on the repo now?
I can see the bug is still open : http://code.google.com/p/nekonme/issues/detail?id=54

There's an antialiasing="4" argument on the <window> tag of nmml files, but if I understood correctly it only applies to bitmaps (via SDL)?

Thx
Erik
Reply | Threaded
Open this post in threaded view
|

C group

tieunguyet
This post has NOT been accepted by the mailing list yet.
In reply to this post by David Peek