Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to do anaglyph 3D using LWJGL  (Read 10003 times)
0 Members and 1 Guest are viewing this topic.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Posted 2009-08-20 17:41:30 »

Here's a little tutorial about how to create the anaglyph stereoscopic 3D effect as I did it in Hyper Blazer.

Although it might need some tinkering to make it look good and even though anaglyph 3D is not the most effective stereoscopic 3D technique, it's a trick that's so easy to add to an existing OpenGL game that I hope to see more implementing it as it can really add something to the experience.
You do look like a total dork when you wear those silly red-cyan 3D glasses though Grin

I'm assuming you know what anaglyph 3D is, but if you don't, here's a link:
http://en.wikipedia.org/wiki/Anaglyph_image

So the idea is to render the image twice, one for your left eye and one for the right eye. Both images are filtered in a way that each eye only sees one image, and are blended together.

Both the direction and position of the left and right eye sights need to be changed a bit so that:
1) They are about 10 cm or so apart
2) They look slightly 'cross eyed'

Then the images should be filtered so that if you wear the red-cyan glasses, your left eye will only see the image meant for the left eye, and the right eye only sees the image meant for the right eye.
This means that since the left glass of red-cyan glasses is red, only the red colour component should be rendered for the left eye, and only green and blue should be rendered for the right eye. Then the images should be merged together.

Fortunately, in OpenGL this can be done with a super easy and neat trick: Using the glColorMask function:
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/colormask.html

So what you do each frame is this:
1) clear colour and depth buffers
2) set glColorMask to only render red
3) render the frame translated and rotated for the left eye
4) clear only the depth buffer (not the colour buffer because otherwise the previously rendered red image would get erased)
5) set glColorMask to only render green and blue
6) render the frame translated and rotated for the right eye

In Hyper Blazer, it looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        if (anaglyphMode) {
            GL11.glColorMask(true, false, false, true);
            renderEye(-eyeDistance, -crossEyedness);

            GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);

            GL11.glColorMask(false, true, true, true);
            renderEye(+eyeDistance, +crossEyedness);

            // reset the colormask again for things like HUD rendering or other things that do not have depth
           GL11.glColorMask(true, true, true, true);
        } else {
            // no anaglyph mode means rendering for just one 'eye'
           renderEye(0, 0);
        }

        renderHUD();


renderEye() renders everything in the game with 3D depth
renderHUD() renders things with no 3D depth (like the HUD)

The 'eyeDistance' will be used in the renderEye() method to translate the camera position a bit along the x-axis (so that both virtual 'eyes' have a distance in between them)

The 'crossEyedness' will be used in the renderEye() method to slightly rotate the camera around the z-axis.
This is VERY important because it determines how far the player is looking and how the depth will appear. Where the lines of sight of both eyes meet will be rendered with no depth.
With no crossEyedness, the player would be looking infinitely far, which implies that the game is rendered such that everything pops out of the TV screen and the farthest object would appear at the location of the screen, which doesn't look natural.
What you want is that most of the image appears 'behind' the screen, and some really close objects popping out of the screen so you'll have to adjust the crossEyedness value for that.
Without crossEyedness, the effect mostly doesn't work at all.

Some notes:
* You will have to avoid colours like full red, green or blue. They will appear only in one eye, which will give you a big headache and no depth. In Hyper Blazer, all colours are a somewhat greyed out in anaglyph mode to avoid this.
* In my experience, the effect usually doesn't work very well on laptop screens, but it works quite well on my flatscreen TV and my CRT monitor
* Adjust the eyeDistance and crossEyedness in such a way that you don't overdo the effect. Overdo it, and you'll get a headache
* Obviously using anaglyphic rendering will cost performance as the whole scene has to be rendered twice per frame
* I used LWJGL in the example code, but of course any OpenGL binding will do
* You can easily order red-cyan 3D glasses on the internet. They're dirt cheap

Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #1 - Posted 2009-08-21 14:08:03 »

