/* draw an ant */ static Bool draw_antinspect_ant(ModeInfo *mi, antinspectstruct * mp, const float *Material, int mono, Bool (*sphere)(float), Bool (*cone)(float)) { float cos1 = cos(mp->ant_step); float cos2 = cos(mp->ant_step + 2 * Pi / 3); float cos3 = cos(mp->ant_step + 4 * Pi / 3); float sin1 = sin(mp->ant_step); float sin2 = sin(mp->ant_step + 2 * Pi / 3); float sin3 = sin(mp->ant_step + 4 * Pi / 3); if (mono) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray5); else glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Material); glEnable(GL_CULL_FACE); glPushMatrix(); glScalef(1, 1.3, 1); if (!((*sphere)(0.18))) return False; glScalef(1, 1 / 1.3, 1); glTranslatef(0.00, 0.30, 0.00); if (!((*sphere)(0.2))) return False; glTranslatef(-0.05, 0.17, 0.05); glRotatef(-90, 1, 0, 0); glRotatef(-25, 0, 1, 0); if (!((*cone)(0.05))) return False; glTranslatef(0.00, 0.10, 0.00); if (!((*cone)(0.05))) return False; glRotatef(25, 0, 1, 0); glRotatef(90, 1, 0, 0); glScalef(1, 1.3, 1); glTranslatef(0.15, -0.65, 0.05); if (!((*sphere)(0.25))) return False; glScalef(1, 1 / 1.3, 1); glPopMatrix(); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); /* ANTENNAS */ glBegin(GL_LINES); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, 0.40); mi->polygon_count++; if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, -0.40); mi->polygon_count++; glEnd(); glBegin(GL_POINTS); if (mono) glColor3fv(MaterialGray6); else glColor3fv(Material); glVertex3f(0.40, 0.70, 0.40); mi->polygon_count++; glVertex3f(0.40, 0.70, -0.40); mi->polygon_count++; glEnd(); /* LEFT-FRONT ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(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 */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(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(); mi->polygon_count++; /* LEFT-BACK ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(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 */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(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 */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(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 */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(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(); glEnable(GL_LIGHTING); return True; }
void draw_options_menu(MenuData *menu) { draw_options_menu_bg(menu); draw_text(AL_Right, 140*(1-menu->fade), 30, "Options", _fonts.mainmenu); glPushMatrix(); glTranslatef(100, 100, 0); /* glPushMatrix(); glTranslatef(SCREEN_W/2 - 100, menu->drawdata[2], 0); glScalef(SCREEN_W - 200, 20, 1); glColor4f(0,0,0,0.5); draw_quad(); glPopMatrix(); */ Texture *bg = get_tex("part/smoke"); glPushMatrix(); glTranslatef(menu->drawdata[0], menu->drawdata[2], 0); glScalef(menu->drawdata[1]/100.0, 0.2, 1); glRotatef(menu->frames*2,0,0,1); glColor4f(0,0,0,0.5); draw_texture_p(0,0,bg); glPopMatrix(); OptionBinding *binds = (OptionBinding*)menu->context; OptionBinding *bind; menu->drawdata[0] += ((SCREEN_W/2 - 100) - menu->drawdata[0])/10.0; menu->drawdata[1] += ((SCREEN_W - 200) - menu->drawdata[1])/10.0; menu->drawdata[2] += (20*menu->cursor - menu->drawdata[2])/10.0; int i, caption_drawn = 0; for(i = 0; i < menu->ecount; i++) { if(!menu->entries[i].name) continue; menu->entries[i].drawdata += 0.2 * (10*(i == menu->cursor) - menu->entries[i].drawdata); float a = menu->entries[i].drawdata * 0.1; bind = &(binds[i]); int hasbind = bind->enabled; float alpha = (!hasbind || bind_isactive(bind))? 1 : 0.5; if(menu->entries[i].action == NULL) { glColor4f(0.5, 0.5, 0.5, 0.7 * alpha); } else { //glColor4f(0.7 + 0.3 * (1-a), 1, 1, (0.7 + 0.3 * a) * alpha); float ia = 1-a; glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, (0.7 + 0.3 * a) * alpha); } draw_text(AL_Left, ((hasbind && bind->dependence)? 20 : 0) // hack hack hack + 20 - menu->entries[i].drawdata, 20*i, menu->entries[i].name, _fonts.standard); if(hasbind) { int j, origin = SCREEN_W - 220; switch(bind->type) { case BT_IntValue: if(bind->valrange_max) { char tmp[16]; // who'd use a 16-digit number here anyway? snprintf(tmp, 16, "%d", bind_getvalue(bind)); draw_text(AL_Right, origin, 20*i, tmp, _fonts.standard); } else for(j = bind->valcount-1; j+1; --j) { if(j != bind->valcount-1) origin -= strlen(bind->values[j+1])/2.0 * 20; if(bind_getvalue(bind) == j) { glColor4f(0.9, 0.6, 0.2, alpha); } else { glColor4f(0.5,0.5,0.5,0.7 * alpha); } draw_text(AL_Right, origin, 20*i, bind->values[j], _fonts.standard); } break; case BT_KeyBinding: if(bind->blockinput) { glColor4f(0.5, 1, 0.5, 1); draw_text(AL_Right, origin, 20*i, "Press a key to assign, ESC to cancel", _fonts.standard); } else draw_text(AL_Right, origin, 20*i, SDL_GetKeyName(tconfig.intval[bind->configentry]), _fonts.standard); if(!caption_drawn) { glColor4f(1,1,1,0.7); draw_text(AL_Center, (SCREEN_W - 200)/2, 20*(i-1), "Controls", _fonts.standard); caption_drawn = 1; } break; case BT_StrValue: if(bind->blockinput) { glColor4f(0.5, 1, 0.5, 1.0); if(strlen(*bind->values)) draw_text(AL_Right, origin, 20*i, *bind->values, _fonts.standard); } else draw_text(AL_Right, origin, 20*i, tconfig.strval[bind->configentry], _fonts.standard); break; case BT_Resolution: { char tmp[16]; int w, h; if(bind->selected == -1) { w = video.intended.width; h = video.intended.height; } else { VideoMode *m = &(video.modes[bind->selected]); w = m->width; h = m->height; } snprintf(tmp, 16, "%dx%d", w, h); draw_text(AL_Right, origin, 20*i, tmp, _fonts.standard); break; } } } } glPopMatrix(); fade_out(menu->fade); }
int a_DrawGLScene(GLfloat globtime) { if (init) {a_InitGL();init=false;} a_time=2.0+globtime*.01; // MOTION if (a_time<10.0f) { a_zeta=25.0f*cos((3.1415f/2.0f)*(1+a_time/10.0f)); a_xrot=-45.0f*cos((3.1415f/2.0f)*(1+a_time/10.0f)); } else { a_xrot=45.0f-30.0f*sin((a_time-10.0f)/20.0f)*sin((a_time-10.0f)/20.0f); a_zrot=360.0f*sin((a_time-10.0f)/50.0f)*sin((a_time-10.0f)/50.0f); a_zeta=-25.0f+5.0f*sin((a_time-10.0f)/10.0f)*sin((a_time-10.0f)/10.0f); } if (a_time>90.0f) a_zeta=-20.0f+10.0f*(1.0f-cos((a_time-90.0f)*3.1415f/10.0f)); if (a_zeta>-2.5f) a_zeta=-2.5f; a_factor=(a_xrot/.5+20)/50.0f; if (a_mod>0.5f) a_mod=1.0-.03f*(a_time-a_gets); else a_mod=.5-0.015f*(a_time-a_gets); if (a_mod<0.0f) a_mod=0.0f; glDisable(GL_TEXTURE_2D); glLoadIdentity(); glTranslatef(0,0,-5); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (a_zeta>-20.0f) glColor4f(0,0,0,-(a_zeta+20.0f)/40.0f+.25f); else glColor4f(0,0,0,.25f); glDisable(GL_LIGHTING); glEnable(GL_BLEND); a_drawquad(6); if (first)//a_time<3.01f) { glDisable(GL_BLEND); glColor4ub(255,255,255,255); a_drawquad(6); glEnable(GL_BLEND); first=false; } if (a_time>95.0f) { glColor4f(1.0f,1.0f,1.0f,(a_time-95.0f)/1.5f); a_drawquad(6); } glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_LIGHTING); glLoadIdentity(); if (a_time>30.0) glTranslatef(0.0f,1.5f,a_zeta); else glTranslatef(0.0f,.5+.5f*(1.0-cos((a_time-2.0f)*3.1415f/28.0f)),a_zeta); glRotatef(-90+2*a_xrot,1.0f,0.0f,0.0f); glRotatef(a_yrot,0.0f,1.0f,0.0f); glRotatef(a_zrot,0.0f,0.0f,1.0f); for (int a_xx=0; a_xx<size; a_xx++) for (int a_yy=0; a_yy<size; a_yy++) { double raggio; double value; double arg; if (quantos>0.0f) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[size/2][size/2][0])*(a_points[a_xx][a_yy][0]-a_points[size/2][size/2][0]) +(a_points[a_xx][a_yy][1]-a_points[size/2][size/2][1])*(a_points[a_xx][a_yy][1]-a_points[size/2][size/2][1]))); arg=2.5*raggio-quantos*2+30; if ((arg<-2*6.28)||(arg>4*6.28)) value=0; else value=.05*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]=value; } if (quantos>10) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[48][48][0])*(a_points[a_xx][a_yy][0]-a_points[48][48][0]) +(a_points[a_xx][a_yy][1]-a_points[48][48][1])*(a_points[a_xx][a_yy][1]-a_points[48][48][1]))); arg=2.5*raggio-(quantos-10)*3+30; if ((arg<-2*6.28)||(arg>4*6.28)) value=0; else value=.025*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]+=value; } if (quantos>24) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[50][22][0])*(a_points[a_xx][a_yy][0]-a_points[50][22][0]) +(a_points[a_xx][a_yy][1]-a_points[50][22][1])*(a_points[a_xx][a_yy][1]-a_points[50][22][1]))); arg=3.0*raggio-(quantos-24)*4+30; if ((arg<-2*6.28)||(arg>4*6.28)) value=0; else value=.02*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]+=value; } if (quantos>32) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[32][32][0])*(a_points[a_xx][a_yy][0]-a_points[32][32][0]) +(a_points[a_xx][a_yy][1]-a_points[32][32][1])*(a_points[a_xx][a_yy][1]-a_points[32][32][1]))); arg=2.5*raggio-(quantos-32)*3+30; if ((arg<0*6.28)||(arg>4*6.28)) value=0; else value=.035*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]+=value; } calcul(a_xx,a_yy); } if (a_time>34.0f) quantos=2.0+(a_time-34.0)/1.5f; a_Text[1].Use(); glMaterialfv(GL_FRONT,GL_DIFFUSE,a_diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,a_ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,a_specular); glMaterialf(GL_FRONT,GL_SHININESS,10.0f); // glPushMatrix(); // what for? //glDisable(GL_LIGHTING); glScalef(-1,-1,1); glColor4f(1,1,1,1); // glPushMatrix(); // what for? glTranslatef(-12.8,12.8,0); glNormal3f(0,0,1); for (int cc=0; cc<1; cc++) { if ((cc%2)==0) { glScalef(1,-1,1); glFrontFace(GL_CCW); } else { glScalef(-1,1,1); glFrontFace(GL_CW); } glBegin(GL_QUADS); for( a_x = 0; a_x < size-1; a_x++ ) { if (1)//a_x%2==0) { for( a_y = 0; a_y < size-1; a_y++ ) { glTexCoord2fv(newcoord[a_x][a_y]); //glNormal3f(-norm[a_x][a_y][0],-norm[a_x][a_y][1],-norm[a_x][a_y][2]); glVertex3fv( a_points[a_x][a_y]); glTexCoord2fv(newcoord[a_x][a_y+1]); //glNormal3f(-norm[a_x][a_y+1][0],-norm[a_x][a_y+1][1],-norm[a_x][a_y+1][2]); glVertex3fv( a_points[a_x][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y+1]); //glNormal3f(-norm[a_x+1][a_y+1][0],-norm[a_x+1][a_y+1][1],-norm[a_x+1][a_y+1][2]); glVertex3fv( a_points[a_x+1][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y]); //glNormal3f(-norm[a_x+1][a_y][0],-norm[a_x+1][a_y][1],-norm[a_x+1][a_y][2]); glVertex3fv( a_points[a_x+1][a_y]); } } else { for(a_y=size-2;a_y>=0;a_y--) { glTexCoord2fv(newcoord[a_x][a_y]); glVertex3fv( a_points[a_x][a_y]); glTexCoord2fv(newcoord[a_x][a_y+1]); glVertex3fv( a_points[a_x][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y+1]); glVertex3fv( a_points[a_x+1][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y]); glVertex3fv( a_points[a_x+1][a_y]); } } } glEnd(); } // glPushMatrix(); // what for? glDisable(GL_DEPTH_TEST); // glPopMatrix(); // what for? glDisable(GL_LIGHTING); a_Text[4].Use(); a_counter=a_time*10.0f; for (int p=0; p<a_num; p++) { GLfloat time; time=a_time*500-2.0-parts[p].time;//******************************************************** glPushMatrix(); glTranslatef(parts[p].a_x,parts[p].a_y,parts[p].z); glRotatef(-a_zrot,0,0,1); glRotatef(90-2.0f*a_xrot,1,0,0); glRotatef(parts[p].angle-135,0,0,1); glTranslatef(parts[p].a_mod,0,0); if (a_time<20.0f) glColor4ub(parts[p].r,parts[p].g,parts[p].b,(unsigned char)((parts[p].a-(int)((GLfloat)time/8.0f))*(a_time-6.0)/14.0)); else glColor4ub(parts[p].r,parts[p].g,parts[p].b,(unsigned char)(parts[p].a-(int)((GLfloat)time/8.0f))); if (a_time>6.0) a_drawquad(1.125f-.75*p/a_num); parts[p].a_mod=parts[p].speed*time/35.0f; parts[p].speed=parts[p].speedlim-time/2500000.0f; if (parts[p].speed<0.005f) parts[p].speed=0.005f; if (parts[p].a-(int)((GLfloat)time/8.0f)<3) { parts[p].a_x=10.0f*sin(a_counter*4.0f*3.14f/360.0f); parts[p].a_y=0.0f+10.0f*sin(a_counter*2*3.14/360.0); parts[p].z=a_Sinus[2]=3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); parts[p].r=128+rand()%128; parts[p].g=128+rand()%128; parts[p].b=128+rand()%128; parts[p].a=rand()%255; parts[p].a_mod=0.0f; parts[p].speedlim=.005+.0001*((GLfloat)(rand()%1000)); parts[p].speed=parts[p].speedlim; parts[p].time=(int)(a_time*500-2);//********************************* } glPopMatrix(); } glPushMatrix(); a_Sinus[0]=10.0f*sin(a_counter*4.0f*3.14f/360.0f); a_Sinus[1]=0.0f+10.0f*sin(a_counter*2*3.14/360.0); a_Sinus[2]=3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); glTranslatef(a_Sinus[0],a_Sinus[1],a_Sinus[2]); glRotatef(-a_zrot,0,0,1); glRotatef(90-2*a_xrot,1,0,0); glColor4ub(255,128,255,255); glColor4ub(128,192,255,255); glRotatef(2*a_counter,0,0,1); a_LightPosition[0]=0;//a_Sinus[0];//10.0f*sin(a_counter*4.0f*3.14f/360.0f); a_LightPosition[1]=0;//a_Sinus[1];//0.0f+10.0f*sin(a_counter*2*3.14/360.0); a_LightPosition[2]=0;//a_Sinus[2];//3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT1,GL_POSITION,a_LightPosition); glDisable(GL_LIGHTING); a_Text[2].Use(); a_drawquad(1.0f+sin(a_counter*12.0f*3.1415f/360.0)+3.1415f/2.0f); a_Text[3].Use(); a_drawquad(3.0f+2*sin(a_counter*6.0f*3.1415f/360.0)); glPopMatrix(); /* a_LightPosition[0]=10.0f*sin(a_counter*4.0f*3.14f/360.0f); a_LightPosition[1]=0.0f+10.0f*sin(a_counter*2*3.14/360.0); a_LightPosition[2]=3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); // glTranslatef(a_LightPosition[0],a_LightPosition[1],a_LightPosition[2]); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT1,GL_POSITION,a_LightPosition); */ // a_time=2.0f+(1)/500.0f;//************************************ if (a_time>96.0f) { //****************************** FINISH //a_Clean(); return false; } glutSwapBuffers(); return true; }
void CCanvasContext::translate(float x, float y) { cleanDrawImage(); glTranslatef(x, y, 0); }
void L_ParticleEffect::draw(int x_shift, int y_shift, float x_size_mod, float y_size_mod) { if (particle_list.size() == 0) return; //LogMsg("particles: %d", particle_list.size()); std::list<L_Particle*>::iterator iter = particle_list.begin(); #ifndef RT_USE_POINT_SPRITES //OPTIMIZE: naive way to draw them with separate blits for normal GL mode or android code g_globalBatcher.Flush(); while( iter != particle_list.end() ) { (*iter)->draw(x_shift, y_shift, x_size_mod, y_size_mod); iter++; } g_globalBatcher.Flush(RenderBatcher::FLUSH_SETUP); glBlendFunc( GL_SRC_ALPHA, GL_ONE); //custom render mode change g_globalBatcher.Flush(RenderBatcher::FLUSH_RENDER); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); //undo custom render mode change g_globalBatcher.Flush(RenderBatcher::FLUSH_UNSETUP); #else SurfaceAnim *pSurf = NULL; int count = 0; glPushMatrix(); glTranslatef(x_shift, y_shift, 0); while( iter != particle_list.end() ) { if (count >= L_ParticleMem::pointSpriteArraySize) { //reached the max of the buffer size.. dump now RenderPointSprites(pSurf, 0, count); count = 0; } if (pSurf != (*iter)->surface) { if (pSurf != NULL) { //uh oh... we can't handle 2 textures with our batching process. We need to sort the textures.. well, //I don't feel like making that happen so let's just render what we've got so far before changing it RenderPointSprites(pSurf, 0, count); count = 0; } pSurf = (*iter)->surface; } L_ParticleMem::pointSpriteArray[count].vPos.x = (*iter)->x_pos; L_ParticleMem::pointSpriteArray[count].vPos.y = (*iter)->y_pos; L_ParticleMem::pointSpriteArray[count].size = pSurf->GetRawTextureWidth()*(*iter)->get_size(); L_ParticleMem::pointSpriteArray[count].color = *(uint32*)&(*iter)->current_color; count++; iter++; } RenderPointSprites(pSurf, 0, count); glPopMatrix(); #endif }
void ProcessHelix() // Draws A Helix { GLfloat x; // Helix x Coordinate GLfloat y; // Helix y Coordinate GLfloat z; // Helix z Coordinate GLfloat phi; // Angle GLfloat theta; // Angle GLfloat v,u; // Angles GLfloat r; // Radius Of Twist int twists = 5; // 5 Twists GLfloat glfMaterialColor[4]; // The Material Color GLfloat specular[4]; // Specular Lighting glfMaterialColor[0]=0.4f; // Set The Material Color glfMaterialColor[1]=0.2f; glfMaterialColor[2]=0.8f; glfMaterialColor[3]=1.0f; specular[0]=1.0f; // Sets Up Specular Lighting specular[1]=1.0f; specular[2]=1.0f; specular[3]=1.0f; glLoadIdentity(); // Reset The Modelview Matrix gluLookAt(0, 5, 50, 0, 0, 0, 0, 1, 0); // Eye Position (0,5,50) Center Of Scene (0,0,0), Up On Y Axis glPushMatrix(); // Push The Modelview Matrix glTranslatef(0,0,-50); // Translate 50 Units Into The Screen glRotatef(angle/2.0f,1,0,0); // Rotate By angle/2 On The X-Axis glRotatef(angle/3.0f,0,1,0); // Rotate By angle/3 On The Y-Axis glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,glfMaterialColor); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular); r=1.5f; // Radius glBegin(GL_QUADS); // Begin Drawing Quads for(phi=0; phi <= 360; phi+=20.0) // 360 Degrees In Steps Of 20 { for(theta=0; theta<=360*twists; theta+=20.0) // 360 Degrees * Number Of Twists In Steps Of 20 { v=(phi/180.0f*3.142f); // Calculate Angle Of First Point ( 0 ) u=(theta/180.0f*3.142f); // Calculate Angle Of First Point ( 0 ) x=(float)(cos(u)*(2.0f+cos(v) ))*r; // Calculate x Position (1st Point) y=(float)(sin(u)*(2.0f+cos(v) ))*r; // Calculate y Position (1st Point) z=(float)((( u-(2.0f*3.142f)) + sin(v) ) * r); // Calculate z Position (1st Point) vertexes[0][0]=x; // Set x Value Of First Vertex vertexes[0][1]=y; // Set y Value Of First Vertex vertexes[0][2]=z; // Set z Value Of First Vertex v=(phi/180.0f*3.142f); // Calculate Angle Of Second Point ( 0 ) u=((theta+20)/180.0f*3.142f); // Calculate Angle Of Second Point ( 20 ) x=(float)(cos(u)*(2.0f+cos(v) ))*r; // Calculate x Position (2nd Point) y=(float)(sin(u)*(2.0f+cos(v) ))*r; // Calculate y Position (2nd Point) z=(float)((( u-(2.0f*3.142f)) + sin(v) ) * r); // Calculate z Position (2nd Point) vertexes[1][0]=x; // Set x Value Of Second Vertex vertexes[1][1]=y; // Set y Value Of Second Vertex vertexes[1][2]=z; // Set z Value Of Second Vertex v=((phi+20)/180.0f*3.142f); // Calculate Angle Of Third Point ( 20 ) u=((theta+20)/180.0f*3.142f); // Calculate Angle Of Third Point ( 20 ) x=(float)(cos(u)*(2.0f+cos(v) ))*r; // Calculate x Position (3rd Point) y=(float)(sin(u)*(2.0f+cos(v) ))*r; // Calculate y Position (3rd Point) z=(float)((( u-(2.0f*3.142f)) + sin(v) ) * r); // Calculate z Position (3rd Point) vertexes[2][0]=x; // Set x Value Of Third Vertex vertexes[2][1]=y; // Set y Value Of Third Vertex vertexes[2][2]=z; // Set z Value Of Third Vertex v=((phi+20)/180.0f*3.142f); // Calculate Angle Of Fourth Point ( 20 ) u=((theta)/180.0f*3.142f); // Calculate Angle Of Fourth Point ( 0 ) x=(float)(cos(u)*(2.0f+cos(v) ))*r; // Calculate x Position (4th Point) y=(float)(sin(u)*(2.0f+cos(v) ))*r; // Calculate y Position (4th Point) z=(float)((( u-(2.0f*3.142f)) + sin(v) ) * r); // Calculate z Position (4th Point) vertexes[3][0]=x; // Set x Value Of Fourth Vertex vertexes[3][1]=y; // Set y Value Of Fourth Vertex vertexes[3][2]=z; // Set z Value Of Fourth Vertex calcNormal(vertexes,normal); // Calculate The Quad Normal glNormal3f(normal[0],normal[1],normal[2]); // Set The Normal // Render The Quad glVertex3f(vertexes[0][0],vertexes[0][1],vertexes[0][2]); glVertex3f(vertexes[1][0],vertexes[1][1],vertexes[1][2]); glVertex3f(vertexes[2][0],vertexes[2][1],vertexes[2][2]); glVertex3f(vertexes[3][0],vertexes[3][1],vertexes[3][2]); } } glEnd(); // Done Rendering Quads glPopMatrix(); // Pop The Matrix }
/* sets up the opengl context. * width, height are to match the values from ED_mask_get_size() */ void ED_mask_draw_region(Mask *mask, ARegion *ar, const char draw_flag, const char draw_type, const char overlay_mode, const int width_i, const int height_i, /* convert directly into aspect corrected vars */ const float aspx, const float aspy, const bool do_scale_applied, const bool do_draw_cb, float stabmat[4][4], /* optional - only used by clip */ const bContext *C /* optional - only used when do_post_draw is set or called from clip editor */ ) { struct View2D *v2d = &ar->v2d; /* aspect always scales vertically in movie and image spaces */ const float width = width_i, height = (float)height_i * (aspy / aspx); int x, y; /* int w, h; */ float zoomx, zoomy; /* frame image */ float maxdim; float xofs, yofs; /* find window pixel coordinates of origin */ UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); /* w = BLI_rctf_size_x(&v2d->tot); */ /* h = BLI_rctf_size_y(&v2d->tot);/*/ zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) / BLI_rctf_size_x(&ar->v2d.cur); zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) / BLI_rctf_size_y(&ar->v2d.cur); if (do_scale_applied) { zoomx /= width; zoomy /= height; } x += v2d->tot.xmin * zoomx; y += v2d->tot.ymin * zoomy; /* frame the image */ maxdim = max_ff(width, height); if (width == height) { xofs = yofs = 0; } else if (width < height) { xofs = ((height - width) / -2.0f) * zoomx; yofs = 0.0f; } else { /* (width > height) */ xofs = 0.0f; yofs = ((width - height) / -2.0f) * zoomy; } if (draw_flag & MASK_DRAWFLAG_OVERLAY) { float *buffer = threaded_mask_rasterize(mask, width, height); int format; if (overlay_mode == MASK_OVERLAY_ALPHACHANNEL) { glColor3f(1.0f, 1.0f, 1.0f); format = GL_LUMINANCE; } else { /* More blending types could be supported in the future. */ glEnable(GL_BLEND); glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA); format = GL_ALPHA; } glPushMatrix(); glTranslatef(x, y, 0); glScalef(zoomx, zoomy, 0); if (stabmat) { glMultMatrixf(stabmat); } glaDrawPixelsTex(0.0f, 0.0f, width, height, format, GL_FLOAT, GL_NEAREST, buffer); glPopMatrix(); if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) { glDisable(GL_BLEND); } MEM_freeN(buffer); } /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ glPushMatrix(); glTranslatef(x + xofs, y + yofs, 0); glScalef(maxdim * zoomx, maxdim * zoomy, 0); if (stabmat) { glMultMatrixf(stabmat); } if (do_draw_cb) { ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); } /* draw! */ draw_masklays(C, mask, draw_flag, draw_type, width, height); if (do_draw_cb) { ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); } glPopMatrix(); }
void render_scene() { // définit la couleur de tracé glColor3f(1.0, 1.0, 1.0); // initialise la matrice de modélisation glLoadIdentity(); // Translate l'objet glTranslatef(-5.0, 5.0, 0.0); // dessine les sommets selon la primitive GL_LINES glBegin(GL_LINES); // Sommet 1 glVertex2f(-1.0, 1.0); // Sommet 2 glVertex2f(1.0, 2.0); // Sommet 3 glVertex2f(2.0, 0.0); // Sommet 4 glVertex2f(1.0, -1.0); // Sommet 5 glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(0.0, 5.0, 0.0); glBegin(GL_LINE_STRIP); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(5.0, 5.0, 0.0); glBegin(GL_LINE_LOOP); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(-5.0, 0.0, 0.0); glBegin(GL_POLYGON); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(0.0, 0.0, 0.0); glBegin(GL_QUADS); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(5.0, 0.0, 0.0); glBegin(GL_QUAD_STRIP); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(-5.0, -5.0, 0.0); glBegin(GL_TRIANGLES); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(0.0, -5.0, 0.0); glBegin(GL_TRIANGLE_STRIP); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); glLoadIdentity(); glTranslatef(5.0, -5.0, 0.0); glBegin(GL_TRIANGLE_FAN); glVertex2f(-1.0, 1.0); glVertex2f(1.0, 2.0); glVertex2f(2.0, 0.0); glVertex2f(1.0, -1.0); glVertex2f(-2.0, -2.0); glEnd(); }