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

Author Topic: Mix OpenGL with SFML.Net? [Also: Where's my AA?]  (Read 6613 times)

0 Members and 1 Guest are viewing this topic.

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« on: June 29, 2013, 01:12:20 pm »
So, I want to draw some Antialiased shapes. Since SFML refuses to do so (I think it is because I am drawing to a GTK widget), I thought I might enable AA myself, via some GL calls. I might want to use some OpenGL later anyways, so not a bad idea to make sure it works.
My first try with OpenTK failed, I couldn't find out how to pass it the context it needs, so I got a whole bunch of null pointer exceptions and the like. So now I am using the much simpler Tao:

Gl.glEnable(Gl.GL_POLYGON_SMOOTH);
Gl.glEnable(Gl.GL_LINE_SMOOTH);
Gl.glHint(Gl.GL_POLYGON_SMOOTH_HINT, Gl.GL_NICEST);
Gl.glHint(Gl.GL_LINE_SMOOTH_HINT, Gl.GL_NICEST);
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
Color transparent = new Color(0, 0, 0, 0);
Vector2f origin = new Vector2f();
Vector2f loopOffset = new Vector2f(3600f, 0f);
foreach (ConvexShape part in Parts)
{
        part.FillColor = transparent;
        part.OutlineColor = Color.White;
        part.OutlineThickness = 2f;
        Draw(part);
        part.Origin -= loopOffset;
        Draw(part);
        part.Origin = origin;
}
 

But I still get no AA! Are all my enables reset by SFML when I call Draw(), or what else could I be doing wrong?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« Reply #1 on: June 29, 2013, 02:39:51 pm »
This is not the way to go. First, GL_POLYGON_SMOOTH is not advised, and second, you can't set OpenGL states and hope that they will apply to your SFML entities.

The only correct solution is to enable fullscreen anti-aliasing when you create the window (see the ContextSettings class).
Laurent Gomila - SFML developer

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« Reply #2 on: June 29, 2013, 02:48:27 pm »
This is not the way to go. First, GL_POLYGON_SMOOTH is not advised, and second, you can't set OpenGL states and hope that they will apply to your SFML entities.
Sorry about my ignorance. My experince with OpenGL is close to zero. I don't understand why I couldn't assume the states I set apply to SFML, but that doesn't matter anyways: even if I render with OpenGL directly, I don't get AA.

The only correct solution is to enable fullscreen anti-aliasing when you create the window (see the ContextSettings class).

Yeah, that's what I tried to do first, but it had no effect:
        ContextSettings settings = new ContextSettings();
        settings.AntialiasingLevel = 8;
        window = new RenderWindow(GetDrawingAreaHandle(), settings);

window.Settings.AntialiasingLevel stays at 0. It might have to do with me using a handle to a GTK widget (Gtk.DrawingArea) to build the RenderWindow, so I am thinking of trying to use OpenTK's GLWidget, instead.

Thanks for your help & patience.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« Reply #3 on: June 29, 2013, 02:54:29 pm »
Quote
Sorry about my ignorance
Don't be sorry. Everyone here is ignorant about something, otherwise the forum would be useless ;)

Quote
I don't understand why I couldn't assume the states I set apply to SFML, but that doesn't matter anyways
It's by design: SFML ensures that external OpenGL calls don't mess with its own internal states. This makes easier to mix SFML and OpenGL; the drawback, as you can see, is that it's impossible to "tune" SFML rendering with custom OpenGL calls.

Quote
Yeah, that's what I tried to do first, but it had no effect
Are you sure that your graphics driver supports anti-aliasing? Are you sure that it's not turned off in the driver settings?

Quote
It might have to do with me using a handle to a GTK widget
I don't know, this is a possibility. You should try to construct a true RenderWindow (not based on a GTK widget), to see if it changes something.
Laurent Gomila - SFML developer

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« Reply #4 on: June 29, 2013, 03:28:00 pm »
Are you sure that your graphics driver supports anti-aliasing? Are you sure that it's not turned off in the driver settings?

Yeah it does and it is enabled. In amdcccle, the card's control panel, everything relevant was set to respect the applications. Just to make sure I bumped up the AA settings to maximum, and restarted gdm, with the result of my whole desktop being blurry, but still no AA in the SFML game. The card is a AMD Radeon HD 7450, btw, a low end but relatively new card.

Quote
It might have to do with me using a handle to a GTK widget
I don't know, this is a possibility. You should try to construct a true RenderWindow (not based on a GTK widget), to see if it changes something.

Good call, I created a SFML RenderWindow and the issue persists, so it's not GTK's fault.
Then I tried the "opengl" & "window" demos: same thing. The RenderWindow refuses to accept the AA values I pass to the it's settings (changing other values, like depth or stencil bits, works, though).

EDIT: A Screenshot BTW, that also shows something weird, IMO, about how SFML renders shape outlines: I think the lines are outside the polygons instead of centered on the edges. E.g. if you use a 20px line, all pixels would end up outside the polygon, instead of 10px inside and 10 outside, as I would had expected. But that's another topic.
« Last Edit: June 29, 2013, 03:49:40 pm by cpolymeris »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« Reply #5 on: June 29, 2013, 05:07:17 pm »
What's your OS? Sometimes AA doesn't work on Linux.

Quote
BTW, that also shows something weird, IMO, about how SFML renders shape outlines: I think the lines are outside the polygons instead of centered on the edges. E.g. if you use a 20px line, all pixels would end up outside the polygon, instead of 10px inside and 10 outside, as I would had expected. But that's another topic.
The outline is indeed outside the shape. This is a design choice. You can have it inside by using a negative outline thickness, but not centered.
Laurent Gomila - SFML developer

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« Reply #6 on: June 30, 2013, 12:03:05 am »
What's your OS? Sometimes AA doesn't work on Linux.
Yes, it's Linux. I have been meaning to get this thing to compile on Windows, but haven't gotten around it (csfml-*2.dll issues). What a pity this doesn't work on Linux. I'll have a look at the SFML code, see if I learn something.

Quote
BTW, that also shows something weird, IMO, about how SFML renders shape outlines: I think the lines are outside the polygons instead of centered on the edges. E.g. if you use a 20px line, all pixels would end up outside the polygon, instead of 10px inside and 10 outside, as I would had expected. But that's another topic.
The outline is indeed outside the shape. This is a design choice. You can have it inside by using a negative outline thickness, but not centered.

I am sure it has it's reasons (it's called an "outline" after all), but that seems, from my point of view, like really weird choice: If I draw 2 adjacent polygons that share one edge, they will seem to overlap. No big deal, though, as I'll have to draw that map myself anyways, eventually (the "provinces" are concave and have holes).

Thanks again for all your help.

 

anything