(I recently implemented anaglyph in minecraft)

You've made a mistake. If you bring the eyes apart and rotate the direction they look, objects infinitely far away will be rendered infinitely far apart on the screen. In reality, things infinitely far apart is straight ahead on both eyes. What you really want to do is SKEW the projection matrices.

Here's what I did (Eye is either -1 or 1)

1  
2  
3  
4  
5  
6  
7  
8  
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef(-eye*stereoScale, 0, 0);
gluPerspective(70, aspect, 0.05f, renderDistance);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(eye*0.10f, 0, 0);
moveCameraToPlayer(a);


To make it perfectly correct, you need to know the eye separation of the player, the distance from the player to the monitor and the size of the monitor.
Then you need to set the fov to match what the player would actually be able to see through the screen, and calculate the skew so objects at screen distance would be rendered with an offset of 0, or so that objects at infinity would be rendered exactly eye distance apart (these two will match up if you know the exact head->screen distance and do the fov calculation right).

Play Minecraft!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2009-08-21 15:22:33 »

Quote
If you bring the eyes apart and rotate the direction they look, objects infinitely far away will be rendered infinitely far apart on the screen.
If you consider that you look slightly cross eyed if you look at an object near to you, then why shouldn't it be rendered that way?
That's exactly what your eyes do, isn't it?

Quote
In reality, things infinitely far apart is straight ahead on both eyes.
Yes, but only if you're looking at things infinitely far.
Not if you look at something close to you because your eyes are then rotated inwards to the object you're looking at.

Now I'm not saying that it's impossible I made a mistake, but I'm not sure I follow your argumentation of what I did wrong and why things should be skewed instead of rotated.
In any case, I'm going to try what happens if I use your way of doing it.

Anyway thanks for the feedback

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #3 - Posted 2009-08-21 15:41:26 »

The point is to force the viewer to cross his eyes to see the object, not to render the object from a crossed perspective.

Awesome graph:
http://www.mojang.com/notch/misc/anaglyph.jpg

The black boxes are the boxes we wish to render. The black circles are the eyes. The black lines are the screens.
The colored lines show the projections.
The bottom area shows how it shows up on the screen.

In front of screen, at screen, behind screen, and at infinity.

Play Minecraft!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #4 - Posted 2009-08-21 16:56:40 »

That is indeed an awesome graph  Smiley

I see what you mean.

Still I can't really wrap my head around why my method is wrong.
And thinking about it, this statement is actually wrong:
Quote
If you bring the eyes apart and rotate the direction they look, objects infinitely far away will be rendered infinitely far apart on the screen.
This implies that an object infinitely far away is not rendered because it would be outside of the screen in both view ports, but I think you don't take the FOV into account.
If you look at my attached awesome graph, you'll see what I mean.
(The black box is what the 2 eyes are looking at. Even at that view, objects infinitely far away will not be rendered infinitely far apart on screen)

Could it be that my method is just different from yours with perhaps a slightly different result and not actually plain wrong?

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #5 - Posted 2009-08-21 17:14:40 »

I have allways done stereoscopic image with only a translation. Even stereoscopic camera doesn't do rotation.

I think the trick is that camera are not eyes. Camera will provide an image for each eyes and then your eyes will do the focus.
You can't predict where the user will focus on (Background ? Far away object ? Near object ?) so you can't define a rotation.
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #6 - Posted 2009-08-21 17:18:11 »

Oh, yes, you're right! I totally didn't think that one through. Yes, you can rotate and have things at infinity still show up on the screen.
Thanks for graphing it so I understand. Cheesy

My gut feeling is still that a skew is right, but I have no proof now.


There's another improvement to be done. If you just no the glColorMask think, a pure red object will be black on one eye and white on the other, and a pure cyan object will be reversed.
To solve this, you need to make the red eye see a monochrome version, and mix in the red color on the cyan eye. I added this to my textureloader and anywhere I manually set a color:

