/* * Draws the plant. */ void drawPlant(int i,float scale,float radscale,int string) { char *ptr = lsystem[string]; char ch[] = { '\0','\0' }; GLfloat c1[] = { 0.6549f,0.4901f,0.2392f }; /* light brown */ GLfloat c2[] = { 0.3607f,0.2510f,0.2000f }; /* dark brown */ GLfloat c3[] = { 0.1373f,0.5568f,0.1373f }; /* forest green */ if(i==0) return; PushMatrix(); while(*ptr != '\0') { switch(*ptr) { case 'F': Rotate(tilt/10000,0.0,0.0,1.0); /* tilt very very slightly */ LoadMatrix(); if(do_growth && floor(growth)==i) { draw_branch(LENGTH*scale*(growth-1),RADIUS*radscale,BASE_TRI,c1,c2); Translate(0.0,LENGTH*scale*(growth-1),0.0); } else { draw_branch(LENGTH*scale,RADIUS*radscale,BASE_TRI,c1,c2); Translate(0.0,LENGTH*scale,0.0); } break; case '[': PushMatrix(); break; case ']': PopMatrix(); break; case 'L': if(do_growth && floor(growth)==i) draw_leaf(4*(growth-1)*scale,1*(growth-1)*scale,25,c3); else draw_leaf(4*scale,1*scale,25,c3); break; case 'R': Rotate(yrotate,0.0,1.0,0.0); break; case 'T': Rotate(tilt,0.0,0.0,1.0); break; default: if(isdigit(*ptr)) { ch[0] = *ptr; drawPlant(i-1,scale*SCALE,radscale*RADSCALE,atoi(ch)); } break; } ptr++; } PopMatrix(); }
void display() { glClear(GL_COLOR_BUFFER_BIT); /* put plant drawing code here */ drawPlant(); /* end drawing code */ glFlush(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // „Ƕ„Ç£„É≥„Éâ„Ƕ„ÅÆËÉåÊôØ„Çí°ó„Çä„ŧ„Å∂„Å? & Èö†Èù¢Âá¶ÁêÅEÇíÂèØËÉΩ„Å´„Åô„Çã glEnable(GL_DEPTH_TEST); // Èö†Èù¢Âá¶ÁêÅEñãÂß? glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glPushMatrix(); glTranslatef(0.0, 1.0, 0.0); polarview(); // „Éù„ÅE„É©„ɺ„Éì„É•„ɺ„Å∏„ÅÆ„Éì„É•„ɺ„ǧ„É≥„Ç∞§âÊèõ glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, light0); glPopMatrix(); shading(5); drawGround2D(); shading(6); glDisable(GL_LIGHTING); drawGrass(); glEnable(GL_LIGHTING); shading(5); drawPlant(); if (rainFlag == GL_TRUE) drawRain(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); drawCloud(); if (thunderFlag == GL_TRUE && rainFlag == GL_TRUE) { if (lightningnum == 0 || lightningnum == 4) lightning(); lightningnum++; if (lightningnum == 5) { lightningnum = 0; thunderFlag = GL_FALSE; } if (rand() % 10 == 4) fallFlag = GL_TRUE; } else thunderFlag = GL_FALSE; glPopMatrix(); glutSwapBuffers(); }
// Draw the leaf void drawPlant(int i, GLfloat t[]) { GLfloat temp[9]; GLfloat *pivot; double rotate_angle; double r; if(t == NULL) { t = Nothing; } if(i <= 0) { drawLeafBezier(t); } else { matrix_multiply3_3(ScaleDown, t , temp); t = temp; t = drawStem(i, t); pivot = t; drawPlant(i - 1, t); // recurse LEFT branch // rotate between PI/8 to PI/4 r = (double)rand() / (double)RAND_MAX; rotate_angle = (M_PI / 8) + r * M_PI / 8; t = matrix_rotate(t, rotate_angle, true); drawPlant(i - 1, t); t = pivot; // recurse RIGHT branch r = (double)rand() / (double)RAND_MAX; rotate_angle = (M_PI / 8) + r * M_PI / 8; t = matrix_rotate(t, -rotate_angle, true); drawPlant(i - 1, t); } }
void display() { glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_MAP1_VERTEX_3); /* See drawplant.c for the definition of this routine */ drawPlant(cur_depth); glFlush(); /* Flush all executed OpenGL ops finish */ /* * Since we are using double buffers, we need to call the swap * function every time we are done drawing. */ glutSwapBuffers(); }
void display() { glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw Background int pic_w, pic_h; GLubyte* img = readPPMfile ("apple.ppm", &pic_w, &pic_h); glRasterPos3f (-40.0f, -10.0f, -40.0f); glDrawPixels (pic_w, pic_h, GL_RGB, GL_UNSIGNED_BYTE, img); /* See drawplant.c for the definition of this routine */ drawPlant(_iterations, 10.0f); glFlush(); /* Flush all executed OpenGL ops finish */ /* * Since we are using double buffers, we need to call the swap * function every time we are done drawing. */ glutSwapBuffers(); }