-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStencilBuffer.java
More file actions
120 lines (94 loc) · 3.64 KB
/
StencilBuffer.java
File metadata and controls
120 lines (94 loc) · 3.64 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package tasks;
import jToolkit4FixedPipeline.primitives.Box;
import jToolkit4FixedPipeline.primitives.Plane;
import jToolkit4FixedPipeline.primitives.Surface;
import jToolkit4FixedPipeline.vector.Vector3f;
import static org.lwjgl.opengl.GL11.*;
/**
* Created with IntelliJ IDEA.
* User: Astemir Eleev
* Date: 9/1/13
* Time: 3:06 PM
* To change this template use File | Settings | File Templates.
*/
public class StencilBuffer {
private float rotationAngle;
private Box box;
private Surface surface;
private Surface wallSurface;
private Plane bottonCoverSurface;
private Plane wallCoverSurface;
public StencilBuffer () {
box = new Box(10, .0f, new Vector3f(), new Vector3f(), new Vector3f().makeIdentity(), new Vector3f(1, 0, 1));
surface = new Surface();
wallSurface = new Surface();
bottonCoverSurface = new Plane(10, 0.0f, new Vector3f(), new Vector3f(0, -0.001f, 0), new Vector3f().makeIdentity(), new Vector3f(1, 1, 1));
wallCoverSurface = new Plane(10, 90.0f, new Vector3f(0, 0, 1), new Vector3f(-10.001f, 8, 0), new Vector3f().makeIdentity(), new Vector3f(1, 1, 1));
surface.drawChessBoard(2, 10, 16, .0f, new Vector3f(), new Vector3f(), new Vector3f().makeIdentity(), new Vector3f(1, 1, 1));
wallSurface.drawChessBoard(3, 10, 16, -90.0f, new Vector3f(0, 0, 1), new Vector3f(-10, 8, 0), new Vector3f().makeIdentity(), new Vector3f(1, 1, 1));
}
/**
* Simulation of reflections by stencil buffer and blending equations
*/
public void stencilPlannarReflections () {
// outside this plane reflected objects won't be rendered
glColorMask(false, false, false, false);
glDisable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilMask(0xFF);
glClear(GL_STENCIL_BUFFER_BIT);
glPushMatrix(); {
glCallList(2);
glCallList(3);
}
glPopMatrix();
glColorMask(true, true, true, true);
glEnable(GL_DEPTH_TEST);
glStencilMask(0x00);
glStencilFunc(GL_EQUAL, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// drawing reflected object
glPushMatrix(); {
box.setTranslate(new Vector3f(.0f, -10.0f, .0f));
box.setScale(new Vector3f(1.0f, -1.0f, 1.0f));
box.setColor(new Vector3f(1.0f, .0f, .0f));
box.setAngleofRotation(rotationAngle);
box.setRotate(new Vector3f(1,1,1));
box.draw();
box.setTranslate(new Vector3f(-20.0f, 10.0f, .0f));
box.setScale(new Vector3f(-1.0f, 1.0f, 1.0f));
box.setColor(new Vector3f(1.0f, .0f, .0f));
box.setAngleofRotation(rotationAngle);
box.setRotate(new Vector3f(1,1,1));
box.draw();
}
glPopMatrix();
glDisable(GL_STENCIL_TEST);
// drawing blended floor
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix(); {
glCallList(2);
glCallList(3);
}
glPopMatrix();
glPushMatrix(); {
bottonCoverSurface.draw();
wallCoverSurface.draw();
}
glPopMatrix();
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
// drawing actual box
glPushMatrix(); {
box.setTranslate(new Vector3f(.0f, 10.0f, .0f));
box.setScale(new Vector3f().makeIdentity());
box.draw();
}
glPopMatrix();
rotationAngle += .5f;
}
}