(The average intensity of a color is r*0.3+g*0.59+b*0.11)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
            if (Minecraft.STEREO_3D_MODE)
            {
                int rr = (r * 30 + g * 59 + b * 11) / 100;
                int gg = (r * 30 + g * 70) / (100);
                int bb = (r * 30 + b * 70) / (100);

                r = rr;
                g = gg;
                b = bb;
            }

Play Minecraft!
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #7 - Posted 2009-08-21 17:25:54 »

Just plain glColorMask:


With the color mixing:


(Look through the glasses, compare the left eye image to the right eye image)

Play Minecraft!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2009-08-21 17:28:16 »

Except that the hearts are grey now persecutioncomplex

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #9 - Posted 2009-08-21 17:38:31 »

That's because they're red. With anaglyph, you lose one color channel.

You can't show a red color that has the same color intensity on both eyes, because to the left eye EVERYTHING is red, and to the right eye NOTHING is.

Play Minecraft!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #10 - Posted 2009-08-21 18:45:21 »

I have allways done stereoscopic image with only a translation. Even stereoscopic camera doesn't do rotation.

I think the trick is that camera are not eyes. Camera will provide an image for each eyes and then your eyes will do the focus.
You can't predict where the user will focus on (Background ? Far away object ? Near object ?) so you can't define a rotation.

In fact cameras are very much like eyes.

"In fact slight rotation inwards (also called 'toe in') can be beneficial. Bear in mind that both images should show the same objects in the scene (just from different angles) - if a tree is on the edge of one image but out of view in the other image, then it will appear in a ghostly, semi-transparent way to the viewer, which is distracting and uncomfortable. Therefore, you can either crop the images so they completely overlap, or you can 'toe-in' the cameras so that the images completely overlap without having to discard any of the images."
http://en.wikipedia.org/wiki/Stereoscopy

Your stereo camera setup defines what you look at, exactly like a single camera. You as a user can still look somewhere else, but it won't be where the camera intended it. Again, exactly like a single camera.
In an ideal world, you'd wear contact lenses with little monitors in them that would track the rotation of both eyes and adjust the view ports accordingly. But that's not really viable yet, so we're stuck with one 2D screen with a fixed view that we somehow want to translated to a stereoscopic image.
Well, that's my theory anyway  Smiley

@Markus_Persson:
Cool, I'll check that out when I get home!  Cheesy
Now I just prevent it by greying everything out a bit, but maybe your method is better.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #11 - Posted 2009-08-22 00:56:43 »

That's because they're red. With anaglyph, you lose one color channel.

You can't show a red color that has the same color intensity on both eyes, because to the left eye EVERYTHING is red, and to the right eye NOTHING is.

The 2nd picture looks indeed a lot easier on the eyes, but now you completely seem to loose the colour red.
You're right you can't display 100% red and not wanting to claw your eyes out (or even be able to see depth with those colours), but there must be way to shift those problematic colours a bit more towards gray without loosing those colours altogether. Hmmm....

Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #12 - Posted 2009-08-22 01:09:54 »

Well, you're losing an entire color channel, leaving you with just two. It might be possible to hue-shift red and compress the entire color spectrum. Since you're seeing things through a horrible color filter anyway, the brain might adapt and interpret the color as red. =D

I'm not clever enough at the moment to implement that, though.

Play Minecraft!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #13 - Posted 2009-08-22 01:31:39 »

Here's a video explaining James Cameron's new 3D camera:
http://video.google.com/videoplay?docid=-241532803911842846
It details how the lenses are rotated inwards, exactly how I described. So unless James Cameron is wrong too, I suppose I didn't make a mistake with my way of rendering after all.

