1 module zglvox_new
is aliced
;
3 import arsd
.simpledisplay
;
8 import iv
.glbinds
.utils
;
15 static import iv
.timer
;
26 //version = vox_check_invariants;
27 version = voxdata_debug
;
30 // ////////////////////////////////////////////////////////////////////////// //
31 __gshared
int scrWidth
= 800, scrHeight
= 800;
32 __gshared
bool paused
= false;
35 // ////////////////////////////////////////////////////////////////////////// //
36 shared static this () {
37 conRegVar
!scrWidth(64, 4096, "v_width", "screen width");
38 conRegVar
!scrHeight(64, 4096, "v_height", "screen height");
42 public void renderSealVars () {
43 conSealVar("v_width");
44 conSealVar("v_height");
48 // ////////////////////////////////////////////////////////////////////////// //
49 __gshared VoxelData voxdata
;
50 __gshared VoxelMesh vox
;
51 __gshared GLVoxelMesh glvox
;
52 __gshared
bool glcreated
= false;
53 __gshared
int angle
= 360/2;
54 __gshared
bool vertical
= false;
55 __gshared vec3 eye
= vec3(0.0f, 14.0f, 64.0f);
61 if (vox
is null) return; // just in case
68 glDisable(GL_TEXTURE_2D
);
69 glEnable(GL_DEPTH_TEST
);
70 glDisable(GL_LIGHTING
);
72 glEnable(GL_COLOR_MATERIAL
);
75 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
77 glDepthFunc(GL_LEQUAL
);
78 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
);
80 glEnable(GL_CULL_FACE
);
81 //glCullFace(GL_FRONT);
83 //glFrontFace(GL_CCW);
86 //glDisable(GL_CULL_FACE); // this way we can draw any model
87 glShadeModel(GL_FLAT
);
89 //glDisable(GL_CULL_FACE); // this way we can draw any model
94 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
);
97 glMatrixMode(GL_PROJECTION
);
100 90.0, // field of view in degree
107 0.0, -vox
.cy
-64, 30.0, // eye is at (0,0,5)
108 0.0, 0.0, 0.0, // center is at (0,0,0)
109 0.0, 0.0, 1.0, // up is in positive Z direction
113 eye
.x
, eye
.y
-vox
.cy
-64, eye
.z
, // eye is at (0,0,5)
114 0.0, 0.0, 0.0, // center is at (0,0,0)
115 0.0, 0.0, 1.0, // up is in positive Z direction
119 // setup model matrix
120 glMatrixMode(GL_MODELVIEW
);
122 //glRotatef(1.0f*angle, 0.8f, 0.9f, 0.4f);
123 //glRotatef(1.0f*angle, 1.0f, 0.0f, 0.0f);
124 //glRotatef(1.0f*angle, 0.0f, 1.0f, 0.0f);
126 glRotatef(1.0f*angle
, 1.0f, 0.0f, 0.0f);
128 glRotatef(1.0f*angle
, 0.0f, 0.0f, 1.0f);
135 // ////////////////////////////////////////////////////////////////////////// //
136 void main (string
[] args
) {
137 //setOpenGLContextVersion(3, 2); // up to GLSL 150
138 //openGLContextCompatible = false;
140 if (args
.length
< 1) {
141 writeln("filename?");
146 loadVoxel(ref voxdata
, args
[2]);
150 conRegVar
!paused("pause", "stop rotating");
151 conRegVar
!angle(0, 359, "angle", "current angle");
152 conRegVar
!vertical("vertical", "rotate vertically");
154 conProcessArgs(args
);
155 while (conProcessQueue()) {}
161 auto sdwin
= new SimpleWindow(conGetVar
!int("v_width"), conGetVar
!int("v_height"),
163 OpenGlOptions
.yes
, Resizability
.fixedSize
);
166 void loadFrom (string fname
) {
168 writeln("loading: ", fname
, (vox_allow_normals ?
" (with normals)" : " (no normals)"));
169 loadVoxel(ref voxdata
, fname
);
170 vox
= new VoxelMesh(ref voxdata
);
174 import std
.string
: format
;
175 sdwin
.title
= "(%s quads, %s verts) -- %s".format(vox
.quads
.length
, glvox
.uniqueVerts
, fname
);
177 { import core
.memory
: GC
; GC
.collect(); GC
.minimize(); }
178 { import core
.memory
: GC
; GC
.collect(); GC
.minimize(); }
182 sdwin
.redrawOpenGlScene
= delegate () {
187 sdwin
.visibleForTheFirstTime
= delegate () {
188 loadFrom(args
[argidx
]);
189 //vox = new Voxel(VFile("untitled.vxl"));
190 sdwin
.setAsCurrentOpenGlContext(); // make this window active
191 glconResize(sdwin
.width
, sdwin
.height
);
192 sdwin
.redrawOpenGlScene();
196 sdwin
.eventLoop(1000/35,
198 if (sdwin
.closed
) return;
200 if (isQuitRequested
) { sdwin
.close(); return; }
201 if (!paused
) angle
= (angle
+1)%360;
204 sdwin
.redrawOpenGlSceneNow();
206 delegate (KeyEvent event
) {
207 if (sdwin
.closed
) return;
208 if (glconKeyEvent(event
)) return;
209 if (!event
.pressed
) return;
210 if (event
.pressed
&& event
.key
== Key
.Escape
) { concmd("quit"); return; }
213 case Key.Escape: sdwin.close(); break;
219 if (event
.modifierState
&ModifierState
.shift
) {
220 delta
= (event
.modifierState
&ModifierState
.ctrl ?
5.0f : 1.0f);
221 } else if (event
.modifierState
&ModifierState
.ctrl
) {
224 if (event
.modifierState
&ModifierState
.alt
) {
225 if (event
.key
== Key
.Up
) eye
.y
-= delta
;
226 if (event
.key
== Key
.Down
) eye
.y
+= delta
;
228 if (event
.key
== Key
.Left
) eye
.x
-= delta
;
229 if (event
.key
== Key
.Right
) eye
.x
+= delta
;
230 if (event
.key
== Key
.Up
) eye
.z
-= delta
;
231 if (event
.key
== Key
.Down
) eye
.z
+= delta
;
235 delegate (MouseEvent event
) {
237 delegate (dchar ch
) {
238 if (sdwin
.closed
) return;
239 if (glconCharEvent(ch
)) return;
240 if (ch
== 'q') { concmd("quit"); return; }
241 if (ch
== ' ') { concmd("pause toggle"); return; }
242 if (ch
== 'v') { concmd("vertical toggle"); return; }
243 if (ch
== '0') { eye
= vec3(0.0f, 0.0f, 0.0f); return; }
244 if (ch
== 'u') { vox_wireframe
= !vox_wireframe
; return; }
246 vox_fix_tjunctions
= !vox_fix_tjunctions
;
247 loadFrom(args
[argidx
]);
251 vox_allow_normals
= !vox_allow_normals
;
252 loadFrom(args
[argidx
]);
256 vox_optimize_hollow
= !vox_optimize_hollow
;
257 loadFrom(args
[argidx
]);
260 if (ch
== '1' || ch
== '2' || ch
== '3' || ch
== '4' || ch
== '5') {
261 vox_optimisation
= (ch
-'1');
262 loadFrom(args
[argidx
]);
266 vox_reuse_colors
= !vox_reuse_colors
;
267 loadFrom(args
[argidx
]);
270 if (ch
== 'p' || ch
== 'P') {
273 loadFrom(args
[argidx
]);
277 if (ch
== 'n' || ch
== 'N') {
278 if (argidx
+1 < args
.length
) {
280 loadFrom(args
[argidx
]);