7

Although I have been discouraged from reading the OpenGL redbook, I am still doing it, because it is the only book designed for beginners, and tutorials and/or documentation don't quite substitute for a book although very important. So much for justifying myself :)

Now, there's an example for antialiasing using multisampling, which involved glEnable(GL_MULTISAMPLE);

I am using Qt, and I get a compile error, because GL_MULTISAMPLE is an undeclared identifier. I currently see the following reasons:

  • For some implementations, including the one that comes with Qt, GL_MULTISAMPLE is not defined.
  • It is not in GL/gl.h or GL/glu.h but rather in some other header which is not included in <QGLWidget> or does not come with Qt
  • It is obsolete/deprecated

Is one of the above reasons correct? If not, which is the reason I don't have it and how can I obtain? Thanks in advance

Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
  • There are many opengl books besides the red book, most of them are much better for beginners. – stonemetal Nov 17 '10 at 18:00
  • @stonemetal: Which would you recommend? – Armen Tsirunyan Nov 17 '10 at 18:00
  • I'm not sure why people would discourage you from reading it, I think it's an excellent book that gets to the core concepts. – Aaron H. Nov 17 '10 at 18:30
  • @ Armen Tsirunyan If you just need to learn the API I suggest the OpenGL Super Bible. If you don't know anything about computer graphics and need to know more about the math side of things Computer Graphics Using OpenGL by Hill and Kelley – stonemetal Nov 22 '10 at 16:49

4 Answers4

6

Since you said you're using Qt's libraries then GLEW etc probably isn't necessary since Qt wraps and binds the extensions for you.

If you're using QGLWidget it's particularly easy. Check this example that ships with Qt and uses GL_MULTISAMPLE, particularly the glwidget.cpp file which defines:

#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE  0x809D
#endif

If you want to customise the FSAA samples, pass your own QGLFormat to the QGLWidget constructor eg:

QGLFormat format;
format.setDoubleBuffer(true);
format.setDepth(false);
format.setAlpha(false);
format.setSampleBuffers(true);
format.setSamples(4);
QGLWidget *glw = new QGLWidget(format);

Change format.setSamples(4) to your liking. Be sure to add glEnable(GL_MULTISAMPLE) in your paintGL() function before rendering your scene.

ʀᴏʙ
  • 1,708
  • 1
  • 13
  • 7
4

GL_MULTISAMPLE is an used to be extension to OpenGL, until 1.3, and whether or not it is implemented depends on your hardware/drivers/vendor implementation. You might actually want to use GL_MULTISAMPLE_ARB instead. If you are on Windows, the platform provided OpenGL headers will not include this macro.

See also:

RA's response will simplify extension handling - I prefer the use of GLee myself, but they are pretty much interchangeable (and GLee does lazy init which helped me fix a critical issue on Solaris), but GLEW is kept more up to date (GLee is outdated now that Kos has brought it to my attention.).

wkl
  • 77,184
  • 16
  • 165
  • 176
  • Umm... That should read "*used to be* an extension", multisampling's been a part of OpenGL core for a long time now. BTW- is GLee kept up to date now? There are GLEW and GL3W which don't have "lazy inits" but are up-to-date with GL 4.1. – Kos Nov 17 '10 at 18:38
  • @Kos - thanks for the comment. Looking at GLee, it is way out of date now, but the last time I used it was around the last release of it (late 2009). I replaced GLEW with GLEE specifically because GLEE provided Lazy Init and the software bug I had no time to fix was due to developers creating/destroying/recreating GL Contexts which did not end well on a custom Solaris port. GLEE's lazy init saved the company there. :) – wkl Nov 17 '10 at 19:03
3

A library for helping out with extensions http://glew.sourceforge.net/

ROAR
  • 1,304
  • 1
  • 11
  • 28
1

GL_MULTISAMPLE is defined within glext.h, glext.h is contained inside some linux package: glew, gtkglext or with some opengl driver (have a look here: http://www.opengl.org/registry/#headers).

angleto
  • 114
  • 4