MSAA in OpenGLContext


#1

Hi Jules,

 

I'm a newbie in the world of OpenGL and I'm actually trying to use multisampling to remove aliasing from my OpenGL context, in which I display a simple cylinder, with gluCylinder(). I have searched in this forum and on the Internet, and I've found that Juce handles multisampling thanks to this initialization code :

openGLContext.setMultisamplingEnabled(true);
OpenGLPixelFormat format;
format.multisamplingLevel = 4;
openGLContext.setPixelFormat(format);

I added this code in the JuceDemo, in OpenGLDemo.cpp, and it actually worked. But, when I try to use the same code for my cylinder, multisampling doesn't seem to be set correctly... So I wonder if it has something to do with the fact that JuceDemo uses shaders and I don't, if it has something to do with the fact that I use Glu, or if I've missed something in the initialization of multisampling. Here are the main points of my code (I work on VS2013) :

// When I create and attach my context to the renderer
mOGLContext = new juce::OpenGLContext();
mOGLContext->setComponentPaintingEnabled(true);
mOGLContext->setContinuousRepainting(true);
mOGLContext->setMultisamplingEnabled(true);
juce::OpenGLPixelFormat format;
format.multisamplingLevel = 8;
mOGLContext->setPixelFormat(format);

mOGLContext->setRenderer(this);
mOGLContext->attachTo(*this);


// When I set OpenGL attributes
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, (double)640 / 480, 1, 1000);

glViewport(0, 0, getWidth(), getHeight());


// When I draw in my context
glClearColor(0, 0, 0, 255);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(3, 1, 4, 0, 0, 0, 0, 0, 1);

GLUquadric* params = gluNewQuadric();
gluQuadricDrawStyle(params, GLU_FILL);
gluQuadricOrientation(params, GLU_OUTSIDE);
glRotated(180, 1, 0, 0);
gluCylinder(params, 0.05, 0.05, 3, 40, 1);
gluDeleteQuadric(params);

glFlush()

Thanks,

 

Lyøks


#2

No idea, sorry - presumably there's something that your code or GLU is doing that prevents the MSAA, but I'm not sure what it'd be. Maybe there's a GL guru out there who can suggest what you might be changing?


#3

glEnable(GL_MULTISAMPLE)? Not sure how it works with glu, but for primitives it is needed


#4

I've already tried this but Visual told me GL_MULTISAMPLE is undefined. I've actually checked in gl.h and there is no trace of GL_MULTISAMPLE... My version of OpenGL is 6.14 (if I'm not wrong), if it has something to do with it.

But it makes me think I didn't try to use

#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE 0x809D
#endif

I'm going to try this, I'll let you know.


#5

Official OpenGL information: https://www.opengl.org/wiki/Multisampling


#6

Yes, I have the same lines in my custom openGL header. Don't know why they're not defined.


#7

If it's missing, GL_MULTISAMPLE should probably be added here:

https://github.com/julianstorer/JUCE/blob/master/modules/juce_opengl/native/juce_MissingGLDefinitions.h


#8

OK this on the latest tip now


#9

Just adding glEnable(GL_MULTISAMPLE) doesn't seem to change anything, I'll try to use the buffers, to see how it goes.


#10

Finally, I found what my problem was, nothing to do with buffers or glEnable(GL_MULTISAMPLING). Just a silly mistake, I was using most of my OpenGL functions in the paint() of my component and not in renderOpenGL().

Thanks for your help even though !