0

I'm trying to make anaglyps to show antenna diagrams for my students. I used one of the classic techniques by using glAccum: Draw left eye, 'load' into the accumulator, draw right eye, and Accumulate, the bring the Accu back in front. (Note that I know this does not produce a perfect anaglyph. After all I'm not even using perspective projection - I use glOrtho (maybe that is the problem?). I am just concerned why glAccum isn't working as expected)

This seems to work, but only partly. axis in 3D

The image shows an axis system in 3D, which shows that the generation actually works, but at the left, RED incorrectly overwrites CYAN while at the right, CYAN actually mixes with RED producing white, as it should do. Maybe the following images are clearer:

axis in 3D axis in 3D

The left image show expected color addition while the right image shows red overwriting cyan.

Can anyone shed some light on this? The actual plot is more complicated of course.

BTW, I know of the other methods to generate anaglyphs...

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
jcoppens
  • 5,306
  • 6
  • 27
  • 47
  • You get any GL errors? – Grimmy Jun 10 '13 at 06:00
  • I hate to break it to you, but the way you're rendering the views for the eyes is wrong. What you currently do is rotating the view (either by using LookAt at the two eye positions toward a convergence point, or by using glRotate directly). What you actually must do is using an asymmetric/shifted frustum, with translated viewpoint (off-axis projection). See this answer by me http://stackoverflow.com/a/7484143/524368 – datenwolf Jun 10 '13 at 09:57
  • 1
    @Grimmy: thanks for the advice! Yes, as I tried to flag in the original message, I am aware of the weaknesses of the system I am using. I am not so much interested in obtaining a picture-perfect anaglyph, after all I am also using glOrtho, which doesn't help either. I **was** intrigued as to why the accumulator wasn't combining the images as (I) expected. – jcoppens Jun 10 '13 at 15:03
  • Sorry - my confusion: @Grimmy: No errors at all. – jcoppens Jun 10 '13 at 15:36
  • @datenwolf: The commend about the weaknesses of my anaglyph generation were destined for you - I even found a doc I read about the issue [link][http://www.orthostereo.com/geometryopengl.html] – jcoppens Jun 10 '13 at 15:41
  • 3
    do you clear your render between the 2 eyes? – Bahbar Jun 10 '13 at 17:08
  • 2
    @jcoppens: Actually, you don't even need the accumulation buffer at all. You could just use a sequence like `clear(color|depth);glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_FALSE); draw_left(); glColorMask(GL_FLASE,GL_TRUE,GL_TRUE,GL_FALSE); clear(depth); draw_right()` to get red/cyan anaglyph images. – derhass Jun 10 '13 at 18:59
  • @derhass: Yes, I have read several documents on that method. I will test it, but I would like to know why this basic operation does not work... – jcoppens Jun 10 '13 at 22:04
  • @Bahbar: Thanks for the suggestion, I added a glClear(GL_COLOR_BUFFER_BIT), but it made no difference. – jcoppens Jun 10 '13 at 23:45
  • Some actual rendering code using said accumulation buffer technique would be interesting, wouldn't it? – Christian Rau Jun 11 '13 at 08:45

1 Answers1

0

Well, @Bahbar's idea pointed me into the right direction. Though I have actually seen various pages with examples where it's not done, I suspected that clearing the depth buffer could have an effect on the graph. So I added

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

in between rendering both views, and the problem was solved!
Looking around more on the 'net, I actually found examples where it is done that way. I'm happy - I even added the correct, frustum-based stereo perspective. The result is:

good plot

Thanks for the attention, maybe this can help someone else...

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
jcoppens
  • 5,306
  • 6
  • 27
  • 47
  • Glad I could be of help. For what it's worth, the reason I suggested it was that it looked to me like your second render had z-test happening from the first render Z. (on one side, red was occluding, on the other it was not). I should have called out Z-buffer specifically! – Bahbar Jun 11 '13 at 08:01
  • @Bahbar: The internet info is a great tool, but it can also provide for great confusion... I'll work out some other kinks in the program, and publish the code. Maybe save someone else a headache. Cheers! – jcoppens Jun 11 '13 at 15:04