X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fantspotlight.c;h=30f2404d87d8866b0ab01e861c6bf938fca63ab2;hb=5f9c47ca98dd43d8f59b7c27d3fde6edfde4fe21;hp=f3272c2e7d58c36df3bdeee93a816ebeee80e23e;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/glx/antspotlight.c b/hacks/glx/antspotlight.c index f3272c2e..30f2404d 100644 --- a/hacks/glx/antspotlight.c +++ b/hacks/glx/antspotlight.c @@ -78,7 +78,7 @@ static antspotlightstruct *antspotlight = (antspotlightstruct *) NULL; #define NUM_SCENES 2 /* draw method for ant */ -static Bool draw_ant(antspotlightstruct *mp, +static Bool draw_ant(ModeInfo *mi, antspotlightstruct *mp, const GLfloat *Material, int mono, int shadow, float ant_step, Bool (*sphere)(float), Bool (*cone)(float)) { @@ -90,6 +90,12 @@ static Bool draw_ant(antspotlightstruct *mp, float sin2 = sin(ant_step + 2 * Pi / 3); float sin3 = sin(ant_step + 4 * Pi / 3); +/* Apparently this is a performance killer on many systems... + glEnable(GL_POLYGON_SMOOTH); + */ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mp->mono ? MaterialGray5 : Material); glEnable(GL_CULL_FACE); glPushMatrix(); @@ -123,22 +129,30 @@ static Bool draw_ant(antspotlightstruct *mp, glDisable(GL_LIGHTING); /* ANTENNAS */ + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin(GL_LINES); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, 0.40); + mi->polygon_count++; glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, -0.40); + mi->polygon_count++; glEnd(); if(!shadow) { glBegin(GL_POINTS); glColor3fv(mp->mono ? MaterialGray6 : MaterialGray5); glVertex3f(0.40, 0.70, 0.40); + mi->polygon_count++; glVertex3f(0.40, 0.70, -0.40); + mi->polygon_count++; glEnd(); } @@ -147,8 +161,10 @@ static Bool draw_ant(antspotlightstruct *mp, glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.05, 0.18); glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45); + mi->polygon_count++; glEnd(); /* LEFT-CENTER ARM */ @@ -156,8 +172,10 @@ static Bool draw_ant(antspotlightstruct *mp, glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.00, 0.18); glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45); + mi->polygon_count++; glEnd(); /* LEFT-BACK ARM */ @@ -165,8 +183,10 @@ static Bool draw_ant(antspotlightstruct *mp, glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, -0.05, 0.18); glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45); + mi->polygon_count++; glEnd(); /* RIGHT-FRONT ARM */ @@ -174,8 +194,10 @@ static Bool draw_ant(antspotlightstruct *mp, glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.05, -0.18); glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45); + mi->polygon_count++; glEnd(); /* RIGHT-CENTER ARM */ @@ -183,8 +205,10 @@ static Bool draw_ant(antspotlightstruct *mp, glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.00, -0.18); glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45); + mi->polygon_count++; glEnd(); /* RIGHT-BACK ARM */ @@ -192,8 +216,10 @@ static Bool draw_ant(antspotlightstruct *mp, glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, -0.05, -0.18); glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45); + mi->polygon_count++; glEnd(); if(!shadow) { @@ -205,6 +231,7 @@ static Bool draw_ant(antspotlightstruct *mp, glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45); glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45); glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45); + mi->polygon_count += 6; glEnd(); } @@ -245,7 +272,7 @@ static Bool mySphere2(float radius) /* no cone */ static Bool myCone2(float radius) { return True; } -static void draw_board(antspotlightstruct *mp) +static void draw_board(ModeInfo *mi, antspotlightstruct *mp) { int i, j; double cutoff = Pi/3.0; @@ -277,7 +304,7 @@ static void draw_board(antspotlightstruct *mp) i should be finding the intersection of the cone of light and the board-plane. */ - for(i = -8; i < 8; ++i) { + for(i = -12; i < 12; ++i) { double theta1, theta2; @@ -291,7 +318,7 @@ static void draw_board(antspotlightstruct *mp) theta1 = mp->ant->direction + i*(cutoff/8); theta2 = mp->ant->direction + (i+1)*(cutoff/8); - for(j = 1; j <= 40; ++j) { + for(j = 1; j <= 64; ++j) { double point[3], tex[2]; /* double fj = pow(1.05, j) - 1.0;*/ double fj = j / 6.0; @@ -314,6 +341,7 @@ static void draw_board(antspotlightstruct *mp) glTexCoord2f(tex[0], tex[1]); glVertex3f(point[0], point[1], point[2]); + mi->polygon_count++; } glEnd(); @@ -381,7 +409,7 @@ static void reset_ant(antspotlightstruct *mp) } /* draw ant composed of skeleton and glass */ -static void show_ant(antspotlightstruct *mp) +static void show_ant(ModeInfo *mi, antspotlightstruct *mp) { glPushMatrix(); @@ -392,14 +420,14 @@ static void show_ant(antspotlightstruct *mp) glRotatef(90.0, 0.0, 0.0, 1.0); /* draw skeleton */ - draw_ant(mp, mp->ant->material, mp->mono, 0, mp->ant->step, mySphere2, myCone2); + draw_ant(mi, mp, mp->ant->material, mp->mono, 0, mp->ant->step, mySphere2, myCone2); /* draw glass */ if(!mp->wire && !mp->mono) { glEnable(GL_BLEND); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB); glColor4fv(MaterialGrayB); - draw_ant(mp, MaterialGrayB, mp->mono, 0, mp->ant->step, mySphere, myCone2); + draw_ant(mi, mp, MaterialGrayB, mp->mono, 0, mp->ant->step, mySphere, myCone2); glDisable(GL_BLEND); } @@ -433,20 +461,25 @@ static void draw_antspotlight_strip(ModeInfo *mi) if(mp->wire) ; else - draw_board(mp); + draw_board(mi, mp); glDisable(GL_LIGHT2); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); /* now modify ant */ - show_ant(mp); + show_ant(mi, mp); /* near goal, bend path towards next step */ if(distance(mp->ant->position, mp->ant->goal) < 0.2) { reset_ant(mp); } + if(random()%100 == 0) { + reset_ant(mp); + } + + /* move toward goal, correct ant direction if required */ else { @@ -517,8 +550,7 @@ static const GLfloat spotlight_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; static void pinit(void) { glClearDepth(1.0); - glClearColor(0.0, 0.0, 0.0, 1.0); - + /* setup twoside lighting */ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); @@ -526,7 +558,8 @@ static void pinit(void) glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_POSITION, position1); -/* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */ + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, spotlight_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); @@ -708,6 +741,8 @@ ENTRYPOINT void draw_antspotlight(ModeInfo * mi) if(!mp->glx_context) return; + mi->polygon_count = 0; + /* Just keep running before the texture has come in. */ /* if (mp->waiting_for_image_p) return; */