Quote
Well, you're losing an entire color channel, leaving you with just two. It might be possible to hue-shift red and compress the entire color spectrum. Since you're seeing things through a horrible color filter anyway, the brain might adapt and interpret the color as red.
Compressing the entire color spectrum is exactly what I do, and it works fairly well.
But then again, anaglyphs are the worst way of projecting stereoscopic images the way it abuses colour filtering, so it's all a big trade-off anyway.

Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #14 - Posted 2009-08-22 02:07:34 »

I'd claim he's wrong.

And from what you explained (graying out), you're not compressing the color spectrum at all. Could you describe your algorithm?

Play Minecraft!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #15 - Posted 2009-08-22 03:42:42 »

I'd claim he's wrong.
Wow, that would be an epic mistake as that camera is filming the most expensive movie ever  Cheesy
I hope you're wrong because I'm kinda looking forward to that movie  Grin

Quote
And from what you explained (graying out), you're not compressing the color spectrum at all. Could you describe your algorithm?

Pardon the sucky code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
    public TileNormal(float r, float g, float b) {
        this.r = r;
        this.g = g;
        this.b = b;
        if (Game.ANAGLYPHIC) {
            float im = (r + g + b) / 3f;
           
            // damp color
           this.r = im - (im - r) * Game.ANA_COLOR_DAMP;
            this.g = im - (im - g) * Game.ANA_COLOR_DAMP;
            this.b = im - (im - b) * Game.ANA_COLOR_DAMP;
           
            // adjust brightness
           this.r = this.r + (1f-this.r) * Game.ANA_BRIGHTNESS;
            this.g = this.g + (1f-this.g) * Game.ANA_BRIGHTNESS;
            this.b = this.b + (1f-this.b) * Game.ANA_BRIGHTNESS;
        }
        this.texId = Game.TEXTURE_POOL.getTextureID("/tile.jpg", Texture.TYPE_MIPMAPPED, Texture.ENV_NONE);
    }


Reading it again, I'm not exactly sure what I was thinking, but the idea is to bring all colors closer to gray persecutioncomplex
Perhaps strictly speaking the word compression is not the right word, although that's probably a matter of interpretation

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #16 - Posted 2009-08-22 09:06:56 »

Here's a video explaining James Cameron's new 3D camera:
http://video.google.com/videoplay?docid=-241532803911842846
It details how the lenses are rotated inwards, exactly how I described. So unless James Cameron is wrong too, I suppose I didn't make a mistake with my way of rendering after all.

Like he said, our brain make correction on focus. What is good for a movie, is no good for a game :
- in a movie, viewers are forced to focus on a particular subject. In this case, your view is wrong but you make correction, your eyes don't have to make the focus so it is less stressfull.
- in a game, you just can't focus on something

Quote
Reading it again, I'm not exactly sure what I was thinking, but the idea is to bring all colors closer to gray persecutioncomplex
I don't know the detail but anaglyph driver from nVidia do a color filter too. It seems to be mostly more red to me.
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #17 - Posted 2009-08-22 12:04:06 »

Wow, that would be an epic mistake as that camera is filming the most expensive movie ever  Cheesy
I hope you're wrong because I'm kinda looking forward to that movie  Grin

In Ice Age 3d, they played around a lot with the focus depth and stereo effect strength across shots. The end result was that, sure, stuff looked 3d both in closeups and wide shots, but the scale of everything varied widely. In wide shots, the huge lumbering mammoths looked like tiny toy figures. It was horrible.

It appears from that video that Cameron is going to do something similar.

Play Minecraft!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #18 - Posted 2009-08-22 14:23:06 »

Like he said, our brain make correction on focus. What is good for a movie, is no good for a game :
- in a movie, viewers are forced to focus on a particular subject. In this case, your view is wrong but you make correction, your eyes don't have to make the focus so it is less stressfull.
- in a game, you just can't focus on something
I don't know the detail but anaglyph driver from nVidia do a color filter too. It seems to be mostly more red to me.

