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
= true;
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/3;
54 __gshared
bool vertical
= false;
55 __gshared vec3 eye
= vec3(0.0f, 14.0f, 64.0f);
61 if (!glcreated
) return;
63 glDisable(GL_TEXTURE_2D
);
64 glEnable(GL_DEPTH_TEST
);
65 glDisable(GL_LIGHTING
);
67 glEnable(GL_COLOR_MATERIAL
);
70 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
72 glDepthFunc(GL_LEQUAL
);
73 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
);
75 glEnable(GL_CULL_FACE
);
76 //glCullFace(GL_FRONT);
78 //glFrontFace(GL_CCW);
81 //glDisable(GL_CULL_FACE); // this way we can draw any model
82 glShadeModel(GL_FLAT
);
84 //glDisable(GL_CULL_FACE); // this way we can draw any model
89 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
);
92 glMatrixMode(GL_PROJECTION
);
95 90.0, // field of view in degree
102 0.0, -vox
.cy
-64, 30.0, // eye is at (0,0,5)
103 0.0, 0.0, 0.0, // center is at (0,0,0)
104 0.0, 0.0, 1.0, // up is in positive Z direction
108 eye
.x
, eye
.y
-vox
.cy
-64, eye
.z
, // eye is at (0,0,5)
109 0.0, 0.0, 0.0, // center is at (0,0,0)
110 0.0, 0.0, 1.0, // up is in positive Z direction
114 // setup model matrix
115 glMatrixMode(GL_MODELVIEW
);
117 //glRotatef(1.0f*angle, 0.8f, 0.9f, 0.4f);
118 //glRotatef(1.0f*angle, 1.0f, 0.0f, 0.0f);
119 //glRotatef(1.0f*angle, 0.0f, 1.0f, 0.0f);
121 glRotatef(1.0f*angle
, 1.0f, 0.0f, 0.0f);
123 glRotatef(1.0f*angle
, 0.0f, 0.0f, 1.0f);
130 // ////////////////////////////////////////////////////////////////////////// //
131 void main (string
[] args
) {
132 //setOpenGLContextVersion(3, 2); // up to GLSL 150
133 //openGLContextCompatible = false;
135 if (args
.length
< 1) {
136 writeln("filename?");
141 loadVoxel(ref voxdata
, args
[2]);
145 conRegVar
!paused("pause", "stop rotating");
146 conRegVar
!angle(0, 359, "angle", "current angle");
147 conRegVar
!vertical("vertical", "rotate vertically");
149 conProcessArgs(args
);
150 while (conProcessQueue()) {}
156 auto sdwin
= new SimpleWindow(conGetVar
!int("v_width"), conGetVar
!int("v_height"),
158 OpenGlOptions
.yes
, Resizability
.fixedSize
);
161 void loadFrom (string fname
) {
162 writeln("loading: ", fname
, (vox_allow_normals ?
" (with normals)" : " (no normals)"));
163 loadVoxel(ref voxdata
, fname
);
164 vox
.createFrom(ref voxdata
);
168 import std
.string
: format
;
169 sdwin
.title
= "(%s quads, %s verts) -- %s".format(vox
.quads
.length
, glvox
.uniqueVerts
, fname
);
171 { import core
.memory
: GC
; GC
.collect(); GC
.minimize(); }
172 //{ import core.memory : GC; GC.collect(); GC.minimize(); }
176 sdwin
.redrawOpenGlScene
= delegate () {
181 sdwin
.visibleForTheFirstTime
= delegate () {
182 loadFrom(args
[argidx
]);
183 //vox = new Voxel(VFile("untitled.vxl"));
184 sdwin
.setAsCurrentOpenGlContext(); // make this window active
185 glconResize(sdwin
.width
, sdwin
.height
);
186 sdwin
.redrawOpenGlScene();
190 sdwin
.eventLoop(1000/35,
192 if (sdwin
.closed
) return;
194 if (isQuitRequested
) { sdwin
.close(); return; }
195 if (!paused
) angle
= (angle
+1)%360;
198 sdwin
.redrawOpenGlSceneNow();
200 delegate (KeyEvent event
) {
201 if (sdwin
.closed
) return;
202 if (glconKeyEvent(event
)) return;
203 if (!event
.pressed
) return;
204 if (event
.pressed
&& event
.key
== Key
.Escape
) { concmd("quit"); return; }
207 case Key.Escape: sdwin.close(); break;
213 if (event
.modifierState
&ModifierState
.shift
) {
214 delta
= (event
.modifierState
&ModifierState
.ctrl ?
5.0f : 1.0f);
215 } else if (event
.modifierState
&ModifierState
.ctrl
) {
218 if (event
.modifierState
&ModifierState
.alt
) {
219 if (event
.key
== Key
.Up
) eye
.y
-= delta
;
220 if (event
.key
== Key
.Down
) eye
.y
+= delta
;
222 if (event
.key
== Key
.Left
) eye
.x
-= delta
;
223 if (event
.key
== Key
.Right
) eye
.x
+= delta
;
224 if (event
.key
== Key
.Up
) eye
.z
-= delta
;
225 if (event
.key
== Key
.Down
) eye
.z
+= delta
;
229 delegate (MouseEvent event
) {
231 delegate (dchar ch
) {
232 if (sdwin
.closed
) return;
233 if (glconCharEvent(ch
)) return;
234 if (ch
== 'q') { concmd("quit"); return; }
235 if (ch
== ' ') { concmd("pause toggle"); return; }
236 if (ch
== 'v') { concmd("vertical toggle"); return; }
237 if (ch
== '0') { eye
= vec3(0.0f, 0.0f, 0.0f); return; }
238 if (ch
== 'u') { vox_wireframe
= !vox_wireframe
; return; }
240 vox_fix_tjunctions
= !vox_fix_tjunctions
;
241 loadFrom(args
[argidx
]);
245 vox_allow_normals
= !vox_allow_normals
;
246 loadFrom(args
[argidx
]);
250 vox_optimize_hollow
= !vox_optimize_hollow
;
251 loadFrom(args
[argidx
]);
254 if (ch
== '1' || ch
== '2' || ch
== '3' || ch
== '4' || ch
== '5') {
255 vox_optimisation
= (ch
-'1');
256 loadFrom(args
[argidx
]);
260 vox_optimiser_use_3dbmp
= !vox_optimiser_use_3dbmp
;
261 conwriteln("OPTIMISER: use3dbmp is ", (vox_optimiser_use_3dbmp ?
"on" : "off"));
262 loadFrom(args
[argidx
]);
266 vox_atlas_cache_colors
= !vox_atlas_cache_colors
;
267 conwriteln("OPTIMISER: cache_colors is ", (vox_atlas_cache_colors ?
"on" : "off"));
268 loadFrom(args
[argidx
]);
272 vox_optimiser_use_cvox
= !vox_optimiser_use_cvox
;
273 conwriteln("OPTIMISER: use faster voxel data is ", (vox_optimiser_use_cvox ?
"on" : "off"));
274 loadFrom(args
[argidx
]);
277 if (ch
== 'p' || ch
== 'P') {
280 loadFrom(args
[argidx
]);
284 if (ch
== 'n' || ch
== 'N') {
285 if (argidx
+1 < args
.length
) {
287 loadFrom(args
[argidx
]);