Beau Gunderson's picture


I've been working on getting FSAA (the ARB_multisample extension) working with the glControl.

I feel like I'm pretty close but using SetPixelFormat to set the 'format' variable to the format I get back from Wgl.ARB.ChoosePixelFormat does not seem to have an effect.

I'm using the NeHe example and applying it to OpenTK. In WinGLControl.cs: c_HandleCreated() I prepare and create the context normally, then use the Wgl.ARB.ChoosePixelFormat function to get back a pixel format with 4 samples. I get back '32' at this point for the format. I then call PrepareContext and CreateContext again, passing in the pixel format.

It doesn't seem to have any effect, however, but I feel like this is kind of on the right track. Any pointers? :)

I can create a patch tomorrow if anyone would like to see what I have so far.




Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Beau Gunderson's picture

I should add that this is the code I am basing mine on:

the Fiddler.'s picture

You'll have to destroy the context (Wgl.DeleteContext), release the device context (API.ReleaseDC), call c.RecreateHandle(), acquire the new device context (API.GetDC), and only then set the new format.

Tao's SimpleOpenGlControl does something similar, you can find the code at, the methods of interest are InitializeContexts() and InitMultisampling(). The only reason I haven't ported this over to OpenTK is that I wanted to make it cross-platform first.

In any case, do upload what you have (even if it doesn't work 100% yet).

Beau Gunderson's picture

Ah, thanks for the pointers! I'll try to get this working tonight and send a patch. How funny that Tao already supports this, I tried getting it to work there too and must have not noticed it already had support for it! I will definitely stay with OpenTK though, I feel like the Wgl bindings are superior and I love the cleaner namespace.

the Fiddler.'s picture

It's not in the Tao SVN yet, that zip is a custom build. It is a useful feature however, so it will be in the next releases of both libraries.

Beau Gunderson's picture

I think I got it!

This code is probably very unnecessarily ugly and does not contain logic to check if the card actually supports FSAA (easy, just haven't done it yet).

I use it like so:

            DisplayMode d = new DisplayMode();
            d.Samples = 4;
            this.glControl1 = new OpenTK.GLControl(d);
the Fiddler.'s picture

Nice! While it's too late to add it in this release, FSAA will make it in the next release. Thanks for the code and keep me updated if you make any changes to the patch!

I just wanted to add that the next few releases will be pretty exiting feature-wise: the current one add adds mouse and timing support to GameWindow, as well as some multithreading enhancements, the next one will add FSAA, adaptive VSync and font-support, and the one after will finally bring Fullscreen mode setting. Thereafter, it's just joystick and GLU support and we are feature-complete! (for the first stable release at least)

logixoul's picture

What is the progress of this?

I'm using OpenTK 0.9.1 in WinXP, nVidia GeForce FX 5500, initializing GameWindow with:
new GraphicsMode(GraphicsMode.Default.ColorFormat,GraphicsMode.Default.Depth, GraphicsMode.Default.Stencil, 8)
And I do GL.Enable(EnableCap.Multisample);
But I don't get FSAA.

However in SDL.NET Video.GLMultiSampleSamples = 8; does work.


the Fiddler's picture

In short: the API is there, but the implementation is not. I'm going to need FSAA soon, so the implementation isn't far off.

Off topic: Do the 5x00 line of cards even support 8x FSAA? I'm pretty sure they can only do up to 4x (while the radeons of the time could go up to 6x on resolutions <= 1280x1024).

logixoul's picture

Cool, thanks :)

Don't know if 5x00 supports 8x. I picked the number at random, must have silently gotten 4x instead.