-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.c
More file actions
9984 lines (9005 loc) · 275 KB
/
main.c
File metadata and controls
9984 lines (9005 loc) · 275 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* LDLITE, a program for viewing *.dat files.
* Copyright (C) 1998 Paul J. Gyugyi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/stat.h> // for polling datfile for updates.
#include "glwinkit.h" //#include <GL/glut.h>
#include "platform.h"
#include "ldliteVR.h"
# ifndef WINDOWS
// This stuff gets pulled in by glut.h for windows.
# include "wstubs.h"
# else
// glut 3.7 no longer includes windows.h
# if (GLUT_XLIB_IMPLEMENTATION >= 13)
# include <windows.h>
# endif
# endif
char ldgliteVersion[] = "Version 1.2.10 ";
// Use Glut popup menus if MUI is not available.
#ifndef OFFSCREEN_ONLY
#ifndef TEST_MUI_GUI
# define USE_GLUT_MENUS 1
#endif
#endif
extern char dirfilepath[256]; // Used by bogus glut popup menu file browser
extern int mainmenunum;
extern void initializeMenus(void);
#ifdef USE_L3_PARSER
extern void LoadModelPre(void);
extern int LoadModel(const char *lpszPathName);
extern void LoadModelPost(void);
extern void DrawModel(void);
#endif
//extern void ldlite_parse(char *filename, char *ldraw_lines);
extern void ldlite_parse(char *ldraw_lines);
extern void translate_color(int c, ZCOLOR *zcp, ZCOLOR *zcs);
extern char pathname[256];
extern char primitivepath[256];
extern char partspath[256];
extern char modelspath[256];
extern char datfilepath[256];
char userpath[256];
char bitmappath[256];
#ifdef USE_L3_PARSER
#define UNKNOWN_PARSER -1
#define LDLITE_PARSER 0
#define L3_PARSER 1
// It's 2008 and the l3 parser works much better with current GPU chips.
// So maybe it's about time to set L3 as the default parser.
int parsername = L3_PARSER; // (was UNKNOWN_PARSER)
#endif
int EPS_OUTPUT_FIGURED_OUT = 0;
char *picfilename = NULL;
char datfilename[256];
char title[256];
char progname[256];
char progpath[256];
char buf[16*1024]; // sizeof buf copied from render_file() in ldliteView.cpp
int use_uppercase = 0;
#define IMAGE_TYPE_PNG_RGB 1
#define IMAGE_TYPE_PNG_RGBA 2
#define IMAGE_TYPE_BMP8 3
#define IMAGE_TYPE_BMP 4
#define IMAGE_TYPE_PPM 5
int use_png_alpha = 1;
int ldraw_projection_type = 0; // 1 = perspective, 0 = orthographic.
#define WIDE_ANGLE_VIEW 1
#if WIDE_ANGLE_VIEW
// znear 1.0 gives zfighting with 16bit Mesa Zbuf, 10.0 still does on datsville
double projection_znear = 10.0;
double projection_zfar = 4000.0;
double projection_fov = 67.38; //L3P default is 67.38 degrees = 2*atan(2/3)
double projection_fromx = 0.0;
double projection_fromy = 0.0;
double projection_fromz = 1000.0;
double projection_depth = 1000; // distance(from, toward);
#else
double projection_znear = 100.0;
double projection_zfar = 4000.0;
double projection_fov = 20.0;
double projection_fromx = 0.0;
double projection_fromy = 0.0;
double projection_fromz = 2000.0;
double projection_depth = 2000; // 500 ??
#endif
double projection_towardx = 0.0;
double projection_towardy = 0.0;
double projection_towardz = 0.0;
double projection_upx = 0.0;
double projection_upy = 1.0;
double projection_upz = 0.0;
double camera_longitude = 0.0;
double camera_latitude = 0.0;
double camera_distance = 0.0;
int ldraw_image_type = IMAGE_TYPE_BMP8;
// Set the light way up and behind us. Will this make it too dim?
// NOTE: The LDRAW polys are not CCW compliant so the normals are random
// LdLite uses 2 opposing lights to avoid the problem with normals?
// I attempted this below but it does not seem to work for OpenGL.
// Hmmm, perhaps LdLite just took the fabs() of normals instead.
// If I calculate normals then I could do that too.
// x, y, z, dist divisor. (divisor = 0 for light at infinite distance)
GLfloat lightposition0[] = { -1000.0, 1000.0, 1000.0, 0.0 };
GLfloat lightposition1[] = { 1000.0, -1000.0, -1000.0, 0.0 };
GLfloat lightcolor0[] = { 0.5, 0.5, 0.5, 1.0 }; // Half light
GLfloat lightcolor1[] = { 0.75, 0.75, 0.75, 1.0 }; // bright light
#if 0
GLfloat lightcolorWhite[] = { 1.0, 1.0, 1.0, 1.0 }; // White light
GLfloat lightcolorBright[] = { 0.75, 0.75, 0.75, 1.0 }; // bright light
GLfloat lightcolorHalf[] = { 0.5, 0.5, 0.5, 1.0 }; // Half light
GLfloat lightcolorDim[] = { 0.25, 0.25, 0.25, 1.0 }; // dim light
#endif
int fogging = 0; // 0 = disabled, 1 = LINEAR, 2 = EXP, 3 = EXP2
GLint fogMode = GL_LINEAR;
GLfloat fogColor[4] = {1.0, 1.0, 1.0, 1.0}; // Fade to white
GLfloat fogDensity = 1.0;
GLfloat fogStart = 0.0;
GLfloat fogEnd = 1.0;
// [Views] swiped from ldraw.ini
// Modified some views to be orthogonal.
char Back[] = "-1,0,0,0,1,0,0,0,-1";
char Left[] = "0,0,1,0,1,0,-1,0,0";
char Right[] = "0,0,-1,0,1,0,1,0,0";
char Above[] = "0,0,1,1,0,0,0,1,0";
char Beneath[] = "0,0,1,-1,0,0,0,-1,0";
char LdrawOblique[] = "1,0,1,0.5,1,-0.5,-1,0,1";
char Oblique[] = "0.707104,0,0.707104,0.353553,0.866025,-0.353553,-0.612372,0.5,0.612372";
char Front[] = "1,0,0,0,1,0,0,0,1";
//char UpsideDown[] = "-1,0,1,-0.5,-1,-0.5,1,0,0";
char UpsideDown[] = "0.707104,0,0.707104,-0.353553,-0.866025,0.353553,0.612372,-0.5,-0.612372";
//char Natural[] = "0.625,0,1.075,0.5375,1.25,-0.3125,-1.25,0,2.5";
char Natural[] = "0.5,0,0.866025,0.433013,0.866025,-0.25,-0.75,0.5,0.433013";
char *m_viewMatrix = LdrawOblique;
// If we separate the ldraw oblique projection from the underlying
// Oblique rotation matrix we get this projection matrix. Perhaps
// we can then offer 3 projection types: orthogonal, perspective, oblique.
char ObliqueProjection[] = "1.4142,0,0,0,1.2196,-0.1124,0,-0.7171,1.2247";
//Notes on deriving the Oblique rotation matrix:
//Rotate 45 degrees and then tilt 30 degrees?
/*
.707104 = sqrt(2) / 2
.353553 = sqrt(2) / 4
.866025 = sin(pi / 3)
.612372 = sqrt(1.5) / 2
*/
extern int glCurColorIndex;
extern float z_line_offset;
int PolygonOffsetEnabled = 1;
GLfloat PolygonOffsetFactor = 1.0;
GLfloat PolygonOffsetunits = 1.0;
extern ZIMAGE z;
GLint Width = 640;
GLint Height = 480;
GLint XwinPos = 0;
GLint YwinPos = 0;
int main_window = -1;
double twirl_angle = 0.0;
double twirl_increment = 10.0;
static int list_made = 0;
#define USE_DOUBLE_BUFFER
#ifndef AGL
#define USE_OPENGL_STENCIL
#endif
int sc[4];
// Stuff for editing mode
// contents of back buffer after glutSwapBuffers():
#define SWAP_TYPE_UNDEFINED 0 // unknown
#define SWAP_TYPE_SWAP 1 // former front buffer
#define SWAP_TYPE_COPY 2 // unchanged
#define SWAP_TYPE_NODAMAGE 3 // unchanged even by X expose() events
#define SWAP_TYPE_KTX 4 // use the GL_KTX_buffer_region extension
#define SWAP_TYPE_APPLE 5 // OSX fakes GL_FRONT by drawing in GL_BACK
// Lookup some of these extensions for reference:
// GL_APPLE_flush_render {provides glSwapAPPLE() glFlushRenderAPPLE(), glFinishRenderAPPLE()}
// GLX_SWAP_COPY_OML, GLX_SWAP_METHOD_OML
// GL_WIN_swap_hint
// WGL_SWAP_METHOD_ARB, WGL_SWAP_METHOD_EXT, WGL_SWAP_UNDEFINED_ARB, WGL_SWAP_UNDEFINED_EXT
// WGL_SWAP_COPY_ARB, WGL_SWAP_COPY_EXT, WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_EXCHANGE_EXT
//
/*
GL_APPLE_flush_render (Specification pending)
-------------------------------
Normally, in single buffered mode glFlush and glFinish submit the
command stream and copy the resulting image to the screen. This
extension provides glFlushRenderAPPLE and glFinishRenderAPPLE which
just submit pending opengl commands and do not copy the results to the
screen. Also, provides glSwapAPPLE which copies rendered image for the
current context to the screen without needing a context argument and
works in both single and double buffered modes symmetrically.
System: Mac OS X v10.3 and later
Renderers: All
GL_APPLE_fence (Specification)
-------------------------------
Provides synchronization primitives that can be inserted into the
OpenGL command stream and later queried for completion.
System: Mac OS X v10.2 "Jaguar" and later
Renderers: All
*/
// Set default editing mode.
#ifdef MESA
int buffer_swap_mode = SWAP_TYPE_NODAMAGE;
#else
# ifdef MACOS_X
int buffer_swap_mode = SWAP_TYPE_APPLE;
# else
int buffer_swap_mode = SWAP_TYPE_UNDEFINED;
# endif
#endif
int use_stencil_for_XOR = 1;
int NVIDIA_XOR_HACK = 0;
int MESA_3_COLOR_FIX = 0;
int AVOID_FRONT_BUFFER_TEXT = 0;
int show_edit_mode_gui = 1;
int autoscaling = 0;
int editing = 0;
int curpiece = 0;
int curpoint = -1;
int movingpiece = -1;
int StartLineNo = -1;
int DrawToCurPiece = 0;
char editingprevmode = 'C';
int editingkey = -1;
int SOLID_EDIT_MODE = 0;
#define EDIT_LINE_LEN 512
static char eprompt[4][EDIT_LINE_LEN];
static char ecommand[EDIT_LINE_LEN] = "";
static char eresponse[EDIT_LINE_LEN] = "";
float moveXamount = 10.0;
float moveYamount = 8.0;
float moveZamount = 10.0;
float turnCenter[4][4] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int turnAxisVisible = 0;
// staticbuffer is where our non-moving background goes
// screenbuffer is where the final composite goes
int staticbuffer = GL_BACK;
int screenbuffer = GL_FRONT;
// renderbuffer is where we render to. Need to know for -ms step saving.
int renderbuffer = GL_FRONT;
// Buffer pointers and IDs for speedier opengl extension functions.
GLint rBits, gBits, bBits, aBits;
GLint DepthBits = 0;
GLint StencilBits = 0;
GLuint cbuffer_region = 0;
GLuint zbuffer_region = 0;
//static float *zbufdata = NULL; // NOTE: gotta free when finished editing.
static int *zbufdata = NULL; // NOTE: gotta free when finished editing.
static char *cbufdata = NULL; // NOTE: gotta free when finished editing.
/***************************************************************/
extern int Find1PartMatrix(int partnum, float m[4][4]);
extern int Find1Part(int partnum);
extern int Draw1Part(int partnum, int Color);
extern int Get1PartPos(int partnum, float m[4][4]);
extern int Move1Part(int partnum, float m[4][4], int premult);
extern int Rotate1Part(int partnum, float m[4][4]);
extern int Translate1Part(int partnum, float m[4][4]);
extern int Locate1Part(int partnum, float m[4][4], int moveonly);
extern int Color1Part(int partnum, int Color);
extern int Add1Part(int partnum);
extern int Select1Part(int partnum);
extern int UnSelect1Part(int partnum);
extern int Delete1Part(int partnum);
extern int Swap1Part(int partnum, char *SubPartDatName);
extern int Print1Part(int partnum, FILE *f);
extern int Print1Model(char *filename);
extern int Print3Parts(int partnum, char *s1, char *s2, char *s3);
extern int Comment1Part(int partnum, char *Comment);
extern int Switch1Part(int partnum);
extern int Get1PartBox(int partnum, int sc[4]);
extern int Make1Primitive(int partnum, char *str);
extern int GetCurLineType(int partnum);
extern int Inline1Part(int partnum);
extern int DrawTurnAxis(float m[4][4]);
int use_quads = 0;
int curstep = 0;
int cropping = 1;
int panning = 0;
int panlock = 0;
int dirtyWindow = 0;
int pan_start_sx = 0; // Screen Coords
int pan_start_sy = 0;
GLdouble pan_start_x = 0.0;
GLdouble pan_start_y = 0.0;
GLdouble pan_end_x = 0.0;
GLdouble pan_end_y = 0.0;
int pan_start_F;
//int pan_visible = TYPE_F_BBOX_MODE | TYPE_F_NO_POLYGONS; // BBoxWire spin mode.
int pan_visible = TYPE_F_BBOX_MODE | TYPE_F_SHADED_MODE; //BBoxShaded spin mode.
int glutModifiers;
int z_extent_x1;
int z_extent_x2;
int z_extent_y1;
int z_extent_y2;
//#define USE_QUATERNION 1
#ifdef USE_QUATERNION
float qspin[4] = {0.0, 0.0, 1.0, 0.0};
#endif
int drawAxis = 0;
int qualityLines = 0;
float lineWidth = 0.0;
int LineChecking = 0;
int preprintstep = 0;
int dimLevel = 0; // Same as ldraw_commandline_opts.maxlevel=32767; // a huge number
float dimAmount = 0.0;
int downsample = 0; // decimate output file by 2 with antialias filter.
int upscale = 0; // upscale everything needed for eventual downsample.
#ifdef TILE_RENDER_OPTION
#include "tr.h"
int tiledRendering = 0;
int TILE_WIDTH = 512;
int TILE_HEIGHT = 512;
int TILE_BORDER = 0;
int TILE_IMAGE_WIDTH = 2000;
int TILE_IMAGE_HEIGHT = 1500;
#endif
int OffScreenRendering = 0;
extern int SetOffScreenRendering();
extern int OffScreenDisplay();
extern int OffScreenRender();
// Opengl implementation details.
char *verstr = "";
char *extstr = "";
char *vendstr = "";
char *rendstr = "";
// Camera movement variables
#define MOVE_SPEED 10.0
#define PI 3.1415927
#define PI_180 (PI/180.0)
float fCamX = 0.0;
float fCamY = 0.0;
float fCamZ = 0.0;
float fXRot = 0.0;
float fYRot = 0.0;
float fZRot = 0.0;
void reshape(int width, int height);
void rendersetup(void);
int edit_mode_keyboard(int key, int x, int y);
int edit_mode_fnkeys(int key, int x, int y);
void mouse(int button, int state, int x, int y);
char *stristr(char *src, char *dst);
/***************************************************************/
static int prevlookup = 0;
static char *partlistbuf = NULL;
static int partlookup = 0;
static char **partlistptr = NULL;
static char **partliststr = NULL;
static int partlistsize = 0;
static int partlisttotal = 0;
static int partlistmax = 0;
/***************************************************************/
static char *pluglistbuf = NULL;
static int pluglookup = 0;
static char **pluglistptr = NULL;
static char **plugliststr = NULL;
static int pluglistsize = 0;
static int pluglisttotal = 0;
static int pluglistmax = 0;
#include "plugins.h"
plugstruct **plugins;
/***************************************************************/
char *pastelist = NULL;
/***************************************************************/
char *strrpbrk(const char *szString, const char *szChars)
{
const char *p;
char *p0, *p1;
for (p = szChars, p0 = p1 = NULL; p && *p; ++p)
{
p1 = strrchr(szString, *p);
if (p1 && p1 > p0)
p0 = p1;
}
return p0;
}
#ifdef WINDOWS
/***************************************************************/
void pasteMove(int moving)
{
static int moveCnt = 0;
static int moveMax = 0;
static int moveDir = 0;
int moveKeys[4] = {GLUT_KEY_UP, GLUT_KEY_LEFT, GLUT_KEY_DOWN, GLUT_KEY_RIGHT};
if (moving <= 0)
{
moveCnt = 0;
moveMax = 0;
moveDir = -1;
printf("pasteMove{%d)\n",moving);
return;
}
moveCnt++;
if (moveCnt > moveMax)
{
moveCnt = 0;
if (moveDir == 1)
moveMax++;
else if (moveDir == 3)
moveMax++;
moveDir++;
moveDir &= 3;
}
edit_mode_fnkeys(moveKeys[moveDir], 0, 0);
printf("pasteMove{%d, %d)\n",moving, moveDir);
}
/***************************************************************/
void pasteCommand(int x, int y)
{
char *str;
char *dst = &ecommand[1];
char *whitespace = " \t\r\n";
char *seps = "\r\n"; // Newline separator chars for DOS, MAC & UNIX.
char *token;
char *s;
char *p;
int i, n, count;
int inventory = 0;
char partstr[255];
char colorstr[255];
int color;
int pastecount = 0;
float savemove = moveXamount;
if (pastelist)
{
str = pastelist;
pastelist = NULL;
}
else if(OpenClipboard(NULL))
{
str = strdup((char*)GetClipboardData(CF_TEXT));
printf("got <%s> from clipboard\n", str);
CloseClipboard();
}
else
return;
// Remove modifier keys before processing the clipboard.
// (We know for sure that Ctrl-V has GLUT_ACTIVE_CTRL set)
glutModifiers = 0;
// Set the move amount to Coarse for a big spiral.
moveXamount = 100.0; // Coarse movement.
moveZamount = 100.0;
moveYamount = 80.0;
// For partname or filename, do not allow space or tab chars.
for (i = 0, token = strtok( str, seps );
token != NULL;
i++, token = strtok( NULL, seps ))
{
color = -1; // Use current color
printf("got token <%s> from clipboard\n", token);
// token is one line of text.
if ((ecommand[0] == 'p') || ((i > 0) && (ecommand[0] == 'c')) ||
(ecommand[0] == 'L') || (ecommand[0] == 'S'))
{
// NOTE: Should skip leading white space, trailing white space.
// Search for first '.' char and grab filename/path around it.
// Should also allow paste of a full LDRAW type 1 line.
// Actually should allow paste of many LDRAW lines/files.
// n = sscanf(token,
// "%d %d %f %f %f %f %f %f %f %f %f %f %f %f %s",...)
// if ((n == 15) && (d == 1))
// it's a type 1 LDRAW line. Keep all info.
// If working on a part, check for peeron inventory list.
if ((ecommand[0] == 'p') || ((i > 0) && (ecommand[0] == 'c')))
{
//if (strstr(token, "Part # Color Description"))
if (stristr(token, "Qty") && stristr(token, "PartNum") &&
stristr(token, "Color") && stristr(token, "Description"))
{
printf("// Hey, it's an inventory from peeron.com.\n");
inventory = 1;
token = strtok( NULL, seps); // Move on to the actual inventory.
printf("Got token <%s> from clipboard\n", token);
}
}
// Look for '.' and remove trailing, leading whitespace.
// If no '.' found, focus on the first word.
if ((!inventory) && (p = strchr(token, '.')))
{
// Eliminate trailing whitespace
if (s = strpbrk(p, whitespace))
*s = 0;
//printf("got trailing <%s> from clipboard\n", token);
// Eliminate leading whitespace
*p = 0;
if (s = strrpbrk(token, whitespace))
token = s+1;
*p = '.';
}
else
token += strspn(token, whitespace); // Eliminate leading whitespace
//printf("got leading <%s> from clipboard\n", token);
if (!inventory)
{
// If not inventory and we still have whitespace, then its a comment.
if (s = strrpbrk(token, whitespace))
{
if ((i > 0) && (ecommand[0] == 'c'))
{
edit_mode_keyboard('\n', x, y);
edit_mode_keyboard('i', x, y);
ecommand[0] == 'p';
}
if (ecommand[0] == 'p')
{
ecommand[0] = 'C'; // Switch to a comment
strcpy(dst, " ");
strcat(dst, token);
continue;
}
}
}
else
{
n = sscanf(token, "%d", &count);
//printf("count = %d\n", count);
p = strpbrk(token, whitespace);
//printf("got trailing <%s> from clipboard\n", p);
if ((n == 0) || !p)
{
if ((i > 0) && (ecommand[0] == 'c'))
{
edit_mode_keyboard('\n', x, y);
edit_mode_keyboard('i', x, y);
}
ecommand[0] = 'C'; // Switch to a comment
strcpy(dst, " ");
strcat(dst, token);
inventory = 0; // All done with inventory.
continue;
}
if (strncmp(p, " ", 4))
n = sscanf(p, " %s %s", partstr, colorstr); // Found a partname.
else if (!strncmp(p, " ", 5))
{
// no part or color on this line. Sticker sheet or cloth or whatever?
sprintf(colorstr, "unknown");
strcpy(partstr, p);
}
else
{
// No part on this line. Convert comment into bogus partname.
p += strspn(p, whitespace); // Eliminate leading whitespace
n = sscanf(p, "%s", colorstr); // Get the color
if (token = strpbrk(p, whitespace)) // Find next whitespace
p = token + strspn(token, whitespace); // Eliminate leading whitespace
// Eliminate trailing whitespace
token = p;
for (p += (strlen(token)-1); p >= token; p--)
{
if ((*p == ' ') || (*p == '\t'))
*p = 0;
else
break;
}
//printf("filling spaces <%s>\n",token);
// Eliminate internal spaces
for (p = token; *p; p++)
if ((*p == ' ') || (*p == '\t'))
*p = '_';
//printf("copying token <%s>\n",token);
strcpy(partstr, token);
}
//printf("setting setting token to part <%s>\n", partstr);
token = partstr;
color = zcolor_lookup(colorstr);
printf("Part = <%s>, color = <%s> = %d\n", token, colorstr, color);
sprintf(colorstr, "%d", color);
}
}
if (token && strlen(token))
{
// If subsequent part, insert last part and start this one.
if (i > 0)
{
edit_mode_keyboard('\n', x, y);
edit_mode_keyboard('i', x, y);
pasteMove(pastecount++);
edit_mode_keyboard('p', x, y);
}
else
pasteMove(pastecount++);
strcat(dst, token);
// Only do more than one if it's a part.
// NOTE: Should also do multiple lines for comments.
if (ecommand[0] != 'p')
break;
if (color >= 0)
{
edit_mode_keyboard('\n', x, y);
edit_mode_keyboard('c', x, y);
strcat(dst, colorstr);
}
if (inventory)
for (n = 1; n < count; n++)
{
edit_mode_keyboard('\n', x, y);
edit_mode_keyboard('i', x, y);
pasteMove(pastecount++);
#if 1
edit_mode_keyboard('p', x, y);
strcat(dst, token);
if (color >= 0)
{
edit_mode_keyboard('\n', x, y);
edit_mode_keyboard('c', x, y);
strcat(dst, colorstr);
}
#endif
}
}
}
free(str);
printf("ecommand = <%s>\n", ecommand);
//restore move amount
if (savemove == 100.0)
{
moveXamount = 100.0; // Coarse movement.
moveZamount = 100.0;
moveYamount = 80.0;
}
else if (savemove == 1.0)
{
moveXamount = 1.0; // Fine movement.
moveZamount = 1.0;
moveYamount = 1.0;
}
else
{
moveXamount = 10.0; // Normal movement.
moveZamount = 10.0;
moveYamount = 8.0;
}
}
#endif
//---------------MESA TESTING BLOCK----------------------
//#define SIMULATE_MESA 1
//#define WINTIMER 1
//#define SAVE_COLOR_ALL 1
//#define SAVE_DEPTH_ALL 1
#define MESA_XOR_TEST 1
//---------------MESA TESTING BLOCK----------------------
//---------------OSX MAC TESTING BLOCK----------------------
//#define SIMULATE_APPLE_BUGS 1
//#define WINTIMER 1
//#define SAVE_COLOR_ALL 1
//#define SAVE_DEPTH_ALL 1
//#define MACOS_X_TEST2 1
//---------------OSX MAC TESTING BLOCK----------------------
#ifdef WINTIMER
#include <mmsystem.h>
int starttime, finishtime, elapsedtime;
#pragma comment (lib, "winmm.lib") /* link with Windows MultiMedia lib */
#endif
#ifdef MACOS_X_TEST2
/***************************************************************/
void SaveColorBuffer(void)
{
#ifdef WINTIMER
starttime = timeGetTime();
#endif
{
glPixelStorei(GL_PACK_ALIGNMENT,1); //4
glPixelStorei(GL_PACK_ROW_LENGTH,0);
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
#ifndef SAVE_COLOR_ALL
// Gotta figure out the src,dst stuff. glTranslate()?
//glRasterPos2i((int)sc[0], (int)sc[1]);
Get1PartBox(curpiece, sc);
if (ldraw_commandline_opts.debug_level == 1)
printf("sbox = %d, %d, %d, %d\n", sc[0], sc[1], sc[2], sc[3]);
if (cbufdata)
free (cbufdata); // NOTE: gotta free this when finished editing.
cbufdata = (int *) malloc(sc[2] * sc[3] * 4 * sizeof(char));
glReadBuffer(staticbuffer); // set pixel source
glReadPixels(sc[0],sc[1],sc[2],sc[3],GL_RGBA,GL_UNSIGNED_BYTE,cbufdata);
#else
#ifndef RESTORE_DEPTH_ALL
Get1PartBox(curpiece, sc);
if (ldraw_commandline_opts.debug_level == 1)
printf("sc_sbox = %d, %d, %d, %d\n", sc[0], sc[1], sc[2], sc[3]);
#endif
if (cbufdata) // NOTE: gotta free this when finished editing.
{
//cbufdata = realloc(zbufdata, Width * Height * sizeof(float));
}
else
cbufdata = (char *) malloc(Width * Height * 4 * sizeof(char));
glReadBuffer(staticbuffer); // set pixel source
glReadPixels(0,0,Width,Height,GL_RGBA,GL_UNSIGNED_BYTE,cbufdata);
#endif
}
#ifdef WINTIMER
finishtime = timeGetTime();
printf("Save Color Elapsed = %d\n", finishtime-starttime);
#endif
//NOTE: I have to reallocate cbufdata whenever we resize the window.
}
/***************************************************************/
void RestoreColorBuffer(void)
{
int savedirty;
#ifdef WINTIMER
starttime = timeGetTime();
#endif
// get fresh copy of static data
{
// Gotta fix these later because they get set only once in init().
//glDisable(GL_COLOR_MATERIAL);
//glDisable(GL_POLYGON_OFFSET_FILL);
//glEnable(GL_CULL_FACE);
//glFrontFace(GL_CW);
//glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glPixelZoom(1, 1);
glDisable(GL_STENCIL_TEST);
glDisable(GL_FOG);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_COLOR_MATERIAL);
/*
* Disable stuff that's likely to slow down
* glDrawPixels.(Omit as much of this as possible,
* when you know in advance that the OpenGL state is
* already set correctly.)
*/
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_DITHER);
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
glDisable(GL_LOGIC_OP);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_2D);
glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
glPixelTransferi(GL_RED_SCALE, 1);
glPixelTransferi(GL_RED_BIAS, 0);
glPixelTransferi(GL_GREEN_SCALE, 1);
glPixelTransferi(GL_GREEN_BIAS, 0);
glPixelTransferi(GL_BLUE_SCALE, 1);
glPixelTransferi(GL_BLUE_BIAS, 0);
glPixelTransferi(GL_ALPHA_SCALE, 1);
glPixelTransferi(GL_ALPHA_BIAS, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT,1); //4
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
// Turn off any smoothing or blending modes.
glDisable( GL_POINT_SMOOTH );
glDisable(GL_ALPHA_TEST);
glDisable( GL_LINE_SMOOTH );
glHint( GL_LINE_SMOOTH_HINT, GL_FASTEST ); // GL_NICEST GL_DONT_CARE
glDisable( GL_BLEND );
glDisable( GL_POLYGON_SMOOTH );
glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST ); // GL_NICEST GL_DONT_CARE
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glDisable(GL_LIGHTING); // Speed up copying
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); //enable color buffer updates
glDisable( GL_DEPTH_TEST );
glDepthFunc(GL_ALWAYS);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D(0, Width, 0, Height);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glRasterPos2i(0, 0);
glDrawBuffer(screenbuffer); // set pixel destination
#ifndef SAVE_COLOR_ALL
// Gotta figure out the src,dst stuff. glTranslate()?
glRasterPos2i(sc[0], sc[1]);
if (ldraw_commandline_opts.debug_level == 1)
printf("bbox = %d, %d, %d, %d\n", sc[0], sc[1], sc[2], sc[3]);
glDrawPixels(sc[2],sc[3],GL_RGBA,GL_UNSIGNED_BYTE,cbufdata);
#else
#ifdef RESTORE_COLOR_ALL
glPixelStorei(GL_UNPACK_ALIGNMENT,1); //4
glPixelStorei(GL_UNPACK_ROW_LENGTH,0); //Width
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glDrawPixels(Width,Height,GL_RGBA,GL_UNSIGNED_BYTE,cbufdata);
#else
glPixelStorei(GL_UNPACK_ALIGNMENT,1); //4
glPixelStorei(GL_UNPACK_ROW_LENGTH,Width); //Width
glPixelStorei(GL_UNPACK_SKIP_ROWS, sc[1]);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, sc[0]);
glRasterPos2i(sc[0], sc[1]);
if (ldraw_commandline_opts.debug_level == 1)
printf("bbox = %d, %d, %d, %d\n", sc[0], sc[1], sc[2], sc[3]);
glDrawPixels(sc[2],sc[3],GL_RGBA,GL_UNSIGNED_BYTE,cbufdata);
// Set UNPACK back to default for glPolygonStipple()
glPixelStorei(GL_UNPACK_ROW_LENGTH,0); //Width
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
#endif
#endif
glEnable(GL_COLOR_MATERIAL);
if (PolygonOffsetEnabled)
{
glEnable(GL_POLYGON_OFFSET_FILL);
}
glPopMatrix();
glEnable( GL_DEPTH_TEST );
glDepthFunc(GL_LESS);
glDrawBuffer(renderbuffer); // set pixel destination to the render buffer.
// Reset the projection matrix.
savedirty = dirtyWindow;
reshape(Width, Height);
dirtyWindow = savedirty;
rendersetup();
}
#ifdef WINTIMER
finishtime = timeGetTime();
printf("Restore Color Elapsed = %d\n", finishtime-starttime);
#endif
}
#endif
/***************************************************************/
void CopyColorBuffer(int srcbuffer, int destbuffer)
{
int savedirty;
#ifdef WINTIMER
starttime = timeGetTime();
#endif
if ((srcbuffer == staticbuffer) && (destbuffer == screenbuffer))
{
if ((buffer_swap_mode == SWAP_TYPE_COPY)
|| (buffer_swap_mode == SWAP_TYPE_NODAMAGE)
|| (buffer_swap_mode == SWAP_TYPE_APPLE) // OSX seems to COPY (according to blender)
)
{
printf("CopyColorBuffer(%s to %s) = glutswapBuffers(mode=%d)\n",
((srcbuffer==GL_FRONT)? "Front" : "Back"),
((destbuffer==GL_FRONT)? "Front" : "Back"),
buffer_swap_mode);
glutSwapBuffers(); // Found GL_WIN_swap_hint extension
#ifdef WINTIMER
finishtime = timeGetTime();
printf("SwapIn Color Elapsed = %d\n", finishtime-starttime);
#endif
return;
}
}
printf("CopyColorBuffer(%s to %s)\n",
((srcbuffer==GL_FRONT)? "Front" : "Back"),
((destbuffer==GL_FRONT)? "Front" : "Back"));
glPushAttrib(GL_COLOR_BUFFER_BIT|GL_CURRENT_BIT|GL_DEPTH_BUFFER_BIT|
GL_FOG_BIT|GL_LIGHTING_BIT|GL_VIEWPORT_BIT);
glPixelZoom(1, 1);
glDisable(GL_STENCIL_TEST);
glDisable(GL_FOG);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_COLOR_MATERIAL);
glReadBuffer(srcbuffer); // set pixel source
glDrawBuffer(destbuffer); // set pixel destination
/*
* Disable stuff that's likely to slow down
* glDrawPixels.(Omit as much of this as possible,
* when you know in advance that the OpenGL state is
* already set correctly.)