80
82
static XrmOptionDescRec opts[] = {
81
83
{"-parts", ".circuit.parts", XrmoptionSepArg, "10" },
84
{"-font", ".circuit.font", XrmoptionSepArg, "fixed" },
82
85
{"-rotate-speed", ".circuit.rotatespeed", XrmoptionSepArg, "1" },
83
{"+spin", ".circuit.spin", XrmoptionNoArg, (caddr_t) "false" },
84
{"-spin", ".circuit.spin", XrmoptionNoArg, (caddr_t) "true" },
85
{"+light", ".circuit.light", XrmoptionNoArg, (caddr_t) "false" },
86
{"-light", ".circuit.light", XrmoptionNoArg, (caddr_t) "true" },
87
{"+seven", ".circuit.seven", XrmoptionNoArg, (caddr_t) "false" },
88
{"-seven", ".circuit.seven", XrmoptionNoArg, (caddr_t) "true" },
89
{"+rotate", ".circuit.rotate", XrmoptionNoArg, (caddr_t) "false" },
90
{"-rotate", ".circuit.rotate", XrmoptionNoArg, (caddr_t) "true" },
86
{"+spin", ".circuit.spin", XrmoptionNoArg, "false" },
87
{"-spin", ".circuit.spin", XrmoptionNoArg, "true" },
88
{"+light", ".circuit.light", XrmoptionNoArg, "false" },
89
{"-light", ".circuit.light", XrmoptionNoArg, "true" },
90
{"+seven", ".circuit.seven", XrmoptionNoArg, "false" },
91
{"-seven", ".circuit.seven", XrmoptionNoArg, "true" },
92
{"+rotate", ".circuit.rotate", XrmoptionNoArg, "false" },
93
{"-rotate", ".circuit.rotate", XrmoptionNoArg, "true" },
93
96
static argtype vars[] = {
94
{(caddr_t *) &maxparts, "parts", "Parts", DEF_PARTS, t_Int},
95
{(caddr_t *) &rotatespeed, "rotatespeed", "Rotatespeed", "1", t_Int},
96
{(caddr_t *) &spin, "spin", "Spin", DEF_SPIN, t_Bool},
97
{(caddr_t *) &rotate, "rotate", "Rotate", "False", t_Bool},
98
{(caddr_t *) &uselight, "light", "Light", "True", t_Bool},
99
{(caddr_t *) &seven, "seven", "Seven", DEF_SEVEN, t_Bool},
97
{&maxparts, "parts", "Parts", DEF_PARTS, t_Int},
98
{&font, "font", "Font", "fixed", t_String},
99
{&rotatespeed, "rotatespeed", "Rotatespeed", "1", t_Int},
100
{&spin, "spin", "Spin", DEF_SPIN, t_Bool},
101
{&rotate, "rotate", "Rotate", "False", t_Bool},
102
{&uselight, "light", "Light", "True", t_Bool},
103
{&seven, "seven", "Seven", DEF_SEVEN, t_Bool},
102
106
ModeSpecOpt circuit_opts = {countof(opts), opts, countof(vars), vars, NULL};
423
563
void sphere(GLfloat r, float stacks, float slices,
424
564
int startstack, int endstack, int startslice,
426
GLfloat d, d1, dr, dr1, Dr, Dr1, D, D1, z1, z2, y1, y2, Y1, Z1, Y2, Z2;
427
int a, a1, b, b1, c, c1;
567
GLfloat d, d1, dr, dr1, Dr, Dr1, D, D1, z1, z2, y1, y2, Y1, Z1, Y2, Z2;
568
int a, a1, b, b1, c, c1;
432
a1 = startstack * step;
433
b1 = startslice * sstep;
434
y1 = z1 = Y1 = Z1 = 0;
435
c = (endslice / slices) * 360;
436
c1 = (endstack/stacks)*180;
438
for (a = startstack * step ; a <= c1 ; a+= step) {
447
for (b = b1 ; b <= c ; b+= sstep) {
452
glNormal3f(D, y1, z1);
453
glVertex3f(Dr,y1,z1);
454
glVertex3f(Dr,y2,z2);
455
glVertex3f(Dr1,Y2,Z2);
456
glVertex3f(Dr1,Y1,Z1);
573
a1 = startstack * step;
574
b1 = startslice * sstep;
575
y1 = z1 = Y1 = Z1 = 0;
576
c = (endslice / slices) * 360;
577
c1 = (endstack/stacks)*180;
579
for (a = startstack * step ; a <= c1 ; a+= step) {
588
for (b = b1 ; b <= c ; b+= sstep) {
593
glNormal3f(Dr, y1, z1);
594
glVertex3f(Dr,y1,z1);
595
glNormal3f(Dr, y2, z2);
596
glVertex3f(Dr,y2,z2);
597
glNormal3f(Dr1, Y2, Z2);
598
glVertex3f(Dr1,Y2,Z2);
599
glNormal3f(Dr1, Y1, Z1);
600
glVertex3f(Dr1,Y1,Z1);
467
int DrawComponent(Component *c) {
468
int ret = 0; /* return 1 if component is freed */
611
int DrawComponent(Component *c)
613
int ret = 0; /* return 1 if component is freed */
471
616
glTranslatef(c->x, c->y, c->z);
472
617
if (c->angle > 0) {
473
glRotatef(c->angle, 0, 0, 1);
618
glRotatef(c->angle, c->rotx, c->roty, c->rotz);
476
621
glRotatef(c->rdeg, c->rotx, c->roty, c->rotz);
549
void DrawFuse(Fuse *f) {
550
static GLfloat col[] = {0.5, 0.5, 0.5, 1.0}; /* endcaps */
551
static GLfloat glass[] = {0.4, 0.4, 0.4, 0.3}; /* glass */
552
static GLfloat spec[] = {1, 1, 1, 1}; /* glass */
712
void DrawRCA(RCA *rca)
714
static GLfloat col[] = {0.6, 0.6, 0.6, 1.0}; /* metal */
715
static GLfloat red[] = {1.0, 0.0, 0.0, 1.0}; /* red */
716
static GLfloat white[] = {1.0, 1.0, 1.0, 1.0}; /* white */
717
static GLfloat spec[] = {1, 1, 1, 1}; /* glass */
720
glTranslatef(0.3, 0, 0);
721
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col);
722
glMateriali(GL_FRONT, GL_SHININESS, 40);
723
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
724
createCylinder(0.7, 0.45, 0, 0);
725
glTranslatef(0.4, 0, 0);
726
createCylinder(0.9, 0.15, 1, 0);
727
glTranslatef(-1.9, 0, 0);
728
glMateriali(GL_FRONT, GL_SHININESS, 20);
729
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, rca->col ? white : red);
730
createCylinder(1.5, 0.6, 1, 0);
731
glTranslatef(-0.9, 0, 0);
732
createCylinder(0.9, 0.25, 0, 0);
733
glTranslatef(0.1, 0, 0);
734
createCylinder(0.2, 0.3, 0, 0);
735
glTranslatef(0.3, 0, 0);
736
createCylinder(0.2, 0.3, 1, 0);
737
glTranslatef(0.3, 0, 0);
738
createCylinder(0.2, 0.3, 1, 0);
742
void DrawSwitch(Switch *f)
744
static GLfloat col[] = {0.6, 0.6, 0.6, 0}; /* metal */
745
static GLfloat dark[] = {0.1, 0.1, 0.1, 1.0}; /* dark */
746
static GLfloat brown[] = {0.69, 0.32, 0, 1.0}; /* brown */
747
static GLfloat spec[] = {0.9, 0.9, 0.9, 1}; /* shiny */
750
glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
751
glMaterialfv(GL_FRONT, GL_AMBIENT, dark);
752
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
753
glMateriali(GL_FRONT, GL_SHININESS, 90);
754
Rect(-0.25, 0, 0, 1.5, 0.5, 0.75);
755
/* Rect(-0.5, 0.5, 0, 2, 0.1, 0.75); */
757
glRotatef(90, 1, 0, 0);
758
glTranslatef(-0.5, -0.4, -0.4);
759
HoledRectangle(0.5, 0.75, 0.1, 0.15, 8);
760
glTranslatef(2, 0, 0);
761
HoledRectangle(0.5, 0.75, 0.1, 0.15, 8);
763
Rect(0.1, -0.4, -0.25, 0.1, 0.4, 0.05);
764
Rect(0.5, -0.4, -0.25, 0.1, 0.4, 0.05);
765
Rect(0.9, -0.4, -0.25, 0.1, 0.4, 0.05);
766
Rect(0.1, -0.4, -0.5, 0.1, 0.4, 0.05);
767
Rect(0.5, -0.4, -0.5, 0.1, 0.4, 0.05);
768
Rect(0.9, -0.4, -0.5, 0.1, 0.4, 0.05);
769
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, dark);
770
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
771
Rect(0, 0.5, -0.1, 1, 0.05, 0.5);
772
Rect(0, 0.6, -0.1, 0.5, 0.6, 0.5);
773
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, brown);
774
Rect(-0.2, -0.01, -0.1, 1.4, 0.1, 0.55);
779
void DrawFuse(Fuse *f)
781
static GLfloat col[] = {0.5, 0.5, 0.5, 1.0}; /* endcaps */
782
static GLfloat glass[] = {0.4, 0.4, 0.4, 0.3}; /* glass */
783
static GLfloat spec[] = {1, 1, 1, 1}; /* glass */
786
glTranslatef(-1.8, 0, 0);
555
787
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col);
556
788
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
557
789
glMateriali(GL_FRONT, GL_SHININESS, 40);
581
void DrawCapacitor(Capacitor *c) {
582
static GLfloat col[] = {0, 0, 0, 0};
583
static GLfloat spec[] = {0.8, 0.8, 0.8, 0};
584
GLfloat brown[] = {0.84, 0.5, 0};
585
static GLfloat shine = 40;
812
void DrawCapacitor(Capacitor *c)
814
static GLfloat col[] = {0, 0, 0, 0};
815
static GLfloat spec[] = {0.8, 0.8, 0.8, 0};
816
GLfloat brown[] = {0.84, 0.5, 0};
817
static GLfloat shine = 40;
589
821
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, brown);
590
sphere(c->width, 20, 20, 0, 5 ,0, 20);
591
glTranslatef(1.45*c->width, 0, 0);
592
sphere(c->width, 20, 20, 15, 20, 0, 20);
822
sphere(c->width, 15, 15, 0, 4 ,0, 15);
823
glTranslatef(1.35*c->width, 0, 0);
824
sphere(c->width, 15, 15, 11, 15, 0, 15);
593
825
glRotatef(90, 0, 0, 1);
594
826
glTranslatef(0, 0.7*c->width, 0.3*c->width);
595
827
wire(3*c->width);
596
828
glTranslatef(0, 0, -0.6*c->width);
597
829
wire(3*c->width);
831
glTranslatef(0-c->length*2, 0, 0);
599
832
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col);
600
833
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
601
834
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &shine);
605
838
glVertex3f(3*c->length, 0.82*c->width, 0.1);
606
839
glVertex3f(0, 0.82*c->width, 0.1);
611
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col);
612
circle(0.6*c->width, 30, 0);
616
844
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col);
617
ring(0.6*c->width, 0.8*c->width, 30);
618
glTranslatef(0.01, 0.0, 0);
845
glEnable(GL_POLYGON_OFFSET_FILL);
846
glPolygonOffset(1.0, 1.0);
619
847
createCylinder(3.0*c->length, 0.8*c->width, 1, 0);
848
glDisable(GL_POLYGON_OFFSET_FILL);
852
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col);
853
circle(0.6*c->width, 30, 0);
623
857
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col);
624
glTranslatef(3.01*c->length, 0.0, 0);
858
glTranslatef(3.0*c->length, 0.0, 0);
625
859
circle(0.6*c->width, 30, 0);
626
860
glTranslatef(0, 0.4*c->width, 0);
627
861
wire(3*c->length);
929
void DrawThreeFive(ThreeFive *d)
932
GLfloat dark[] = {0.3, 0.3, 0.3, 0};
933
GLfloat light[] = {0.6, 0.6, 0.6, 0};
934
GLfloat cream[] = {0.8, 0.8, 0.6, 0};
935
GLfloat spec[] = {0.7, 0.7, 0.7, 0};
938
glMaterialfv(GL_FRONT, GL_SHININESS, &shine);
939
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cream);
940
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
692
void DrawDiode(Diode *d) {
694
GLfloat col[] = {0.3, 0.3, 0.3, 0};
695
GLfloat spec[] = {0.7, 0.7, 0.7, 0};
942
glTranslatef(-2.0, 0, 0);
943
createCylinder(0.7, 0.2, 0, 0);
944
glTranslatef(0.7, 0, 0);
945
createCylinder(1.3, 0.4, 1, 0);
946
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, light);
947
glTranslatef(1.3, 0, 0);
948
createCylinder(1.3, 0.2, 0, 0);
949
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, dark);
950
glTranslatef(0.65, 0, 0);
951
createCylinder(0.15, 0.21, 0, 0);
952
glTranslatef(0.3, 0, 0);
953
createCylinder(0.15, 0.21, 0, 0);
954
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, light);
955
glTranslatef(0.4, 0, 0);
956
sphere(0.23, 7, 7, 0, 5, 0, 7);
961
void DrawDiode(Diode *d)
964
GLfloat col[] = {0.3, 0.3, 0.3, 0};
965
GLfloat spec[] = {0.7, 0.7, 0.7, 0};
698
968
glMaterialfv(GL_FRONT, GL_SHININESS, &shine);
778
GLfloat col[] = {0.1, 0.1, 0.1, 0};
779
GLfloat spec[] = {0.6, 0.6, 0.6, 0};
781
GLfloat lspec[] = {0.6, 0.6, 0.6, 0};
782
GLfloat lcol[] = {0.4, 0.4, 0.4, 0};
1049
GLfloat col[] = {0.1, 0.1, 0.1, 0};
1050
GLfloat col2[] = {0.2, 0.2, 0.2, 0};
1051
GLfloat spec[] = {0.6, 0.6, 0.6, 0};
1053
GLfloat lspec[] = {0.6, 0.6, 0.6, 0};
1054
GLfloat lcol[] = {0.4, 0.4, 0.4, 0};
1055
GLfloat lshine = 40;
1056
float mult, th, size;
786
1059
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col);
787
1060
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
1061
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
788
1062
glMaterialfv(GL_FRONT, GL_SHININESS, &shine);
789
1063
switch(c->pins) {
845
1145
for (z = 0 ; z < c->pins/2 ; z++) {
846
1146
ICLeg(-w, -h + z*d + d/2, 0, 1);
1148
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col2);
1149
glTranslatef(-w+0.3, h-0.3, 0.1);
1150
glRotatef(90, 0, 1, 0);
851
void DrawDisp(Disp *d) {
852
GLfloat col[] = {0.8, 0.8, 0.8, 1.0}; /* body colour */
853
GLfloat front[] = {0.2, 0.2, 0.2, 1.0}; /* front colour */
854
GLfloat on[] = {0.9, 0, 0, 1}; /* 'on' segment */
855
GLfloat off[] = {0.3, 0, 0, 1}; /* 'off' segment */
857
GLfloat x, y; /* for the pins */
858
GLfloat spec[] = {0.6, 0.6, 0.6, 0};
859
GLfloat lcol[] = {0.4, 0.4, 0.4, 0};
861
static GLfloat vdata_h[6][2] =
870
static GLfloat vdata_v[6][2] =
880
static GLfloat seg_start[7][2] =
892
static int nums[10][7] =
894
{1, 1, 1, 1, 1, 1, 0}, /* 0 */
895
{0, 1, 1, 0, 0, 0, 0}, /* 1 */
896
{1, 1, 0, 1, 1, 0, 1}, /* 2 */
897
{1, 1, 1, 1, 0, 0, 1}, /* 3 */
898
{0, 1, 1, 0, 0, 1, 1}, /* 4 */
899
{1, 0, 1, 1, 0, 1, 1}, /* 5 */
900
{1, 0, 1, 1, 1, 1, 1}, /* 6 */
901
{1, 1, 1, 0, 0, 0, 0}, /* 7 */
902
{1, 1, 1, 1, 1, 1, 1}, /* 8 */
903
{1, 1, 1, 0, 0, 1, 1} /* 9 */
1155
void DrawDisp(Disp *d)
1157
GLfloat col[] = {0.8, 0.8, 0.8, 1.0}; /* body colour */
1158
GLfloat front[] = {0.2, 0.2, 0.2, 1.0}; /* front colour */
1159
GLfloat on[] = {0.9, 0, 0, 1}; /* 'on' segment */
1160
GLfloat off[] = {0.3, 0, 0, 1}; /* 'off' segment */
1162
GLfloat x, y; /* for the pins */
1163
GLfloat spec[] = {0.6, 0.6, 0.6, 0};
1164
GLfloat lcol[] = {0.4, 0.4, 0.4, 0};
1166
static GLfloat vdata_h[6][2] = {
1174
static GLfloat vdata_v[6][2] = {
1183
static GLfloat seg_start[7][2] = {
1193
static int nums[10][7] = {
1194
{1, 1, 1, 1, 1, 1, 0}, /* 0 */
1195
{0, 1, 1, 0, 0, 0, 0}, /* 1 */
1196
{1, 1, 0, 1, 1, 0, 1}, /* 2 */
1197
{1, 1, 1, 1, 0, 0, 1}, /* 3 */
1198
{0, 1, 1, 0, 0, 1, 1}, /* 4 */
1199
{1, 0, 1, 1, 0, 1, 1}, /* 5 */
1200
{1, 0, 1, 1, 1, 1, 1}, /* 6 */
1201
{1, 1, 1, 0, 0, 0, 0}, /* 7 */
1202
{1, 1, 1, 1, 1, 1, 1}, /* 8 */
1203
{1, 1, 1, 0, 0, 1, 1} /* 9 */
1206
glTranslatef(-0.9, -1.8, 0);
906
1207
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col);
907
1208
Rect(0, 0, -0.01, 1.8, 2.6, 0.7);
908
1209
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, front);
1023
void DrawTransistor(Transistor *t) {
1024
static GLfloat col[] = {0.3, 0.3, 0.3, 1.0};
1025
static GLfloat spec[] = {0.9, 0.9, 0.9, 1.0};
1026
static GLfloat nospec[] = {0.4, 0.4, 0.4, 1.0};
1325
void DrawTransistor(Transistor *t)
1327
static GLfloat col[] = {0.3, 0.3, 0.3, 1.0};
1328
static GLfloat spec[] = {0.9, 0.9, 0.9, 1.0};
1329
static GLfloat nospec[] = {0.4, 0.4, 0.4, 1.0};
1029
1332
glPushMatrix();
1030
1333
glMaterialfv(GL_FRONT, GL_SHININESS, &shin);
1031
1334
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col);
1335
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1336
if (t->type == 1) { /* TO-92 style */
1338
mult = 1.5*t->th/t->tw;
1341
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col);
1033
1342
glRotatef(90, 0, 1, 0);
1034
1343
glRotatef(90, 0, 0, 1);
1035
1344
createCylinder(1.0, 0.4, 1, 1);
1036
1345
Rect(0, -0.2, 0.4, 1, 0.2, 0.8);
1346
/* Draw the markings */
1347
glEnable(GL_TEXTURE_2D);
1348
if (t->tnum) glBindTexture(GL_TEXTURE_2D, t->tnum);
1350
glDepthMask(GL_FALSE);
1352
glNormal3f(0, 0, 1);
1354
glVertex3f(y1, -0.21, 0.3);
1356
glVertex3f(y1, -0.21, -0.3);
1358
glVertex3f(y2, -0.21, -0.3);
1360
glVertex3f(y2, -0.21, 0.3);
1362
glDisable(GL_TEXTURE_2D);
1363
glDisable(GL_BLEND);
1364
glDepthMask(GL_TRUE);
1037
1365
glTranslatef(-2, 0, -0.2);
1039
1367
glTranslatef(0, 0, 0.2);
1041
1369
glTranslatef(0, 0, 0.2);
1044
Rect(0, 0, 0, 1.5, 1.5, 0.75);
1045
glTranslatef(0.75, 1.875, -0.5);
1371
} else if (t->type == 0) { /* TO-220 Style */
1373
mult = 1.5*t->th/t->tw;
1376
Rect(0, 0, 0, 1.5, 1.5, 0.5);
1377
glEnable(GL_TEXTURE_2D);
1378
if (t->tnum) glBindTexture(GL_TEXTURE_2D, t->tnum);
1380
glDepthMask(GL_FALSE);
1382
glNormal3f(0, 0, 1);
1384
glVertex3f(0, y1, 0.01);
1386
glVertex3f(1.5, y1, 0.01);
1388
glVertex3f(1.5, y2, 0.01);
1390
glVertex3f(0, y2, 0.01);
1392
glDisable(GL_TEXTURE_2D);
1393
glDisable(GL_BLEND);
1394
glDepthMask(GL_TRUE);
1046
1395
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col);
1047
1396
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
1048
1397
glMaterialfv(GL_FRONT, GL_SHININESS, &shin);
1049
if (glIsEnabled(GL_NORMALIZE)) glEnable(GL_NORMALIZE);
1398
Rect(0, 0, -0.5, 1.5, 1.5, 0.30);
1399
if (!glIsEnabled(GL_NORMALIZE)) glEnable(GL_NORMALIZE);
1400
glTranslatef(0.75, 1.875, -0.55);
1050
1401
HoledRectangle(1.5, 0.75, 0.25, 0.2, 8);
1051
1402
glMaterialfv(GL_FRONT, GL_SPECULAR, nospec);
1052
1403
glTranslatef(-0.375, -1.875, 0);
1057
1408
glTranslatef(0, 0.375, 0);
1410
} else { /* SMC transistor */
1412
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col);
1413
glTranslatef(-0.5, -0.25, 0.1);
1414
Rect(0, 0, 0, 1, 0.5, 0.2);
1415
/* Draw the markings */
1416
glEnable(GL_TEXTURE_2D);
1417
if (t->tnum) glBindTexture(GL_TEXTURE_2D, t->tnum);
1419
glDepthMask(GL_FALSE);
1421
glNormal3f(0, 0, 1);
1423
glVertex3f(0.2, 0, 0.01);
1425
glVertex3f(0.8, 0, 0.01);
1427
glVertex3f(0.8, 0.5, 0.01);
1429
glVertex3f(0.2, 0.5, 0.01);
1431
glDisable(GL_TEXTURE_2D);
1432
glDisable(GL_BLEND);
1433
glDepthMask(GL_TRUE);
1434
/* Now draw the legs */
1435
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col);
1436
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
1437
glMaterialfv(GL_FRONT, GL_SHININESS, &shin);
1438
Rect(0.25, -0.1, -0.05, 0.1, 0.1, 0.2);
1439
Rect(0.75, -0.1, -0.05, 0.1, 0.1, 0.2);
1440
Rect(0.5, 0.5, -0.05, 0.1, 0.1, 0.2);
1441
Rect(0.25, -0.2, -0.2, 0.1, 0.15, 0.1);
1442
Rect(0.75, -0.2, -0.2, 0.1, 0.15, 0.1);
1443
Rect(0.5, 0.5, -0.2, 0.1, 0.15, 0.1);
1063
Component * NewComponent(void) {
1448
Component * NewComponent(void)
1067
1453
c = malloc(sizeof(Component));
1068
1454
c->angle = RAND_RANGE(0,360);
1152
Transistor *NewTransistor(void) {
1550
Transistor *NewTransistor(void)
1553
float texfg[] = {0.7, 0.7, 0.7, 1.0};
1554
float texbg[] = {0.3, 0.3, 0.3, 0.1};
1155
1558
t = malloc(sizeof(Transistor));
1156
t->type = (f_rand() < 0.5);
1559
t->type = (random() % 3);
1561
val = transistortypes[random() % countof(transistortypes)];
1562
tn = fonttexturealloc(val, texfg, texbg);
1564
fprintf(stderr, "Error getting a texture for a string!\n");
1568
t->tw = tn->w; t->th = tn->h;
1571
} else if (t->type == 2) {
1572
val = smctypes[random() % countof(smctypes)];
1573
tn = fonttexturealloc(val, texfg, texbg);
1575
fprintf(stderr, "Error getting a texture for a string!\n");
1579
t->tw = tn->w; t->th = tn->h;
1582
} else if (t->type == 1) {
1583
val = to92types[random() % countof(to92types)];
1584
tn = fonttexturealloc(val, texfg, texbg);
1586
fprintf(stderr, "Error getting a texture for a string!\n");
1590
t->tw = tn->w; t->th = tn->h;
1160
Capacitor *NewCapacitor(void) {
1598
Capacitor *NewCapacitor(void)
1163
1602
c = malloc(sizeof(Capacitor));
1164
1603
c->type = (f_rand() < 0.5);
1331
void drawgrid(void) {
1333
static GLfloat col[] = {0, 0.25, 0.05};
1334
static GLfloat col2[] = {0, 0.125, 0.05};
1335
GLfloat col3[] = {0, 0.8, 0};
1336
static GLfloat sx, sy; /* bright spot co-ords */
1337
static int sdir; /* 0 = left-right, 1 = right-left, 2 = up->dn, 3 = dn->up */
1338
static int s = 0; /* if spot is enabled */
1339
static float ds; /* speed of spot */
1834
static GLfloat col[] = {0, 0.25, 0.05};
1835
static GLfloat col2[] = {0, 0.125, 0.05};
1836
GLfloat col3[] = {0, 0.8, 0};
1837
static GLfloat sx, sy; /* bright spot co-ords */
1838
static int sdir; /* 0 = left-right, 1 = right-left, 2 = up->dn, 3 = dn->up */
1839
static int s = 0; /* if spot is enabled */
1840
static float ds; /* speed of spot */
1342
1843
if (f_rand() < ((rotate) ? 0.05 : 0.01)) {
1997
void freetexture (GLuint texture) {
1999
if (s_refs[texture] < 1) {
2000
glDeleteTextures(1, &texture);
2004
TexNum * fonttexturealloc (const char *str, float *fg, float *bg)
2006
static char *strings[50]; /* max of 40 textures */
2007
static int w[50], h[50];
2015
for (i = 0 ; i < 50 ; i++) {
2022
for (i = 0 ; i < 50 ; i++) {
2023
if (!s_refs[i] && strings[i]) {
2027
if (strings[i] && !strcmp(str, strings[i])) { /* if one matches */
2028
t = malloc(sizeof(TexNum));
2029
t->w = w[i]; t->h = h[i];
2035
/* at this point we need to make the new texture */
2036
ximage = text_to_ximage (modeinfo->xgwa.screen,
2037
modeinfo->xgwa.visual,
2040
for (i = 0 ; strings[i] != NULL ; i++) { /* set i to the next unused value */
2042
fprintf(stderr, "Texture cache full!\n");
2049
glBindTexture(GL_TEXTURE_2D, i);
2050
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2051
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2052
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2055
status = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, ximage->width, ximage->height,
2056
GL_RGBA, GL_UNSIGNED_BYTE, ximage->data);
2059
const char *s = (char *) gluErrorString (status);
2060
fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n",
2061
progname, ximage->width, ximage->height,
2062
(s ? s : "(unknown)"));
2065
check_gl_error("mipmapping");
2067
t = malloc(sizeof(TexNum));
2068
t->w = ximage->width;
2069
t->h = ximage->height;
2070
w[i] = t->w; h[i] = t->h;
2074
c = malloc(strlen(str)+1);
2075
strncpy(c, str, strlen(str)+1);
1495
2082
/* ensure transparent components are at the end */
1496
void reorder(Component *c[]) {
1498
Component *c1[MAX_COMPONENTS];
1499
Component *c2[MAX_COMPONENTS];
2083
void reorder(Component *c[])
2086
Component *c1[MAX_COMPONENTS];
2087
Component *c2[MAX_COMPONENTS];
1502
2090
for (i = 0 ; i < maxparts ; i++) { /* clear old matrix */