Two questions on JOGL bindings

Hi, everybody

Just started playing with JOGL and following the examples in the red book, tried to create a 3D model. The first question is about creating a custom 3D model and shading it - i see seams all over the place. It looks like the quad strips are broken into triangles and the edges are not rendered properly. When i use a “bundled” 3D model (glutSolidTorus), it is rendered without seams. I searched for it on the web and the explanations there seem to be way too complicated for such a simple issue. Is there something i’m missing in the source code (run the attached and see that the torus has seams)?

In addition, i’ve played a little with custom textures and TextureIO and different modes to pass to glTexEnvf. If i create a custom texture as a bytearray, all four modes (DECAL, REPLACE, BLEND, MODULATE) work as expected, but when i load a texture from a JPG file using TextureIO, then the BLEND mode uses an invert of the original JPG image (run the attached and see that the torus is painted green-blue instead of red). Is this a known issue or something wrong in the attached program?

Thanks
Kirill

The normals should be computed like this:

				double rx = Math.cos(t * twopi / numt);
				double ry = Math.sin(t * twopi / numt);
				gl.glNormal3d(x-rx, y-ry, z);

But it still doesn’t change the seams and texturing (only the lighting).

Something is wrong with your geometry, as can be seen by using the X and Y keys to view it edge on. I think either your normals are inverted or the geometry is being specified with the wrong orientation of the faces.

The seams are being caused by your enabling of blending. I don’t understand fully why at this point but it’s probably related to the incorrect geometry. I’d suggest you fix that first and go from there. You can look at the source code for the com.sun.opengl.util.GLUT class, method doughnut(), and try matching up your code with that to see what is wrong.

The geometry might be wrong, but this doesn’t affect the two questions i’ve asked. After replacing the custom model with

	GLUT glut = new GLUT();
	glut.glutSolidTorus(0.5, 1.0, 10, 50);

and leaving only

    gl.glDepthFunc(GL.GL_LESS);
    gl.glEnable(GL.GL_DEPTH_TEST);

(having old CULL, … affects the GLUT torus as well on rotation with that “wrong” geometry), produces the attached results:

  1. no-texture.png shows the original white torus

  2. modulate.png shows reddish torus under GL_MODULATE texture mode (as expected)

  3. blend.png shows cyan torus under GL_BLEND texture mode (using the same texture as 2. above)

  4. smooth.png shows torus with seams when the following are enabled:

     gl.glEnable(GL.GL_POLYGON_SMOOTH);
     gl.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST);
     gl.glEnable(GL.GL_BLEND);
     gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    

Kirill

I don’t know what polygon smoothing does and have never used it in any of my own OpenGL applications. Especially given that it seems to be producing rendering artifacts I’d suggest you leave it turned off. The same goes for GL_AUTO_NORMAL, which doesn’t apply since you aren’t using evaluators. In general you want to enable as few state bits as possible, and only those which are necessary, both for best performance and to avoid accidentally enabling state bits which may affect your rendering output.

The blue color is what is expected if you apply the GL_BLEND texture environment function to the incoming fragment and your red texture. See the man page for glTexEnv and read carefully the definition of the various terms in the GL_RGB equation.

BTW, you aren’t supplying texture coordinates for your vertices, which you would need if you were using a texture containing anything but a solid color.

Thanks for the clarification on BLEND mode - the only thing that is bothering me is that when i create the texture using byte arrays, the BLEND mode still produces reddish torus.

The polygon smoothing is there to remove the jaggies around the torus. As you can see, both the inner and the outer rim of the torus are not anti-aliased. Is there another simple way to paint it as anti-aliased (without going too deep in supersampling, jittering and so on)?

Thanks
Kirill

If you think there is a bug in the TextureIO classes then please provide a small and self-contained test case that clearly shows the issue. I think you’d need to investigate this a little further in this case – so far I don’t see evidence of a bug.

You can try full-scene antialiasing, which is the recommended technique nowadays. See demos.multisample.Multisample in the jogl-demos workspace for an example.

Perhaps it’s too late and you no longer care, but I’m fairly sure that the seams on the smooth torus are caused by the combination of polygon antialiasing and blending. I would suggest reading up on the polygon/line/point aa sections in the red book as well as the section on edge flags. I believe that edge flags may fix the seams although I’ve never had a reason to use them yet and have looked into them that much.

A post on the apple OpenGL mailing list provides some ideas on how to work around the POLYGON_SMOOTH artifacts.