Antialiasing support in Cafu?

Get help with installing and running the Cafu Engine here. This forum is also for general questions and discussion of all aspects regarding the Cafu Engine.
Post Reply
User avatar
BRabbit
Posts:28
Joined:2010-08-16, 19:26
Location:Moscow, Russia
Antialiasing support in Cafu?

Post by BRabbit » 2010-12-01, 23:18

Does any of the renderers bundled with Cafu support antialiasing? If not, i would like to implement it (I found the following webpages with information on using antialiasing with OpenGL: http://glprogramming.com/red/chapter06.html#name2, http://nehe.gamedev.net/data/lessons/le ... ?lesson=46 and http://www.opengl.org/wiki/Multisampling)

Also i'm developing a DirectX 9 Renderer for cafu, but the Cafu engine executable will have to use pure Win32 windows given that DirectX can't be used with wxWidgets (of course only in Windows).
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Antialiasing support in Cafu?

Post by Carsten » 2010-12-02, 01:06

BRabbit wrote:Does any of the renderers bundled with Cafu support antialiasing? If not, i would like to implement it (I found the following webpages with information on using antialiasing with OpenGL: http://glprogramming.com/red/chapter06.html#name2, http://nehe.gamedev.net/data/lessons/le ... ?lesson=46 and http://www.opengl.org/wiki/Multisampling)
Are you referring to full-screen anti-aliasing (FSAA)?
Cafu doesn't have it, and any help with adding it would much be welcome!

Note however that FSAA can already be enabled with Cafu as-is when you set the settings of your video driver appropriately (afaik, at least the NVidia drivers allow to force-set FSAA settings for applications).
(Explicit support in Cafu would of course be welcome nevertheless!)

Also, FSAA is enabled at window-creation time, that is, by the wxGLCanvas class. I normally follow changes in wxGLCanvas closely, but did not fully so when FSAA support was introduced - afaik wxGLCanvas has FSAA support built in, but I've not looked into it yet.

Also i'm developing a DirectX 9 Renderer for cafu,
Oh! I'd be very interested in this (especially with an eye on DX10 and DX11), please let us know how things go! :wohow:
but the Cafu engine executable will have to use pure Win32 windows given that DirectX can't be used with wxWidgets (of course only in Windows).
Hm, I see that DX doesn't run under Linux, but why can DX not be used with wxWidgets?
Ttbomk, you could use a plain wxWindow instead of the wxGLCanvas, get the (Windows-specific) handles from it, and use those to initialize DX (?).
Best regards,
Carsten
User avatar
BRabbit
Posts:28
Joined:2010-08-16, 19:26
Location:Moscow, Russia

Re: Antialiasing support in Cafu?

Post by BRabbit » 2010-12-02, 02:49

OMG!!! I did it (again)!!! :shock:

CAFU with ANTIALIASING (technically, multisampling).

A picture is worth a thousand words:
comparision.png
All that is necessary to get antialiasing in Cafu is to do add some code to a Ca3DE source file:

-Go to MainCanvas.cpp and change the OpenGLAttributeList[] (line 97) to the following:

Code: Select all

static int OpenGLAttributeList[]=
{
	WX_GL_RGBA,
	WX_GL_DOUBLEBUFFER,
	WX_GL_MIN_RED,       8,
	WX_GL_MIN_GREEN,     8,
	WX_GL_MIN_BLUE,      8,
	WX_GL_MIN_ALPHA,     8,
	WX_GL_SAMPLE_BUFFERS, GL_TRUE,
	WX_GL_SAMPLES, 4, // Change this line if you need less/more samples
	WX_GL_DEPTH_SIZE,   16,
	WX_GL_STENCIL_SIZE,  8,
    0   // Zero indicates the end of the array.
};
NOTE: You can change the WX_GL_SAMPLES to any multiple of 2 with a maximum of 16, i guess (change this accordingly to what your graphic card actually supports)

Then, add the following to the MainCanvasT::MainCanvasT constructor: (line 130):

Code: Select all

MainCanvasT::MainCanvasT(MainFrameT* Parent)
    : wxGLCanvas(Parent, wxID_ANY, OpenGLAttributeList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS, "CafuMainCanvas"),
      m_Parent(Parent),
      m_InitState(INIT_REQUIRED),
      m_GLContext(NULL),
      m_RendererDLL(NULL),
      m_SoundSysDLL(NULL),
      m_GameDLL(NULL),
      m_Client(NULL),
      m_Server(NULL),
      m_SvGuiCallback(NULL),
      m_ConByGuiWin(NULL),
      m_Timer(),
      m_TotalTime(0.0),
      m_LastMousePos(IN_OTHER_2D_GUI)
{
    m_GLContext=new wxGLContext(this);

    SetCursor(wxCURSOR_BLANK);
    SetBackgroundStyle(wxBG_STYLE_PAINT);
    glEnable(0x809D);
}
What is 0x809D? Well, it's just the #define GL_MULTISAMPLE in the glext.h file, but i was too lazy to include it :roll:

And that's it! :up: (Quite easy, isn't it?).

Now I'm trying to add a dropdown on the Video Options dialog to enable/disable FSAA and edit how many samples to use. :beta:

And be warned! My FPS went down exactly 33% less with antialias 4x enabled. (Not to mention how was it like with Fraps enabled)
Also I don't know how this works with hardware that does not support antialias.
Carsten wrote:(afaik, at least the NVidia drivers allow to force-set FSAA settings for applications
Yes, I remember using my Geforce 5200 and the nvidia control panel to enable antialias in EA's Rugby 06. It was anything but acceptable!
Carsten wrote:but why can DX not be used with wxWidgets
I thought the same, but still has some conflicts regarding the flicker rate. I have to make a more deep google search for it. :google:
Carsten wrote:especially with an eye on DX10 and DX11
Yes, that would be great too, but although I'm using win7 there are lots of people using XP where there's no DX10+... So maybe the first thing to do is a DX9 fallback renderer (or even less, a la Valve) and then adapt subsequently new versions.

I'm having a look at the code of Ogre and how it makes a unique renderer interface which is implemented by a DX and a OpenGL renderer. I have also read that it's rather easy to use Ogre and wxWidgets and inside them, DirectX.
Also Irrlicht (another german 3D engine, but not as stunning as Cafu! :D ) does the same thing.
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Antialiasing support in Cafu?

Post by Carsten » 2011-04-03, 06:20

Hi BRabbit,

your results with FSAA look very impressive! :-D

In order to integrate it into the official Cafu code, we'd however need support for configuring it (off, 2x, 4x, ...) in the games Main Menu GUI, which in turn requires querying the proper OpenGL extension as well. If you can provide the related details (a patch would be ideal), I'd be happy to integrate them into the Cafu repository.

Your details about DX look very promising as well!
(While I don't see anything that DX can do that OpenGL cannot, supporting a DX renderer would be a very worthwhile effort nevertheless! :up: )


Last bumped by BRabbit on 2011-04-03, 06:20.
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests