0

I am using OpenGL with C++ (but without shaders and GLSL) and drawing spheres (the pool ball) and cylinders (the cue stick) using the glu library functions to draw them. I am using glBindTexture() to bind the texture and loading the texture using the SOIL library.

As you can see from the screenshots there are jagged edges to both the cylinder and the sphere. Calling the following glHint() How do I get rid of the jagged edges. The gluSphere() has 25 stacks and slices, and the gluCylinder() has 100 stacks and slices. Increasing the stacks and slices does not improve the image quality.

Using freeglut for the rest of the drawing

glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); //Smooth polygons
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Best perspective corrections
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); //Smooth points
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); //Smooth lines

Screenshot

viraj
  • 1,784
  • 4
  • 35
  • 52

1 Answers1

3

First of all your question is related to aliasing term, this is what is happen when tringles and some other primitives (these are very basic objects which create whole scene) are rasterized (based on geometric description some pixels on the screen are colored or not). Try to look for "How to turn on antialiasing" - here is many usefull informations about this and some related topics: http://www.glprogramming.com/red/chapter06.html. In your case it will be probably glEnable for GL_POLYGON_SMOOTH and GL_BLEND for sure. eg.

glEnable (GL_POLYGON_SMOOTH);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);

If you plan to use lines there will be GL_LINE_SMOOTH and GL_LINE_SMOOTH_HINT.

For future projects try to not use so complex models if they are far from viewer (making as many slices for sphere), this will cause loss of performance.

Marek Kijo
  • 173
  • 1
  • 9
  • Is there any other way to draw spheres and cylinders without the glu() functions? Or are you talking about reducing the number of stacks and slices? – viraj Jun 06 '13 at 04:55
  • EDIT: I had to enable GL_MULTISAMPLE as well. And pass GL_MUTLISAMPLE as a parameter to `glutInit()` to get Anti-Aliasing – viraj Jun 06 '13 at 05:01
  • 1
    Yes I was talking about reducing the number of stacks and slices - 25 is pretty hot, if you have couple of spheres built with so many triangles then you can get little performance loss - it is not critical in such scene but just keep it in your mind for future. Those functions are OK to do some samples (those models has good texture coords, and normal vectors), but for more anvanced projects try to look for some library to read models from files, a good one, and easy to use, with lot of features, is [assimp](http://assimp.sourceforge.net/). – Marek Kijo Jun 06 '13 at 08:08
  • Hmm. I feel that performance sort of plateaus out after a point. While tying to get rid of the jagged edges I increased the stacks and slices to some obscene number like 1000000 and still got the same performance. – viraj Jun 06 '13 at 11:47
  • 1
    Eg. slices & stacks args of gluSphere fun has some limitations, it depends on current implementation, eg. take a look at [Mesa implementation](http://cgit.freedesktop.org/mesa/mesa/tree/src/glu/sgi/libutil/quad.c?h=cxx-1-branch&=switch) of that method, look for gluSphere and track what is going on with those 2 args. In this case, if they are >= than const named CACHE_SIZE (== 240), they they are rounded to that value:) Try to do some test in your app, turn on wireframes to see how complex model is and start increasing slices & stacks, for sure you will notice that there is some limitation. – Marek Kijo Jun 07 '13 at 10:22