That is indeed exactly the problem of using stereoscopic 3D in an interactive game: The rendered view ports are not corrected according to what the user is looking at.
This is not a problem with 2D (although it is too as soon as you implement depth of field effects).

However this doesn't make rotating the view ports inwards wrong. If you don't do it, the camera is focusing at infinity instead of closer by, and you still have exactly the same problem.

In Ice Age 3d, they played around a lot with the focus depth and stereo effect strength across shots. The end result was that, sure, stuff looked 3d both in closeups and wide shots, but the scale of everything varied widely. In wide shots, the huge lumbering mammoths looked like tiny toy figures. It was horrible.

It appears from that video that Cameron is going to do something similar.

No I disagree, to me it sounds more like that in Ice Age 3D they made a few mistakes that have nothing to do with rotating the viewports:
More specifically, it sounds exactly like they separated the view ports too far apart in the wide shots (probably in an attempt to enhance the 3D effect), which makes everything look too small.

As explained in the video, they avoided that problem in the new camera by placing the lenses at the same distance from each other as human eyes (old film camera's were too big to do that).

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #19 - Posted 2009-08-22 16:50:59 »

I try to do a drawing to see what stereoscopic with rotation differ from stereoscopic without. But I didn't manage... when using rotation, projection plans are not parralel to the screen !
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #20 - Posted 2009-08-23 19:59:10 »

I try to do a drawing to see what stereoscopic with rotation differ from stereoscopic without. But I didn't manage... when using rotation, projection plans are not parralel to the screen !

I see what you mean.

But I think it's a problem caused by rendering 2 different view ports to the same screen while ideally it should be 2 screens right in front of both eyes. Remember I'm rotating the *camera's* and not the spectator's eyes (they are still more or less right in front of the screen, no matter how the camera's are rotated).
I think it is a small problem related to the viewing angle difference from your 2 eyes to the screen, and does not actually have anything to do with rotation of the camera's.

But I can't imagine it to be really noticable unless you're *really* close to the screen.

I think it all comes down to this (I'll quote myself here):
Quote
In an ideal world, you'd wear contact lenses with little monitors in them that would track the rotation of both eyes and adjust the view ports accordingly. But that's not really viable yet, so we're stuck with one 2D screen with a fixed view that we somehow want to translate to a stereoscopic image.

But I find it all quite mind boggling Shocked so I'm not ruling out I'm making a mistake somewhere, but I think (especially interactive) stereoscopic projection using just one screen and with no tracking of the spectator's eyes is a trade off no matter what, caused by the fact that the cameras' orientations will differ from those of the spectator's eyes.

You could say that the inward rotation of the camera's should be same as that of the spectator's eyes, but then you still have the same problem as soon as you look at something at a different depth from the screen.

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #21 - Posted 2009-08-25 08:18:01 »

A comparison for anaglyph color mixing.

NVidia seems to use the "Optimized Anaglyphs".


For camera, without rotation it is the "parallel method" and with rotation it is the "Toe-in method"... and there are both "wrong"  Wink

The "good" method is the "Off-axis method"



Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #22 - Posted 2009-08-25 15:11:03 »

Thanks for the helpful links!
I get it now and see I was wrong after all...

Sorry for the confusion and not being the sharpest tool in the shed sometimes  Roll Eyes persecutioncomplex

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #23 - Posted 2009-08-25 15:34:27 »

Getting back to Cameron's 3D camera, I think the fact that the  lenses can be 'toe-ed in' doesn't mean he's making the same mistake as I did.
I guess it's still possible (and actually quite likely) that rotating the lenses inward will still film with an 'off axis' perspective by exposing the film (or CCD or whatever) at an angle. That'd probably even be the best way to film 'off axis'.

Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #24 - Posted 2009-08-25 15:54:43 »

NVidia seems to use the "Optimized Anaglyphs".
 
[...]

The "good" method is the "Off-axis method"

BOOM! Exactly what I do. Cheesy

Play Minecraft!
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #25 - Posted 2009-08-27 09:41:15 »

It make me want to redo some anaglyph stuff  Tongue

What glasses are you using ? (And how effective are they ?)
With a quick search, I found thoses (sorry in french, it is the second ones)
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #26 - Posted 2009-08-27 09:48:40 »

I use a pair called "Pro-X" or something. They work pretty well, but there's some ghosting that especially noticeable in bright areas. I think the reason for the ghosting is my monitors, though.

Play Minecraft!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #27 - Posted 2009-08-27 11:12:05 »

It make me want to redo some anaglyph stuff  Tongue

What glasses are you using ? (And how effective are they ?)
With a quick search, I found thoses (sorry in french, it is the second ones)

I'm using the cheap paper ones.
My understanding is that the plastic ones (the 2nd one in the link) are doing also some focus correction on the red glass so those might be easier on the eyes and give a sharper image.

As for ghosting, I found that the monitor makes most difference here. I see a lot of ghosting on laptop screens (to the point that the 3D effect becomes almost ineffective), but on my CRT monitor and LCD TV there's much less ghosting and the effect is quite good there.

I'm also considering to implement ColorCode 3D (amber-dark blue anaglyph). It's supposed to look better than traditional red-cyan.

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #28 - Posted 2009-08-30 12:19:26 »

Ok first try :



I'm not sure for the view setup.

What I use for none stereoscopic view :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
GL11.glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
    GL11.glMatrixMode(GL11.GL_PROJECTION) ;
    GL11.glLoadIdentity();
   
    if (type == ORTHOGONAL)
    {
      GLU.gluOrtho2D(left,right,bottom,top);
    }
    else
    {
      GLU.gluPerspective(fovy,(float)viewport_w/(float)viewport_h, zNear ,zFar);  
    }
   
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadMatrix(correctZ.getFloatBuffer());


For left eye :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
public void applyLeftEyes(float eyesep,float focal)
  {
    GL11.glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
    GL11.glMatrixMode(GL11.GL_PROJECTION) ;
    GL11.glLoadIdentity();
   
    if (type == ORTHOGONAL)
    {
      GLU.gluOrtho2D(left,right,bottom,top);
    }
    else
    {
      float aspectratio = (float)viewport_w/(float)viewport_h;
       
      float top = (float)Math.tan(fovy*Math.PI/360.0) * zNear;
      float bottom = -top;
     
      float left = aspectratio * bottom + 0.5f * eyesep * zNear / focal;
      float right = aspectratio * top + 0.5f * eyesep * zNear / focal;
       
      GL11.glFrustum(left,right,bottom,top,zNear,zFar);
    }
   
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadMatrix(correctZ.getFloatBuffer());
  }


For right eye :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
public void applyRightEyes(float eyesep,float focal)
  {
    GL11.glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
    GL11.glMatrixMode(GL11.GL_PROJECTION) ;
    GL11.glLoadIdentity();
   
    if (type == ORTHOGONAL)
    {
      GLU.gluOrtho2D(left,right,bottom,top);
    }
    else
    {
      float aspectratio = (float)viewport_w/(float)viewport_h;
       
      float top = (float)Math.tan(fovy*Math.PI/360.0) * zNear;
      float bottom = -top;
     
      float left = aspectratio * bottom - 0.5f * eyesep * zNear / focal;
      float right = aspectratio * top - 0.5f * eyesep * zNear / focal;
       
      GL11.glFrustum(left,right,bottom,top,zNear,zFar);  
    }
   
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadMatrix(correctZ.getFloatBuffer());
  }


Now I wonder how to do the optimized anaglyph. Of course, there is allways the shader solution. May be I can use the GL_COLOR matrix but I only heard bad thing about it ? Accumaltion buffer ? Something else ?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

E.R. Fleming (20 views)
2014-07-29 03:07:13

E.R. Fleming (7 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (45 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!