629
639
initialize_gl(ModeInfo *mi, GLsizei width, GLsizei height)
631
mirrorblobstruct *gp = &Mirrorblob[MI_SCREEN(mi)];
641
mirrorblobstruct *gp = &Mirrorblob[MI_SCREEN(mi)];
633
/* Lighting values */
634
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
636
GLfloat lightPos0[] = {500.0f, 100.0f, 200.0f, 1.0f };
637
GLfloat whiteLight0[] = { 0.0f, 0.0f, 0.0f, 1.0f };
638
GLfloat sourceLight0[] = { 0.6f, 0.6f, 0.6f, 1.0f };
639
GLfloat specularLight0[] = { 0.8f, 0.8f, 0.9f, 1.0f };
641
GLfloat lightPos1[] = {0.0f, -500.0f, 500.0f, 1.0f };
642
GLfloat whiteLight1[] = { 0.0f, 0.0f, 0.0f, 1.0f };
643
GLfloat sourceLight1[] = { 0.6f, 0.6f, 0.6f, 1.0f };
644
GLfloat specularLight1[] = { 0.7f, 0.7f, 0.7f, 1.0f };
646
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
648
GLfloat fogColor[4] = { 0.4, 0.4, 0.5, 0.1 };
650
/* Set the internal parameters based on the configuration settings */
653
/* Set the viewport to the width and heigh of the window */
654
glViewport (0, 0, width, height );
643
/* Lighting values */
644
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
646
GLfloat lightPos0[] = {500.0f, 100.0f, 200.0f, 1.0f };
647
GLfloat whiteLight0[] = { 0.0f, 0.0f, 0.0f, 1.0f };
648
GLfloat sourceLight0[] = { 0.6f, 0.6f, 0.6f, 1.0f };
649
GLfloat specularLight0[] = { 0.8f, 0.8f, 0.9f, 1.0f };
651
GLfloat lightPos1[] = {-50.0f, -100.0f, 2500.0f, 1.0f };
652
GLfloat whiteLight1[] = { 0.0f, 0.0f, 0.0f, 1.0f };
653
GLfloat sourceLight1[] = { 0.6f, 0.6f, 0.6f, 1.0f };
654
GLfloat specularLight1[] = { 0.7f, 0.7f, 0.7f, 1.0f };
656
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
658
GLfloat fogColor[4] = { 0.4, 0.4, 0.5, 0.1 };
660
/* Set the internal parameters based on the configuration settings */
663
/* Set the viewport to the width and heigh of the window */
664
glViewport (0, 0, width, height );
659
glEnable(GL_LINE_SMOOTH);
660
glEnable(GL_POLYGON_SMOOTH);
669
glEnable(GL_LINE_SMOOTH);
670
glEnable(GL_POLYGON_SMOOTH);
663
/* The blend function is used for trasitioning between two images even when
664
* blend is not selected.
666
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
673
/* The blend function is used for trasitioning between two images even when
674
* blend is not selected.
676
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
671
glFogfv(GL_FOG_COLOR, fogColor);
672
glFogf(GL_FOG_DENSITY, 0.50);
673
glFogf(GL_FOG_START, 15.0);
674
glFogf(GL_FOG_END, 30.0);
677
/* Set the shading model to smooth (Gouraud shading). */
678
glShadeModel (GL_SMOOTH);
680
/* Set the clear color. */
681
glClearColor( 0, 0, 0, 0 );
683
glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambientLight);
684
glLightfv (GL_LIGHT0, GL_AMBIENT, whiteLight0);
685
glLightfv (GL_LIGHT0, GL_DIFFUSE, sourceLight0);
686
glLightfv (GL_LIGHT0, GL_SPECULAR, specularLight0);
687
glLightfv (GL_LIGHT0, GL_POSITION, lightPos0);
688
glEnable (GL_LIGHT0);
689
glLightfv (GL_LIGHT1, GL_AMBIENT, whiteLight1);
690
glLightfv (GL_LIGHT1, GL_DIFFUSE, sourceLight1);
691
glLightfv (GL_LIGHT1, GL_SPECULAR, specularLight1);
692
glLightfv (GL_LIGHT1, GL_POSITION, lightPos1);
693
glEnable (GL_LIGHT1);
694
glEnable (GL_LIGHTING);
696
/* Enable color tracking */
697
glEnable (GL_COLOR_MATERIAL);
699
/* Set Material properties to follow glColor values */
700
glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
702
/* Set all materials to have specular reflectivity */
703
glMaterialfv (GL_FRONT, GL_SPECULAR, specref);
704
glMateriali (GL_FRONT, GL_SHININESS, 32);
706
/* Let GL implementation scale normal vectors. */
707
glEnable (GL_NORMALIZE);
712
glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
713
glEnable (GL_TEXTURE_2D);
715
gp->current_texture = 0;
716
glGenTextures (NUM_TEXTURES, gp->textures);
717
grab_texture (mi, gp->current_texture);
721
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
723
glMatrixMode (GL_TEXTURE);
724
glRotated (180.0, 1.0, 0.0, 0.0);
725
glMatrixMode (GL_MODELVIEW);
730
glEnableClientState (GL_COLOR_ARRAY);
732
glEnableClientState (GL_NORMAL_ARRAY);
733
glEnableClientState (GL_VERTEX_ARRAY);
735
/* Clear the buffer since this is not done during a draw with motion blur */
736
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
681
glFogfv(GL_FOG_COLOR, fogColor);
682
glFogf(GL_FOG_DENSITY, 0.50);
683
glFogf(GL_FOG_START, 15.0);
684
glFogf(GL_FOG_END, 30.0);
687
/* Set the shading model to smooth (Gouraud shading). */
688
glShadeModel (GL_SMOOTH);
690
/* Set the clear color. */
691
glClearColor( 0, 0, 0, 0 );
693
glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambientLight);
694
glLightfv (GL_LIGHT0, GL_AMBIENT, whiteLight0);
695
glLightfv (GL_LIGHT0, GL_DIFFUSE, sourceLight0);
696
glLightfv (GL_LIGHT0, GL_SPECULAR, specularLight0);
697
glLightfv (GL_LIGHT0, GL_POSITION, lightPos0);
698
glEnable (GL_LIGHT0);
699
glLightfv (GL_LIGHT1, GL_AMBIENT, whiteLight1);
700
glLightfv (GL_LIGHT1, GL_DIFFUSE, sourceLight1);
701
glLightfv (GL_LIGHT1, GL_SPECULAR, specularLight1);
702
glLightfv (GL_LIGHT1, GL_POSITION, lightPos1);
703
glEnable (GL_LIGHT1);
704
glEnable (GL_LIGHTING);
706
/* Enable color tracking */
707
glEnable (GL_COLOR_MATERIAL);
709
/* Set Material properties to follow glColor values */
710
glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
712
/* Set all materials to have specular reflectivity */
713
glMaterialfv (GL_FRONT, GL_SPECULAR, specref);
714
glMateriali (GL_FRONT, GL_SHININESS, 32);
716
/* Let GL implementation scale normal vectors. */
717
glEnable (GL_NORMALIZE);
722
glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
723
glEnable (GL_TEXTURE_2D);
725
gp->current_texture = 0;
726
glGenTextures(NUM_TEXTURES, gp->textures);
727
grab_texture(mi, gp->current_texture);
729
glMatrixMode (GL_TEXTURE);
730
glRotated (180.0, 1.0, 0.0, 0.0);
731
glMatrixMode (GL_MODELVIEW);
734
/* Clear the buffer since this is not done during a draw with motion blur */
735
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
739
738
/******************************************************************************
806
805
int bump_array_size)
809
int i, u, v, node, side, face, base, base2 = 0;
810
int nodes_on_edge = resolution;
811
Vector3D node1, node2, result;
813
if (nodes_on_edge < 2)
816
gp->num_nodes = 2 * nodes_on_edge * nodes_on_edge - 4 * nodes_on_edge + 4;
817
gp->num_faces = 4 * (nodes_on_edge - 1) * (nodes_on_edge - 1);
819
gp->nodes = (Node_Data *) malloc (gp->num_nodes * sizeof (Node_Data));
822
fprintf (stderr, "Couldn't allocate gp->nodes buffer\n");
826
gp->faces = (Face_Data *) malloc (gp->num_faces * sizeof (Face_Data));
829
fprintf (stderr, "Couldn't allocate faces data buffer\n");
833
gp->bump_data = (Bump_Data *) malloc (bumps * sizeof (Bump_Data));
836
fprintf(stderr, "Couldn't allocate bump data buffer\n");
840
gp->bump_shape = (double *)malloc(bump_array_size * sizeof(double));
843
fprintf(stderr, "Couldn't allocate bump buffer\n");
847
gp->wall_shape = (double *)malloc(bump_array_size * sizeof(double));
850
fprintf(stderr, "Couldn't allocate wall bump buffer\n");
854
gp->dots = (Vector3D *)malloc(gp->num_nodes * sizeof(Vector3D));
857
fprintf(stderr, "Couldn't allocate nodes buffer\n");
860
glVertexPointer (3, GL_DOUBLE, 0, (GLvoid *) gp->dots);
862
gp->normals = (Vector3D *)malloc(gp->num_nodes * sizeof(Vector3D));
865
fprintf(stderr, "Couldn't allocate normals buffer\n");
868
glNormalPointer (GL_DOUBLE, 0, (GLvoid *) gp->normals);
872
gp->colours = (Colour *)malloc(gp->num_nodes * sizeof(Colour));
875
fprintf(stderr, "Couldn't allocate colours buffer\n");
878
glColorPointer (4, GL_UNSIGNED_BYTE, 0, (GLvoid *) gp->colours);
883
gp->tex_coords = (Vector2D *)malloc(gp->num_nodes * sizeof(Vector2D));
886
fprintf(stderr, "Couldn't allocate gp->tex_coords buffer\n");
889
glTexCoordPointer (2, GL_DOUBLE, 0, (GLvoid *) gp->tex_coords);
892
/* Initialise bump data */
893
for (i = 0; i < bumps; i++)
895
gp->bump_data[i].ax = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
896
gp->bump_data[i].ay = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
897
gp->bump_data[i].power = (5.0 / pow(bumps, 0.75)) * (((double)random() / (double)RAND_MAX) - 0.5);
898
gp->bump_data[i].size = 0.1 + 0.5 * (((double)random() / (double)RAND_MAX));
900
gp->bump_data[i].pos.x = 1.5 * sin(PI * gp->bump_data[i].ay)
901
* cos(PI * gp->bump_data[i].ax);
902
gp->bump_data[i].pos.y = 1.5 * cos(PI * gp->bump_data[i].ay);
903
gp->bump_data[i].pos.z = 1.5 * sin(PI * gp->bump_data[i].ay)
904
* sin(PI * gp->bump_data[i].ax);
906
gp->bump_data[i].cx = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
907
gp->bump_data[i].cy = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
908
gp->bump_data[i].cpower = (5.0 / pow(bumps, 0.75)) * (((double)random() / (double)RAND_MAX) - 0.5);
909
gp->bump_data[i].csize = 0.35; /*0.1 + 0.25 * (((double)random() / (double)RAND_MAX));*/
911
gp->bump_data[i].vx = 0.0;
912
gp->bump_data[i].vy = 0.0;
913
gp->bump_data[i].vpower = 0.0;
914
gp->bump_data[i].vsize = 0.0;
916
gp->bump_data[i].mx = 0.003 * ((double)random() / (double)RAND_MAX);
917
gp->bump_data[i].my = 0.003 * ((double)random() / (double)RAND_MAX);
918
gp->bump_data[i].mpower = 0.003 * ((double)random() / (double)RAND_MAX);
919
gp->bump_data[i].msize = 0.003 * ((double)random() / (double)RAND_MAX);
922
/* Initialise lookup table of bump strength */
923
for (i = 0; i < bump_array_size; i++)
926
xd = i / (double)bump_array_size;
928
xd2 = 48.0 * xd * xd;
929
gp->bump_shape[i] = 0.1 / (xd2 + 0.1);
931
xd2 = 40.0 * xd * xd * xd * xd;
932
gp->wall_shape[i] = 0.4 / (xd2 + 0.1);
937
for (side = 0; side < 4; side++)
945
* The start and end of the for loops below are modified based on the
946
* side of the tetrahedron that is being calculated to avoid duplication
947
* of the gp->nodes that are on the edges of the tetrahedron.
949
for (u = (side > 1); u < (nodes_on_edge - (side > 0)); u++)
951
node1 = partial (normalise (tetrahedron[side][0]),
952
normalise (tetrahedron[side][1]),
953
u / (double) (nodes_on_edge - 1));
954
node2 = partial (normalise (tetrahedron[side][0]),
955
normalise (tetrahedron[side][2]),
956
u / (double) (nodes_on_edge - 1));
958
for (v = (side > 1); v <= (u - (side > 2)); v++)
961
result = partial (node1, node2, v / (double) u);
808
int i, u, v, node, side, face, base, base2 = 0;
809
int nodes_on_edge = resolution;
810
Vector3D node1, node2, result;
812
if (nodes_on_edge < 2)
815
gp->num_nodes = 2 * nodes_on_edge * nodes_on_edge - 4 * nodes_on_edge + 4;
816
gp->num_faces = 4 * (nodes_on_edge - 1) * (nodes_on_edge - 1);
818
gp->nodes = (Node_Data *) malloc (gp->num_nodes * sizeof (Node_Data));
821
fprintf (stderr, "Couldn't allocate gp->nodes buffer\n");
825
gp->faces = (Face_Data *) malloc (gp->num_faces * sizeof (Face_Data));
828
fprintf (stderr, "Couldn't allocate faces data buffer\n");
832
gp->bump_data = (Bump_Data *) malloc (bumps * sizeof (Bump_Data));
835
fprintf(stderr, "Couldn't allocate bump data buffer\n");
839
gp->bump_shape = (double *)malloc(bump_array_size * sizeof(double));
842
fprintf(stderr, "Couldn't allocate bump buffer\n");
846
gp->wall_shape = (double *)malloc(bump_array_size * sizeof(double));
849
fprintf(stderr, "Couldn't allocate wall bump buffer\n");
854
gp->dots = (Vector3D *)malloc(gp->num_nodes * sizeof(Vector3D));
857
fprintf(stderr, "Couldn't allocate nodes buffer\n");
861
gp->normals = (Vector3D *)malloc(gp->num_nodes * sizeof(Vector3D));
864
fprintf(stderr, "Couldn't allocate normals buffer\n");
868
gp->colours = (Colour *)malloc(gp->num_nodes * sizeof(Colour));
871
fprintf(stderr, "Couldn't allocate colours buffer\n");
875
gp->tex_coords = (Vector2D *)malloc(gp->num_nodes * sizeof(Vector2D));
878
fprintf(stderr, "Couldn't allocate gp->tex_coords buffer\n");
883
/* Initialise bump data */
884
for (i = 0; i < bumps; i++)
886
gp->bump_data[i].ax = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
887
gp->bump_data[i].ay = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
888
gp->bump_data[i].power = (5.0 / pow(bumps, 0.75)) * (((double)random() / (double)RAND_MAX) - 0.5);
889
gp->bump_data[i].size = 0.1 + 0.5 * (((double)random() / (double)RAND_MAX));
891
gp->bump_data[i].pos.x = 1.5 * sin(PI * gp->bump_data[i].ay)
892
* cos(PI * gp->bump_data[i].ax);
893
gp->bump_data[i].pos.y = 1.5 * cos(PI * gp->bump_data[i].ay);
894
gp->bump_data[i].pos.z = 1.5 * sin(PI * gp->bump_data[i].ay)
895
* sin(PI * gp->bump_data[i].ax);
897
gp->bump_data[i].cx = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
898
gp->bump_data[i].cy = 2.0 * (((double)random() / (double)RAND_MAX) - 0.5);
899
gp->bump_data[i].cpower = (5.0 / pow(bumps, 0.75)) * (((double)random() / (double)RAND_MAX) - 0.5);
900
gp->bump_data[i].csize = 0.35; /*0.1 + 0.25 * (((double)random() / (double)RAND_MAX));*/
902
gp->bump_data[i].vx = 0.0;
903
gp->bump_data[i].vy = 0.0;
904
gp->bump_data[i].vpower = 0.0;
905
gp->bump_data[i].vsize = 0.0;
907
gp->bump_data[i].mx = 0.003 * ((double)random() / (double)RAND_MAX);
908
gp->bump_data[i].my = 0.003 * ((double)random() / (double)RAND_MAX);
909
gp->bump_data[i].mpower = 0.003 * ((double)random() / (double)RAND_MAX);
910
gp->bump_data[i].msize = 0.003 * ((double)random() / (double)RAND_MAX);
913
/* Initialise lookup table of bump strength */
914
for (i = 0; i < bump_array_size; i++)
917
xd = i / (double)bump_array_size;
919
xd2 = 48.0 * xd * xd;
920
gp->bump_shape[i] = 0.1 / (xd2 + 0.1);
922
xd2 = 40.0 * xd * xd * xd * xd;
923
gp->wall_shape[i] = 0.4 / (xd2 + 0.1);
928
for (side = 0; side < 4; side++)
936
* The start and end of the for loops below are modified based on the
937
* side of the tetrahedron that is being calculated to avoid duplication
938
* of the gp->nodes that are on the edges of the tetrahedron.
940
for (u = (side > 1); u < (nodes_on_edge - (side > 0)); u++)
942
node1 = partial (normalise (tetrahedron[side][0]),
943
normalise (tetrahedron[side][1]),
944
u / (double) (nodes_on_edge - 1));
945
node2 = partial (normalise (tetrahedron[side][0]),
946
normalise (tetrahedron[side][2]),
947
u / (double) (nodes_on_edge - 1));
949
for (v = (side > 1); v <= (u - (side > 2)); v++)
952
result = partial (node1, node2, v / (double) u);
956
gp->nodes[node].position = normalise (result);
957
gp->nodes[node].initial_position = gp->nodes[node].position;
958
gp->nodes[node].normal = zero_vector;
964
* Determine which nodes make up each face. The complexity is caused
965
* by having to determine the correct nodes for the edges of the
966
* tetrahedron since the common nodes on the edges are only calculated
969
for (u = 0; u < (nodes_on_edge - 1); u++)
971
for (v = 0; v <= u; v++)
976
gp->faces[face].node1 = base + ((u * (u + 1)) / 2) + v;
977
gp->faces[face].node2 =
978
base + ((u + 1) * (u + 2)) / 2 + v + 1;
979
gp->faces[face].node3 =
980
base + ((u + 1) * (u + 2)) / 2 + v;
982
if ((side == 1) && (u == (nodes_on_edge - 2)))
984
gp->faces[face].node3 =
985
((u + 1) * (u + 2)) / 2 +
986
nodes_on_edge - v - 1;
987
gp->faces[face].node2 =
988
((u + 1) * (u + 2)) / 2 +
989
nodes_on_edge - v - 2;
994
gp->faces[face].node1 =
995
base + (((u - 1) * u) / 2) + v - 1;
996
gp->faces[face].node2 = base + ((u) * (u + 1)) / 2 + v;
997
gp->faces[face].node3 =
998
base + ((u) * (u + 1)) / 2 + v - 1;
1000
if (u == (nodes_on_edge - 2))
1002
int n = nodes_on_edge - v - 1;
1003
gp->faces[face].node2 =
1005
(nodes_on_edge + 1)) / 2) +
1006
((n - 1) * (n + 0)) / 2;
1007
gp->faces[face].node3 =
1009
(nodes_on_edge + 1)) / 2) +
1010
((n + 0) * (n + 1)) / 2;
1014
gp->faces[face].node1 = (((u + 1) * (u + 2)) / 2) - 1;
1015
gp->faces[face].node3 = (((u + 2) * (u + 3)) / 2) - 1;
965
gp->nodes[node].position = normalise (result);
966
gp->nodes[node].initial_position = gp->nodes[node].position;
967
gp->nodes[node].normal = zero_vector;
973
* Determine which nodes make up each face. The complexity is caused
974
* by having to determine the correct nodes for the edges of the
975
* tetrahedron since the common nodes on the edges are only calculated
978
for (u = 0; u < (nodes_on_edge - 1); u++)
980
for (v = 0; v <= u; v++)
985
gp->faces[face].node1 = base + ((u * (u + 1)) / 2) + v;
986
gp->faces[face].node2 =
987
base + ((u + 1) * (u + 2)) / 2 + v + 1;
988
gp->faces[face].node3 =
989
base + ((u + 1) * (u + 2)) / 2 + v;
991
if ((side == 1) && (u == (nodes_on_edge - 2)))
993
gp->faces[face].node3 =
994
((u + 1) * (u + 2)) / 2 +
995
nodes_on_edge - v - 1;
996
gp->faces[face].node2 =
997
((u + 1) * (u + 2)) / 2 +
998
nodes_on_edge - v - 2;
1003
gp->faces[face].node1 =
1004
base + (((u - 1) * u) / 2) + v - 1;
1005
gp->faces[face].node2 = base + ((u) * (u + 1)) / 2 + v;
1006
gp->faces[face].node3 =
1007
base + ((u) * (u + 1)) / 2 + v - 1;
1009
if (u == (nodes_on_edge - 2))
1011
int n = nodes_on_edge - v - 1;
1012
gp->faces[face].node2 =
1014
(nodes_on_edge + 1)) / 2) +
1015
((n - 1) * (n + 0)) / 2;
1016
gp->faces[face].node3 =
1018
(nodes_on_edge + 1)) / 2) +
1019
((n + 0) * (n + 1)) / 2;
1023
gp->faces[face].node1 = (((u + 1) * (u + 2)) / 2) - 1;
1024
gp->faces[face].node3 = (((u + 2) * (u + 3)) / 2) - 1;
1029
gp->faces[face].node1 =
1030
base + (((u - 2) * (u - 1)) / 2) + v - 1;
1031
gp->faces[face].node2 = base + ((u - 1) * u) / 2 + v;
1032
gp->faces[face].node3 = base + ((u - 1) * u) / 2 + v - 1;
1036
gp->faces[face].node1 =
1037
base2 + ((u * (u + 1)) / 2) - 1;
1038
gp->faces[face].node3 =
1039
base2 + ((u + 1) * (u + 2)) / 2 - 1;
1041
if (u == (nodes_on_edge - 2))
1043
gp->faces[face].node3 =
1045
(nodes_on_edge + 1)) / 2) +
1046
((v + 1) * (v + 2)) / 2 - 1;
1047
gp->faces[face].node2 =
1049
(nodes_on_edge + 1)) / 2) +
1050
((v + 2) * (v + 3)) / 2 - 1;
1054
gp->faces[face].node1 = (u * (u + 1)) / 2;
1055
gp->faces[face].node2 = ((u + 1) * (u + 2)) / 2;
1065
gp->faces[face].node1 = base + ((u * (u + 1)) / 2) + v;
1066
gp->faces[face].node2 =
1067
base + ((u * (u + 1)) / 2) + v + 1;
1068
gp->faces[face].node3 =
1069
base + (((u + 1) * (u + 2)) / 2) + v + 1;
1071
if ((side == 1) && (u == (nodes_on_edge - 2)))
1073
gp->faces[face].node3 =
1074
((u + 1) * (u + 2)) / 2 +
1075
nodes_on_edge - v - 2;
1080
gp->faces[face].node1 =
1081
base + ((u * (u - 1)) / 2) + v - 1;
1082
gp->faces[face].node2 = base + ((u * (u - 1)) / 2) + v;
1083
gp->faces[face].node3 = base + ((u * (u + 1)) / 2) + v;
1085
if (u == (nodes_on_edge - 2))
1087
int n = nodes_on_edge - v - 1;
1088
gp->faces[face].node3 =
1090
(nodes_on_edge + 1)) / 2) +
1091
((n + 0) * (n - 1)) / 2;
1095
gp->faces[face].node1 = (((u + 1) * (u + 2)) / 2) - 1;
1100
gp->faces[face].node1 =
1101
base + (((u - 2) * (u - 1)) / 2) + v - 1;
1102
gp->faces[face].node2 =
1103
base + (((u - 2) * (u - 1)) / 2) + v;
1104
gp->faces[face].node3 = base + (((u - 1) * u) / 2) + v;
1108
gp->faces[face].node1 = base2 + (u * (u + 1)) / 2 - 1;
1110
if (u == (nodes_on_edge - 2))
1112
gp->faces[face].node3 =
1113
((nodes_on_edge * (nodes_on_edge + 1)) / 2) +
1114
((v + 2) * (v + 3)) / 2 - 1;
1118
gp->faces[face].node2 = (u * (u + 1)) / 2;
1020
gp->faces[face].node1 =
1021
base + (((u - 2) * (u - 1)) / 2) + v - 1;
1022
gp->faces[face].node2 = base + ((u - 1) * u) / 2 + v;
1023
gp->faces[face].node3 = base + ((u - 1) * u) / 2 + v - 1;
1027
gp->faces[face].node1 =
1028
base2 + ((u * (u + 1)) / 2) - 1;
1029
gp->faces[face].node3 =
1030
base2 + ((u + 1) * (u + 2)) / 2 - 1;
1032
if (u == (nodes_on_edge - 2))
1034
gp->faces[face].node3 =
1036
(nodes_on_edge + 1)) / 2) +
1037
((v + 1) * (v + 2)) / 2 - 1;
1038
gp->faces[face].node2 =
1040
(nodes_on_edge + 1)) / 2) +
1041
((v + 2) * (v + 3)) / 2 - 1;
1045
gp->faces[face].node1 = (u * (u + 1)) / 2;
1046
gp->faces[face].node2 = ((u + 1) * (u + 2)) / 2;
1056
gp->faces[face].node1 = base + ((u * (u + 1)) / 2) + v;
1057
gp->faces[face].node2 =
1058
base + ((u * (u + 1)) / 2) + v + 1;
1059
gp->faces[face].node3 =
1060
base + (((u + 1) * (u + 2)) / 2) + v + 1;
1062
if ((side == 1) && (u == (nodes_on_edge - 2)))
1064
gp->faces[face].node3 =
1065
((u + 1) * (u + 2)) / 2 +
1066
nodes_on_edge - v - 2;
1071
gp->faces[face].node1 =
1072
base + ((u * (u - 1)) / 2) + v - 1;
1073
gp->faces[face].node2 = base + ((u * (u - 1)) / 2) + v;
1074
gp->faces[face].node3 = base + ((u * (u + 1)) / 2) + v;
1076
if (u == (nodes_on_edge - 2))
1078
int n = nodes_on_edge - v - 1;
1079
gp->faces[face].node3 =
1081
(nodes_on_edge + 1)) / 2) +
1082
((n + 0) * (n - 1)) / 2;
1086
gp->faces[face].node1 = (((u + 1) * (u + 2)) / 2) - 1;
1091
gp->faces[face].node1 =
1092
base + (((u - 2) * (u - 1)) / 2) + v - 1;
1093
gp->faces[face].node2 =
1094
base + (((u - 2) * (u - 1)) / 2) + v;
1095
gp->faces[face].node3 = base + (((u - 1) * u) / 2) + v;
1099
gp->faces[face].node1 = base2 + (u * (u + 1)) / 2 - 1;
1101
if (u == (nodes_on_edge - 2))
1103
gp->faces[face].node3 =
1104
((nodes_on_edge * (nodes_on_edge + 1)) / 2) +
1105
((v + 2) * (v + 3)) / 2 - 1;
1109
gp->faces[face].node2 = (u * (u + 1)) / 2;
1130
1121
/******************************************************************************
1152
/* Loop variables */
1154
/* position of a node */
1157
Vector3D bump_vector;
1160
/* Update position and strength of bumps used to distort the blob */
1161
for (i = 0; i < bumps; i++)
1163
gp->bump_data[i].vx += gp->bump_data[i].mx*(gp->bump_data[i].cx - gp->bump_data[i].ax);
1164
gp->bump_data[i].vy += gp->bump_data[i].my*(gp->bump_data[i].cy - gp->bump_data[i].ay);
1165
gp->bump_data[i].vpower += gp->bump_data[i].mpower
1166
* (gp->bump_data[i].cpower - gp->bump_data[i].power);
1167
gp->bump_data[i].vsize += gp->bump_data[i].msize
1168
* (gp->bump_data[i].csize - gp->bump_data[i].size);
1170
gp->bump_data[i].ax += 0.1 * gp->bump_data[i].vx;
1171
gp->bump_data[i].ay += 0.1 * gp->bump_data[i].vy;
1172
gp->bump_data[i].power += 0.1 * gp->bump_data[i].vpower;
1173
gp->bump_data[i].size += 0.1 * gp->bump_data[i].vsize;
1175
gp->bump_data[i].pos.x = 1.0 * sin(PI * gp->bump_data[i].ay)
1176
* cos(PI * gp->bump_data[i].ax);
1177
gp->bump_data[i].pos.y = 1.0 * cos(PI * gp->bump_data[i].ay);
1178
gp->bump_data[i].pos.z = 1.0 * sin(PI * gp->bump_data[i].ay)
1179
* sin(PI * gp->bump_data[i].ax);
1182
/* Update calculate new position for each vertex based on an offset from
1183
* the initial position
1185
gp->blob_force = zero_vector;
1186
for (index = 0; index < gp->num_nodes; ++index)
1188
node = gp->nodes[index].initial_position;
1189
gp->nodes[index].normal = zero_vector;
1191
offset = zero_vector;
1192
for ( i = 0; i < bumps; i++)
1194
bump_vector = subtract(gp->bump_data[i].pos, node);
1196
dist = bump_array_size * dot(bump_vector, bump_vector) * gp->bump_data[i].size;
1198
if (dist < bump_array_size)
1200
add(&offset, scale(node, gp->bump_data[i].power * gp->bump_shape[dist]));
1201
add(&gp->blob_force, scale(node, gp->bump_data[i].power * gp->bump_shape[dist]));
1206
node = scale(node, zoom);
1207
add(&node, gp->blob_center);
1211
if (node.z < -limit) node.z = -limit;
1212
if (node.z > limit) node.z = limit;
1214
dist = bump_array_size * (node.z + limit) * (node.z + limit) * 0.5;
1215
if (dist < bump_array_size)
1217
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1218
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1219
gp->blob_force.z += (node.z + limit);
1223
dist = bump_array_size * (node.z - limit) * (node.z - limit) * 0.5;
1224
if (dist < bump_array_size)
1226
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1227
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1228
gp->blob_force.z -= (node.z - limit);
1231
if (node.y < -limit) node.y = -limit;
1232
if (node.y > limit) node.y = limit;
1234
dist = bump_array_size * (node.y + limit) * (node.y + limit) * 0.5;
1235
if (dist < bump_array_size)
1237
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1238
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1239
gp->blob_force.y += (node.y + limit);
1243
dist = bump_array_size * (node.y - limit) * (node.y - limit) * 0.5;
1244
if (dist < bump_array_size)
1246
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1247
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1248
gp->blob_force.y -= (node.y - limit);
1252
if (node.x < -limit) node.x = -limit;
1253
if (node.x > limit) node.x = limit;
1255
dist = bump_array_size * (node.x + limit) * (node.x + limit) * 0.5;
1256
if (dist < bump_array_size)
1258
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1259
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1260
gp->blob_force.x += (node.x + limit);
1264
dist = bump_array_size * (node.x - limit) * (node.x - limit) * 0.5;
1265
if (dist < bump_array_size)
1267
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1268
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1269
gp->blob_force.x -= (node.x - limit);
1273
if (node.y < -limit) node.y = -limit;
1274
if (node.y > limit) node.y = limit;
1277
gp->dots[index] = node;
1280
/* Determine the normal for each face */
1281
for (face = 0; face < gp->num_faces; face++)
1283
/* Use nodeers to indexed nodes to help readability */
1284
Node_Data *node1 = &gp->nodes[gp->faces[face].node1];
1285
Node_Data *node2 = &gp->nodes[gp->faces[face].node2];
1286
Node_Data *node3 = &gp->nodes[gp->faces[face].node3];
1288
gp->faces[face].normal = cross(subtract(node2->position, node1->position),
1289
subtract(node3->position, node1->position));
1143
/* Loop variables */
1145
/* position of a node */
1148
Vector3D bump_vector;
1151
/* Update position and strength of bumps used to distort the blob */
1152
for (i = 0; i < bumps; i++)
1154
gp->bump_data[i].vx += gp->bump_data[i].mx*(gp->bump_data[i].cx - gp->bump_data[i].ax);
1155
gp->bump_data[i].vy += gp->bump_data[i].my*(gp->bump_data[i].cy - gp->bump_data[i].ay);
1156
gp->bump_data[i].vpower += gp->bump_data[i].mpower
1157
* (gp->bump_data[i].cpower - gp->bump_data[i].power);
1158
gp->bump_data[i].vsize += gp->bump_data[i].msize
1159
* (gp->bump_data[i].csize - gp->bump_data[i].size);
1161
gp->bump_data[i].ax += 0.1 * gp->bump_data[i].vx;
1162
gp->bump_data[i].ay += 0.1 * gp->bump_data[i].vy;
1163
gp->bump_data[i].power += 0.1 * gp->bump_data[i].vpower;
1164
gp->bump_data[i].size += 0.1 * gp->bump_data[i].vsize;
1166
gp->bump_data[i].pos.x = 1.0 * sin(PI * gp->bump_data[i].ay)
1167
* cos(PI * gp->bump_data[i].ax);
1168
gp->bump_data[i].pos.y = 1.0 * cos(PI * gp->bump_data[i].ay);
1169
gp->bump_data[i].pos.z = 1.0 * sin(PI * gp->bump_data[i].ay)
1170
* sin(PI * gp->bump_data[i].ax);
1173
/* Update calculate new position for each vertex based on an offset from
1174
* the initial position
1176
gp->blob_force = zero_vector;
1177
for (index = 0; index < gp->num_nodes; ++index)
1179
node = gp->nodes[index].initial_position;
1180
gp->nodes[index].normal = node;
1182
offset = zero_vector;
1183
for ( i = 0; i < bumps; i++)
1185
bump_vector = subtract(gp->bump_data[i].pos, node);
1187
dist = bump_array_size * dot(bump_vector, bump_vector) * gp->bump_data[i].size;
1189
if (dist < bump_array_size)
1191
add(&offset, scale(node, gp->bump_data[i].power * gp->bump_shape[dist]));
1192
add(&gp->blob_force, scale(node, gp->bump_data[i].power * gp->bump_shape[dist]));
1197
node = scale(node, zoom);
1198
add(&node, gp->blob_center);
1202
if (node.z < -limit) node.z = -limit;
1203
if (node.z > limit) node.z = limit;
1205
dist = bump_array_size * (node.z + limit) * (node.z + limit) * 0.5;
1206
if (dist < bump_array_size)
1208
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1209
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1210
gp->blob_force.z += (node.z + limit);
1214
dist = bump_array_size * (node.z - limit) * (node.z - limit) * 0.5;
1215
if (dist < bump_array_size)
1217
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1218
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1219
gp->blob_force.z -= (node.z - limit);
1222
if (node.y < -limit) node.y = -limit;
1223
if (node.y > limit) node.y = limit;
1225
dist = bump_array_size * (node.y + limit) * (node.y + limit) * 0.5;
1226
if (dist < bump_array_size)
1228
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1229
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1230
gp->blob_force.y += (node.y + limit);
1234
dist = bump_array_size * (node.y - limit) * (node.y - limit) * 0.5;
1235
if (dist < bump_array_size)
1237
node.x += (node.x - gp->blob_center.x) * gp->wall_shape[dist];
1238
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1239
gp->blob_force.y -= (node.y - limit);
1243
if (node.x < -limit) node.x = -limit;
1244
if (node.x > limit) node.x = limit;
1246
dist = bump_array_size * (node.x + limit) * (node.x + limit) * 0.5;
1247
if (dist < bump_array_size)
1249
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1250
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1251
gp->blob_force.x += (node.x + limit);
1255
dist = bump_array_size * (node.x - limit) * (node.x - limit) * 0.5;
1256
if (dist < bump_array_size)
1258
node.y += (node.y - gp->blob_center.y) * gp->wall_shape[dist];
1259
node.z += (node.z - gp->blob_center.z) * gp->wall_shape[dist];
1260
gp->blob_force.x -= (node.x - limit);
1264
if (node.y < -limit) node.y = -limit;
1265
if (node.y > limit) node.y = limit;
1268
gp->dots[index] = node;
1271
/* Determine the normal for each face */
1272
for (face = 0; face < gp->num_faces; face++)
1274
/* Use pointers to indexed nodes to help readability */
1275
int index1 = gp->faces[face].node1;
1276
int index2 = gp->faces[face].node2;
1277
int index3 = gp->faces[face].node3;
1279
gp->faces[face].normal = cross(subtract(gp->dots[index2], gp->dots[index1]),
1280
subtract(gp->dots[index3], gp->dots[index1]));
1291
/* Add the normal for the face onto the normal for the verticies of
1293
add(&node1->normal, gp->faces[face].normal);
1294
add(&node2->normal, gp->faces[face].normal);
1295
add(&node3->normal, gp->faces[face].normal);
1282
/* Add the normal for the face onto the normal for the verticies of
1284
add(&gp->nodes[index1].normal, gp->faces[face].normal);
1285
add(&gp->nodes[index2].normal, gp->faces[face].normal);
1286
add(&gp->nodes[index3].normal, gp->faces[face].normal);
1298
/* Use the normal to set the colour and texture */
1299
if (do_colour || do_texture)
1289
/* Use the normal to set the colour and texture */
1290
if (do_colour || do_texture)
1301
for (index = 0; index < gp->num_nodes; ++index)
1292
for (index = 0; index < gp->num_nodes; ++index)
1303
gp->normals[index] = normalise(gp->nodes[index].normal);
1294
gp->normals[index] = normalise(gp->nodes[index].normal);
1307
gp->colours[index].red = (int)(255.0 * fabs(gp->normals[index].x));
1308
gp->colours[index].green = (int)(255.0 * fabs(gp->normals[index].y));
1309
gp->colours[index].blue = (int)(255.0 * fabs(gp->normals[index].z));
1310
gp->colours[index].alpha = (int)(255.0 * fade);
1298
gp->colours[index].red = (int)(255.0 * fabs(gp->normals[index].x));
1299
gp->colours[index].green = (int)(255.0 * fabs(gp->normals[index].y));
1300
gp->colours[index].blue = (int)(255.0 * fabs(gp->normals[index].z));
1301
gp->colours[index].alpha = (int)(255.0 * fade);
1316
gp->tex_coords[index].x = gp->dots[index].x * 0.125 + 0.5
1317
* (1.0 + 0.25 * asin(gp->normals[index].x) / (0.5 * PI));
1318
gp->tex_coords[index].y = -gp->dots[index].y * 0.125 - 0.5
1319
* (1.0 + 0.25 * asin(gp->normals[index].y) / (0.5 * PI));
1323
gp->tex_coords[index].x = 0.5
1324
* (1.0 + asin(gp->normals[index].x) / (0.5 * PI));
1325
gp->tex_coords[index].y = -0.5
1326
* (1.0 + asin(gp->normals[index].y) / (0.5 * PI));
1328
/* Adjust the texture co-ordinates to from range 0..1 to
1329
* 0..width or 0..height as appropriate
1331
gp->tex_coords[index].x *= gp->tex_width[gp->current_texture];
1332
gp->tex_coords[index].y *= gp->tex_height[gp->current_texture];
1307
const float cube_size = 100.0;
1308
Vector3D eye = {0.0, 0.0, 50.0};
1309
Vector3D eye_r = normalise(subtract(gp->dots[index], eye));
1310
Vector3D reference = subtract(eye_r, scale(gp->normals[index], 2.0 * dot(eye_r, gp->normals[index])));
1313
double n, n_min = 10000.0, sign = 1.0;
1314
if (fabs(reference.z) > 1e-9)
1316
n = (cube_size - gp->dots[index].z) / reference.z;
1319
n = (-cube_size - gp->dots[index].z) / reference.z;
1324
x = sign * (gp->dots[index].x + n * reference.x);
1325
y = sign * (gp->dots[index].y + n * reference.y);
1329
if (fabs(reference.x) > 1e-9)
1331
n = (cube_size - gp->dots[index].x) / reference.x;
1335
n = (-cube_size - gp->dots[index].x) / reference.x;
1338
if ((n > 0.0) && (n < n_min))
1340
x = sign * (2.0 * cube_size - (gp->dots[index].z + n * reference.z));
1341
y = sign * x * (gp->dots[index].y + n * reference.y) / cube_size;
1345
if (fabs(reference.y) > 1e-9)
1347
n = (cube_size - gp->dots[index].y) / reference.y;
1351
n = (-cube_size - gp->dots[index].y) / reference.y;
1354
if ((n > 0.0) && (n < n_min))
1356
y = sign * (2.0 * cube_size -( gp->dots[index].z + n * reference.z));
1357
x = sign * y * (gp->dots[index].x + n * reference.x) / cube_size;
1361
gp->tex_coords[index].x = 0.5 + x / (cube_size * 6.0);
1362
gp->tex_coords[index].y = 0.5 - y / (cube_size * 6.0);
1366
gp->tex_coords[index].x = 0.5
1367
* (1.0 + asin(gp->normals[index].x) / (0.5 * PI));
1368
gp->tex_coords[index].y = -0.5
1369
* (1.0 + asin(gp->normals[index].y) / (0.5 * PI));
1371
/* Adjust the texture co-ordinates to from range 0..1 to
1372
* 0..width or 0..height as appropriate
1374
gp->tex_coords[index].x *= gp->tex_width[gp->current_texture];
1375
gp->tex_coords[index].y *= gp->tex_height[gp->current_texture];
1337
/* Update the center of the whole blob */
1338
add(&gp->blob_velocity, scale (subtract (gp->blob_anchor, gp->blob_center), 1.0 / 80.0));
1339
add(&gp->blob_velocity, scale (gp->blob_force, 0.01 / gp->num_nodes));
1341
add(&gp->blob_center, scale(gp->blob_velocity, 0.5));
1343
gp->blob_velocity = scale(gp->blob_velocity, 0.999);
1380
/* Update the center of the whole blob */
1381
add(&gp->blob_velocity, scale (subtract (gp->blob_anchor, gp->blob_center), 1.0 / 80.0));
1382
add(&gp->blob_velocity, scale (gp->blob_force, 0.01 / gp->num_nodes));
1384
add(&gp->blob_center, scale(gp->blob_velocity, 0.5));
1386
gp->blob_velocity = scale(gp->blob_velocity, 0.999);
1390
draw_vertex(mirrorblobstruct *gp, int index)
1394
glColor3ub(gp->colours[index].red,
1395
gp->colours[index].green,
1396
gp->colours[index].blue);
1400
glTexCoord3dv((GLdouble *) &gp->tex_coords[index]);
1402
glNormal3dv((GLdouble *) &gp->normals[index]);
1403
glVertex3dv((GLdouble *) &gp->dots[index]);
1346
1406
/******************************************************************************
1424
1500
draw_scene(ModeInfo * mi)
1426
mirrorblobstruct *gp = &Mirrorblob[MI_SCREEN(mi)];
1502
mirrorblobstruct *gp = &Mirrorblob[MI_SCREEN(mi)];
1429
double current_time;
1430
check_gl_error ("draw_scene");
1432
mi->polygon_count = 0;
1433
glColor4d(1.0, 1.0, 1.0, 1.0);
1435
current_time = double_time();
1505
double current_time;
1506
check_gl_error ("draw_scene");
1508
mi->polygon_count = 0;
1509
glColor4d(1.0, 1.0, 1.0, 1.0);
1511
current_time = double_time();
1515
glColor4d(0.0, 0.0, 0.0, 1.0);
1438
1519
case TRANSITIONING:
1439
fade = 1.0 - (current_time - gp->state_start_time) / fade_time;
1520
fade = 1.0 - (current_time - gp->state_start_time) / fade_time;
1442
1523
case LOADING: /* FALL-THROUGH */
1448
/* Set the correct texture, when transitioning this ensures that the first draw
1449
* is the original texture (which has the new texture drawn over it with decreasing
1454
glBindTexture (GL_TEXTURE_2D, gp->textures[gp->current_texture]);
1457
glDisable (GL_DEPTH_TEST);
1458
if (do_paint_background)
1460
glEnable (GL_TEXTURE_2D);
1461
if (motion_blur > 0.0)
1463
glClear(GL_DEPTH_BUFFER_BIT);
1464
glEnable (GL_BLEND);
1465
glColor4d (1.0, 1.0, 1.0, motion_blur);
1469
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1471
draw_background (mi);
1472
mi->polygon_count++;
1474
/* When transitioning between two images paint the new image over the old
1475
* image with a varying alpha value to get a smooth fade.
1477
if (gp->state == TRANSITIONING)
1479
glEnable (GL_BLEND);
1480
/* Select the texture to transition to */
1481
glBindTexture (GL_TEXTURE_2D, gp->textures[1 - gp->current_texture]);
1482
glColor4d (1.0, 1.0, 1.0, 1.0 - fade);
1484
draw_background (mi);
1485
mi->polygon_count++;
1487
/* Select the original texture to draw the blob */
1488
glBindTexture (GL_TEXTURE_2D, gp->textures[gp->current_texture]);
1490
/* Clear the depth buffer bit so the backgound is behind the blob */
1491
glClear(GL_DEPTH_BUFFER_BIT);
1493
else if (motion_blur > 0.0)
1495
glEnable (GL_BLEND);
1496
glColor4d (0.0, 0.0, 0.0, motion_blur);
1497
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1498
glTranslatef (0.0, 0.0, -4.0);
1499
glRectd (-10.0, -10.0, 10.0, 10.0);
1502
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1504
glClear (GL_DEPTH_BUFFER_BIT);
1508
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1514
glDisable (GL_TEXTURE_2D);
1517
calc_blob(gp, MI_WIDTH(mi), MI_HEIGHT(mi), BUMP_ARRAY_SIZE, 2.5, fade * blend);
1519
set_blob_gl_state(fade * blend);
1523
/* Disable the three colour chanels so that only the depth buffer is updated */
1524
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1526
mi->polygon_count += gp->num_faces;
1527
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1528
glDepthFunc(GL_LEQUAL);
1530
glDepthFunc(GL_LEQUAL);
1532
mi->polygon_count += gp->num_faces;
1534
/* While transitioning between images draw a second blob with a modified
1537
if (load_textures && (hold_time > 0))
1529
/* Set the correct texture, when transitioning this ensures that the first draw
1530
* is the original texture (which has the new texture drawn over it with decreasing
1535
glBindTexture(GL_TEXTURE_2D, gp->textures[gp->current_texture]);
1538
glDisable (GL_DEPTH_TEST);
1539
if (do_paint_background)
1541
glEnable (GL_TEXTURE_2D);
1542
if (motion_blur > 0.0)
1544
glClear(GL_DEPTH_BUFFER_BIT);
1545
glEnable (GL_BLEND);
1546
glColor4d (1.0, 1.0, 1.0, motion_blur);
1550
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1552
draw_background (mi);
1553
mi->polygon_count++;
1555
/* When transitioning between two images paint the new image over the old
1556
* image with a varying alpha value to get a smooth fade.
1558
if (gp->state == TRANSITIONING)
1560
glEnable (GL_BLEND);
1561
/* Select the texture to transition to */
1562
glBindTexture (GL_TEXTURE_2D, gp->textures[1 - gp->current_texture]);
1563
glColor4d (1.0, 1.0, 1.0, 1.0 - fade);
1565
draw_background (mi);
1566
mi->polygon_count++;
1568
/* Select the original texture to draw the blob */
1569
glBindTexture (GL_TEXTURE_2D, gp->textures[gp->current_texture]);
1571
/* Clear the depth buffer bit so the backgound is behind the blob */
1572
glClear(GL_DEPTH_BUFFER_BIT);
1574
else if (motion_blur > 0.0)
1576
glEnable (GL_BLEND);
1577
glColor4d (0.0, 0.0, 0.0, motion_blur);
1578
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1579
glTranslatef (0.0, 0.0, -4.0);
1580
glRectd (-10.0, -10.0, 10.0, 10.0);
1583
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1585
glClear(GL_DEPTH_BUFFER_BIT);
1589
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1595
glDisable (GL_TEXTURE_2D);
1598
calc_blob(gp, MI_WIDTH(mi), MI_HEIGHT(mi), BUMP_ARRAY_SIZE, 2.5, fade * blend);
1600
set_blob_gl_state(fade * blend);
1604
/* Disable the colour chanels so that only the depth buffer is updated */
1605
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1607
mi->polygon_count += gp->num_faces;
1608
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1611
glDepthFunc(GL_LEQUAL);
1613
mi->polygon_count += gp->num_faces;
1615
/* While transitioning between images draw a second blob with a modified
1618
if (load_textures && (hold_time > 0))
1623
if (!gp->waiting_for_image_p)
1625
gp->state = HOLDING;
1542
if ((current_time - gp->state_start_time) > hold_time)
1630
if ((current_time - gp->state_start_time) > hold_time)
1544
grab_texture(mi, 1 - gp->current_texture);
1545
gp->state = LOADING;
1632
grab_texture(mi, 1 - gp->current_texture);
1633
gp->state = LOADING;
1550
/* Once the image has loaded move to the TRANSITIONING STATE */
1551
if (!gp->waiting_for_image_p)
1638
/* Once the image has loaded move to the TRANSITIONING STATE */
1639
if (!gp->waiting_for_image_p)
1553
gp->state = TRANSITIONING;
1554
/* Get the time again rather than using the current time so
1555
* that the time taken by the grab_texture function is not part
1558
gp->state_start_time = double_time();
1641
gp->state = TRANSITIONING;
1642
/* Get the time again rather than using the current time so
1643
* that the time taken by the grab_texture function is not part
1646
gp->state_start_time = double_time();
1562
1650
case TRANSITIONING:
1564
/* If the blob is textured draw over existing blob to fade between
1652
/* If the blob is textured draw over existing blob to fade between
1569
/* Select the texture to transition to */
1570
glBindTexture (GL_TEXTURE_2D, gp->textures[1 - gp->current_texture]);
1571
glEnable (GL_BLEND);
1657
/* Select the texture to transition to */
1658
glBindTexture (GL_TEXTURE_2D, gp->textures[1 - gp->current_texture]);
1659
glEnable (GL_BLEND);
1573
/* If colour is enabled update the alpha data in the buffer and
1574
* use that in the blending since the alpha of the incomming
1575
* verticies will not be correct
1579
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
1580
glClearColor(0.0, 0.0, 0.0, (1.0 - fade) * blend);
1581
glClear(GL_COLOR_BUFFER_BIT);
1582
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1583
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
1587
glColor4d(0.9, 0.9, 1.0, (1.0 - fade) * blend);
1591
mi->polygon_count += gp->num_faces;
1595
/* Restore the 'standard' blend functions. */
1596
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1661
/* If colour is enabled update the alpha data in the buffer and
1662
* use that in the blending since the alpha of the incomming
1663
* verticies will not be correct
1667
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
1668
glClearColor(0.0, 0.0, 0.0, (1.0 - fade) * blend);
1669
glClear(GL_COLOR_BUFFER_BIT);
1670
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1671
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
1675
glColor4d(0.9, 0.9, 1.0, (1.0 - fade) * blend);
1679
mi->polygon_count += gp->num_faces;
1683
/* Restore the 'standard' blend functions. */
1684
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1600
if ((current_time - gp->state_start_time) > fade_time)
1688
if ((current_time - gp->state_start_time) > fade_time)
1602
gp->state = HOLDING;
1603
gp->state_start_time = current_time;
1604
gp->current_texture = 1 - gp->current_texture;
1690
gp->state = HOLDING;
1691
gp->state_start_time = current_time;
1692
gp->current_texture = 1 - gp->current_texture;