void Renderer::Render(const Camera& cam, IContext& c){ #if ZEUS_SAFE if (c.GetType() != IContext::OpenGL21) throw Exception("Context not supported by renderer: " + Utils::ToString<IContext::Type>(c.GetType())); #endif Context& glContext = (Context&)c; // Draw scene ApplyCamera(cam, c); glEnable(GL_CULL_FACE); // @TODO Setup light. Lightmaps 'n shit glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); Vector3 dir = Vector3(1,3,2); Normalize(dir); float hat[4]; dir.GetData(hat); hat[3] = 1.0f; glLightfv(GL_LIGHT0, GL_POSITION, hat); SceneObjectList::iterator itr = SceneObjectList::Begin(); while (itr != SceneObjectList::End()){ //Debug::Log("Rendering " + (*itr)->GetName()); const ModelComponent* m = (*itr)->GetComponent<ModelComponent>(); if (m){ //Debug::Log((*itr)->GetName() + " has mesh"); const ModelPropertiesPtr props = m->GetModelProperties(); if (props) { ModelProperties::Texture2DIterator itr = props->Texture2DBegin(); while (itr != props->Texture2DEnd()) { const GLTexture2D* tex = glContext.AddTexture(itr->second); glBindTexture(GL_TEXTURE_2D, tex->GetID()); glEnable(GL_TEXTURE_2D); ++itr; } } else { glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } const MeshPtr mesh = m->GetMesh(); if (mesh) { const Transformation* t = (*itr)->GetComponent<Transformation>(); glPushMatrix(); Matrix4x4 m = t->GetAccumulatedMatrix(); glMultMatrixf(m.GetData()); // @TODO Apply material const GLMesh* mInfo = glContext.AddMesh(mesh); RenderModel(*mInfo, glContext); glPopMatrix(); } } ++itr; } glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_CULL_FACE); }
ENTRYPOINT void draw_providence(ModeInfo * mi) { providencestruct *mp; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if(!providence) return; mp = &providence[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if(!mp->glx_context) return; glXMakeCurrent(display, window, *(mp->glx_context)); /* setup twoside lighting */ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient2); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, mp->position0); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glFrontFace(GL_CCW); /* glDisable(GL_CULL_FACE); */ glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(current_device_rotation(), 0, 0, 1); /* modify camera */ if(fabs(mp->camera_velocity) > EPSILON) { mp->camera_z = max(min(mp->camera_z + 0.1*mp->camera_velocity, -4.0), -12.0); mp->camera_velocity = 0.95*mp->camera_velocity; } /* rotate providence */ glTranslatef(0.0, 0.0, mp->camera_z + sin(mp->theta/4.0)); glRotatef(10.0+20.0*sin(mp->theta/2.0), 1.0, 0.0, 0.0); gltrackball_rotate(mp->trackball); glRotatef(mp->theta * 180.0 / Pi, 0.0, -1.0, 0.0); # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ { GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); int o = (int) current_device_rotation(); if (o != 0 && o != 180 && o != -180) glScalef (1/h, 1/h, 1/h); } # endif /* draw providence */ draw_providence_strip(mi); glPopMatrix(); if(MI_IS_FPS(mi)) do_fps (mi); glFlush(); glXSwapBuffers(display, window); /* update */ mp->currenttime += 1.0 / FPS; mp->theta = mp->currenttime / 2.0 * mp->theta_scale; update_particles(mp); }
void display(){ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glViewport(0, 0, glwidth, glheight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(1.5, (double)glwidth / (double)glheight, 1.0, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(150.0,100.0,-200.0, 0.0,0.0,0.0, 0.0,1.0,0.0); glMultMatrixd(Rotate); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, gold_diff); glPushMatrix(); glTranslated(sin(t),cos(t),-3.); glRotatef(90, 1.0f, 0.0f, 0.0f); glutSolidSphere(.3,20,20); glPopMatrix(); glutSolidSphere(1.5,20,20); glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_light); if(!colormask_on){ glColorMask(0,0,0,0); glDepthMask(0); } glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); glStencilMask(~0); if(frontcull){ glCullFace(GL_FRONT); glStencilFunc(GL_ALWAYS, 1, ~0); glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE); /* glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); */ /* glStencilOp(GL_KEEP, GL_INCR, GL_KEEP); */ glPushMatrix(); glTranslated(sin(t),cos(t),-3); glRotatef(90, 1.0f, 0.0f, 0.0f); /* glRotatef(90, 0.0f, 0.0f, 1.0f); */ cylinder(.3,100,20); glPopMatrix(); } if(backcull){ glCullFace(GL_BACK); glStencilFunc(GL_ALWAYS, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); /* glStencilOp(GL_KEEP, GL_DECR, GL_KEEP); */ glPushMatrix(); glTranslated(sin(t),cos(t),-3.); glRotatef(90, 1.0f, 0.0f, 0.0f); /* glRotatef(90, 0.0f, 0.0f, 1.0f); */ cylinder(.3,100,20); glPopMatrix(); } glDisable(GL_CULL_FACE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); glStencilFunc(GL_EQUAL, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glDisable(GL_DEPTH_TEST); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,black_light); glBegin(GL_QUADS); glVertex2i(-10, -10); glVertex2i(-10, 10); glVertex2i(10, 10); glVertex2i(10, -10); glEnd(); glEnable(GL_DEPTH_TEST); /* glEnable(GL_DEPTH_TEST); */ glDisable(GL_STENCIL_TEST); console(); t+=1e-2; glFinish(); glutSwapBuffers(); }
M(void, glLightfv, jint light, jint pname, jobject params) { glLightfv(light, pname, BUFF(GLfloat, params)); }
void init() { glClearColor(0.0, 0.0, 0.0, 1.0); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); glMaterialfv(GL_LIGHT0, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialf(GL_LIGHT0, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission); glShadeModel(GL_SMOOTH); /* enable smooth shading */ glEnable(GL_LIGHTING); /* enable lighting */ glEnable(GL_LIGHT0); /* enable light 0 */ glEnable(GL_DEPTH_TEST); // following are texture mapping part // glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glEnable ( GL_COLOR_MATERIAL ); glColorMaterial ( GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE ); glEnable ( GL_TEXTURE_2D ); glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); // glGenTextures (1, texture_id); image_t temp_image; glBindTexture ( GL_TEXTURE_2D, texture_id[MOUNTAIN_TEXTURE] ); tgaLoad ( "mountains-hero.tga", &temp_image, TGA_FREE | TGA_LOW_QUALITY ); //try to load a second picture glPixelStorei ( GL_UNPACK_ALIGNMENT, 2); // glGenTextures (2, texture_id); image_t temp_image2; glBindTexture ( GL_TEXTURE_2D, texture_id[CLOUD_TEXTURE] ); tgaLoad ( "atmosphere_clouds.tga", &temp_image2, TGA_FREE | TGA_LOW_QUALITY ); //try to load a third texture glPixelStorei ( GL_UNPACK_ALIGNMENT, 3 ); glGenTextures (3, texture_id); image_t temp_image3; glBindTexture ( GL_TEXTURE_2D, texture_id[CHECKBOARD_TEXTURE] ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); tgaLoad ( "color_checkboard.tga", &temp_image3, TGA_FREE | TGA_LOW_QUALITY ); // a flat image glShadeModel(GL_FLAT); makeCheckImage(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(4, &texture_id[3]); glBindTexture(GL_TEXTURE_2D, texture_id[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBindTexture(GL_TEXTURE_2D, texture_id[3]); glEnable ( GL_CULL_FACE ); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); }
/* Focntion de dessin */ void DrawGLScene() { // Effacement du buffer de couleur et de profondeur glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Paramètrage de l'éclairage glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_POSITION,light_position); ////////////////////////////////////////////////// // camera // gluLookAt(0.0,5.0,30.0,0.0,5.0,0.0,0.0,1.0,0.0); // premère partie : robot seul gluLookAt(cam_pos_x,10.0,cam_pos_z,cam_look_x,5.0,cam_look_z,0.0,1.0,0.0); ////////////////////////////////////////////////// // Compilation des listes Make_CallListes(); ////////////////////////////////////////////////// // sol glPushMatrix(); ground(); glPopMatrix(); ////////////////////////////////////////////////// // Bras articulé /*Mettre les degré de liberté au fur et a mesure des objets*/ /* // base glTranslatef(base_x,0.0,base_z); glRotatef(base_rot,0.0,1.0,0.0); glCallList(OBJET_3); // segment 1 float first_y = 0.25*5.5; glTranslatef(0.0,first_y,0.0); glRotatef(first_x,1.0,0.0,0.0); glRotatef(first_z,0.0,0.0,1.0); glCallList(OBJET_4); glCallList(OBJET_1); // segment2 float second_y = 0.6*8.0; glTranslatef(0.0,second_y,0.0); glRotatef(second_x,1.0,0.0,0.0); glRotatef(second_z,0.0,0.0,1.0); glCallList(OBJET_4); glCallList(OBJET_1); // segment 3 glTranslatef(0.0,second_y,0.0); glRotatef(third_x,1.0,0.0,0.0); glRotatef(third_z,0.0,0.0,1.0); glCallList(OBJET_4); glCallList(OBJET_1); // pinces 1 & 2 //float finger_x = 45.0; glTranslatef(0.0,second_y,0.0); glCallList(OBJET_4); glPushMatrix(); glRotatef(finger_x,0.0,0.0,1.0); glCallList(OBJET_2); glTranslatef(0.0,5.85*0.3,0.0); glRotatef(-45.0,0.0,0.0,1.0); glCallList(OBJET_2); glPopMatrix(); glRotatef(-finger_x,0.0,0.0,1.0); glCallList(OBJET_2); glTranslatef(0.0,5.85*0.3,0.0); glRotatef(45.0,0.0,0.0,1.0); glCallList(OBJET_2); */ ////////////////////////////////////////////////// ////////////////////////////////////////////////// // Robot complet ///////////////////////////////// // Base glTranslatef(base_x,0.0,base_z); glPushMatrix(); glScalef(2.0,2.0,2.0); glCallList(OBJET_3); glPopMatrix(); ///////////////////////////////// // Tronc glTranslatef(0.0,4.0+(2.0*1.375),0.0); glRotatef(base_rot,0.0,1.0,0.0); glPushMatrix(); glScalef(3.0,4.0,3.0); tronc_robot(); glPopMatrix(); ////////////////////////////////////////////////// // bras 1 glPushMatrix(); glTranslatef(-3.0,2.0,0.0); glRotatef(90.0,0.0,0.0,1.0); bras_robot(); glPopMatrix(); ////////////////////////////////////////////////// ////////////////////////////////////////////////// // bras 2 glPushMatrix(); glTranslatef(3.0,2.0,0.0); glRotatef(-90.0,0.0,0.0,1.0); glScalef(-1.0,1.0,1.0); bras_robot(); glPopMatrix(); ////////////////////////////////////////////////// //Tête du robot glTranslatef(0.0,5.0,0.0); glutSolidSphere(2.5,20,20); // Permutation des buffers glutSwapBuffers(); glutPostRedisplay(); }
static void new_ship(ModeInfo *mi) { commander_conf *cp = &commander[MI_SCREEN(mi)]; int i; GLfloat *this_v; GLint *p; /*GLfloat *this_n;*/ int count; #if 0 int wire = MI_IS_WIREFRAME(mi); GLfloat bcolor[4] = {0.2, 0.2, 0.2, 0.2}; GLfloat bspec[4] = {0.1, 0.1, 0.1, 0.1}; GLfloat bshiny = 32.0; GLfloat pos[4] = {-8.0, -8.0, -16.0, 0.0}; /* -6 -6 -16 */ GLfloat amb[4] = {0.2, 0.2, 0.2, 0.4}; GLfloat dif[4] = {0.2, 0.2, 0.2, 0.2}; GLfloat spc[4] = {0.0, 0.0, 0.0, 0.0}; if(!wire) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, bcolor); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, bspec); glMateriali (GL_FRONT_AND_BACK, GL_SHININESS, bshiny); } #endif cp->list = glGenLists(1); glNewList(cp->list, GL_COMPILE); if(MI_IS_MONO(mi)) { /* FIXME support mono display */ abort(); } /* wireframe strategy: use stencil buffer, not polygon offset, * because it's impossible to get the right parameters for * glPolygonOffset() reliably */ /* hidden-line removal as per * http://glprogramming.com/red/chapter14.html#name16 */ /* TODO: - reinstate choice of wireframe vs filled - rationalise some of the duplicated code below */ glEnable(GL_STENCIL_TEST); glEnable(GL_DEPTH_TEST); glClear(GL_STENCIL_BUFFER_BIT); glStencilFunc(GL_ALWAYS, 0, 1); glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); glColor3f(1.0, 1.0, 1.0); p=ship_f[cp->which]; this_v=ship_v[cp->which]; /* for debugging - draw axes */ #if 0 glLineWidth(1); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(10,0,0); glEnd(); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,10,0); glEnd(); glBegin(GL_LINES); glVertex3f(0.1,0,0); glVertex3f(0.1,10,0); glEnd(); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,0,10); glEnd(); glBegin(GL_LINES); glVertex3f(0,0.1,0); glVertex3f(0,0.1,10); glEnd(); glBegin(GL_LINES); glVertex3f(0,0.2,0); glVertex3f(0,0.2,10); glEnd(); #endif /* draw the wireframe shape */ while(*p != 0) { count=*p; p++; /* draw outline polygon */ if(count==1) { glBegin(GL_POINTS); } else if(count==2) { /* chunky lines :-) */ glLineWidth(2); glBegin(GL_LINES); } else { glLineWidth(2); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POLYGON); do_normal(this_v[p[0]*3], this_v[p[0]*3+1], this_v[p[0]*3+2], this_v[p[1]*3], this_v[p[1]*3+1], this_v[p[1]*3+2], this_v[p[2]*3], this_v[p[2]*3+1], this_v[p[2]*3+2]); } for (i = 0 ; i < count ; i++) { glVertex3f(this_v[p[i]*3], this_v[p[i]*3+1], this_v[p[i]*3+2]); } glEnd(); glColor3f(0.0, 0.0, 0.0); glStencilFunc(GL_EQUAL, 0, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); /* draw filled polygon */ if(count>=3) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); do_normal(this_v[p[0]*3], this_v[p[0]*3+1], this_v[p[0]*3+2], this_v[p[1]*3], this_v[p[1]*3+1], this_v[p[1]*3+2], this_v[p[2]*3], this_v[p[2]*3+1], this_v[p[2]*3+2]); for (i = 0 ; i < count ; i++) { glVertex3f(this_v[p[i]*3], this_v[p[i]*3+1], this_v[p[i]*3+2]); } glEnd(); } glColor3f(1.0, 1.0, 1.0); glStencilFunc(GL_ALWAYS, 0, 1); glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); /* draw outline polygon */ if(count==1) { glBegin(GL_POINTS); } else if(count==2) { /* chunky lines :-) */ glLineWidth(2); glBegin(GL_LINES); } else { glLineWidth(2); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POLYGON); do_normal(this_v[p[0]*3], this_v[p[0]*3+1], this_v[p[0]*3+2], this_v[p[1]*3], this_v[p[1]*3+1], this_v[p[1]*3+2], this_v[p[2]*3], this_v[p[2]*3+1], this_v[p[2]*3+2]); } for (i = 0 ; i < count ; i++) { glVertex3f(this_v[p[i]*3], this_v[p[i]*3+1], this_v[p[i]*3+2]); } glEnd(); cp->npoints++; p+=count; } glEndList(); }
void Engine::initLight(void) { float ambientLight_0[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float diffuseLight_0[] = { 0.6f, 0.0f, 0.0f, 1.0f }; float specularLight_0[] = { 0.9f, 0.0f, 0.0f, 1.0f }; float position_0[] = { -0.4f, 0.0f, 0.6f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight_0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight_0); glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight_0); glLightfv(GL_LIGHT0, GL_POSITION, position_0); glEnable(GL_LIGHT1); float ambientLight_1[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float diffuseLight_1[] = { 0.0f, 0.6f, 0.0f, 1.0f }; float specularLight_1[] = { 0.0f, 0.9f, 0.0f, 1.0f }; float position_1[] = { 0.0f, 0.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight_1); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight_1); glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight_1); glLightfv(GL_LIGHT1, GL_POSITION, position_1); glEnable(GL_LIGHT2); float ambientLight_2[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float diffuseLight_2[] = { 0.0f, 0.0f, 0.6f, 1.0f }; float specularLight_2[] = { 0.0f, 0.0f, 0.9f, 1.0f }; float position_2[] = { 0.4f, 0.0f, 0.6f, 1.0f }; glLightfv(GL_LIGHT2, GL_AMBIENT, ambientLight_2); glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuseLight_2); glLightfv(GL_LIGHT2, GL_SPECULAR, specularLight_2); glLightfv(GL_LIGHT2, GL_POSITION, position_2); float mcolor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float shine[] = { 0.1f }; float specular[] = { 1.0f }; glMaterialfv(GL_FRONT, GL_SHININESS, shine); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor); }
void myinit() { // GLfloat light_ambient[] = { btScalar(0.2), btScalar(0.2), btScalar(0.2), btScalar(1.0) }; GLfloat light_ambient[] = { btScalar(1.0), btScalar(1.2), btScalar(0.2), btScalar(1.0) }; GLfloat light_diffuse[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0) }; GLfloat light_specular[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0 )}; /* light_position is NOT default value */ GLfloat light_position0[] = { btScalar(1000.0), btScalar(1000.0), btScalar(1000.0), btScalar(0.0 )}; GLfloat light_position1[] = { btScalar(-1.0), btScalar(-10.0), btScalar(-1.0), btScalar(0.0) }; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position0); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); // glShadeModel(GL_FLAT);//GL_SMOOTH); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glClearColor(float(0.7),float(0.7),float(0.7),float(0)); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); static bool m_textureenabled = true; static bool m_textureinitialized = false; if(m_textureenabled) { if(!m_textureinitialized) { glActiveTexture(GL_TEXTURE0); GLubyte* image=new GLubyte[256*256*3]; for(int y=0;y<256;++y) { const int t=y>>5; GLubyte* pi=image+y*256*3; for(int x=0;x<256;++x) { const int s=x>>5; const GLubyte b=180; GLubyte c=b+((s+t&1)&1)*(255-b); pi[0]=255; pi[1]=c; pi[2]=c; pi+=3; } } glGenTextures(1,(GLuint*)&m_texturehandle); glBindTexture(GL_TEXTURE_2D,m_texturehandle); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); gluBuild2DMipmaps(GL_TEXTURE_2D,3,256,256,GL_RGB,GL_UNSIGNED_BYTE,image); delete[] image; m_textureinitialized=true; } // glMatrixMode(GL_TEXTURE); // glLoadIdentity(); // glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,m_texturehandle); } else
//Perform per frame updates void UpdateFrame() { window.Update(); //update balls' position float c = 2.0f*(float)cos(timer.GetTime()/600); metaballs[0].position.x=-4.0f*(float)cos(timer.GetTime()/700) - c; metaballs[0].position.y=4.0f*(float)sin(timer.GetTime()/600) - c; metaballs[1].position.x=5.0f*(float)sin(timer.GetTime()/400) + c; metaballs[1].position.y=5.0f*(float)cos(timer.GetTime()/400) - c; metaballs[2].position.x=-5.0f*(float)cos(timer.GetTime()/400) - 0.2f*(float)sin(timer.GetTime()/600); metaballs[2].position.y=5.0f*(float)sin(timer.GetTime()/500) - 0.2f*(float)sin(timer.GetTime()/400); //increase or decrease density if(window.isKeyPressed(VK_UP) && gridSize<maxGridSize) { gridSize++; cubeGrid.Init(gridSize); } if(window.isKeyPressed(VK_DOWN) && gridSize>minGridSize) { gridSize--; cubeGrid.Init(gridSize); } //pause & unpause if(window.isKeyPressed('P')) { timer.Pause(); } if(window.isKeyPressed('U')) { timer.Unpause(); } //clear the field for(int i=0; i<cubeGrid.numVertices; i++) { cubeGrid.vertices[i].value=0.0f; cubeGrid.vertices[i].normal.LoadZero(); } //evaluate the scalar field at each point VECTOR3D ballToPoint; float squaredRadius; VECTOR3D ballPosition; float normalScale; for(int i=0; i<numMetaballs; i++) { squaredRadius=metaballs[i].squaredRadius; ballPosition=metaballs[i].position; //VC++6 standard does not inline functions //by inlining these maually, in this performance-critical area, //almost a 100% increase in speed is found for(int j=0; j<cubeGrid.numVertices; j++) { //ballToPoint=cubeGrid.vertices[j].position-ballPosition; ballToPoint.x=cubeGrid.vertices[j].position.x-ballPosition.x; ballToPoint.y=cubeGrid.vertices[j].position.y-ballPosition.y; ballToPoint.z=cubeGrid.vertices[j].position.z-ballPosition.z; //get squared distance from ball to point //float squaredDistance=ballToPoint.GetSquaredLength(); float squaredDistance= ballToPoint.x*ballToPoint.x + ballToPoint.y*ballToPoint.y + ballToPoint.z*ballToPoint.z; if(squaredDistance==0.0f) squaredDistance=0.0001f; //value = r^2/d^2 cubeGrid.vertices[j].value+=squaredRadius/squaredDistance; //normal = (r^2 * v)/d^4 normalScale=squaredRadius/(squaredDistance*squaredDistance); //cubeGrid.vertices[j].normal+=ballToPoint*normalScale; cubeGrid.vertices[j].normal.x+=ballToPoint.x*normalScale; cubeGrid.vertices[j].normal.y+=ballToPoint.y*normalScale; cubeGrid.vertices[j].normal.z+=ballToPoint.z*normalScale; } } //toggle wireframe if(window.isKeyPressed('W')) { glPolygonMode(GL_FRONT, GL_LINE); } if(window.isKeyPressed('F')) { glPolygonMode(GL_FRONT, GL_FILL); } //Change color if(window.isKeyPressed(VK_SPACE)) { currentDiffuseColor++; if(currentDiffuseColor==numDiffuseColors) currentDiffuseColor=0; glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseColors[currentDiffuseColor]); window.SetKeyReleased(VK_SPACE); } }
//Set up openGL bool GLInit() { //set viewport int height; if (window.height==0) height=1; else height=window.height; glViewport(0, 0, window.width, height); //reset viewport //set up projection matrix glMatrixMode(GL_PROJECTION); //select projection matrix glLoadIdentity(); //reset gluPerspective(45.0f, (GLfloat)window.width/(GLfloat)height, 1.0f, 100.0f); //load identity modelview glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //other states //shading glShadeModel(GL_SMOOTH); glClearColor( backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); //depth glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); //hints glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //need to normalize! glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); //set up lighting float ambient[]={0.0f, 0.0f, 0.2f, 1.0f}; glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseColors[currentDiffuseColor]); float position[]={-1.0f, 1.0f, 1.0f, 0.0f}; glLightfv(GL_LIGHT1, GL_POSITION, position); float specular[]={1.0f, 1.0f, 1.0f, 1.0f}; glLightfv(GL_LIGHT1, GL_SPECULAR, specular); glEnable(GL_LIGHT1); //set full reflectance glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white); glMaterialfv(GL_FRONT, GL_SPECULAR, white); float shininess=32.0f; glMaterialfv(GL_FRONT, GL_SHININESS, &shininess); return true; }
/** Start an asteroids game. */ void Asteroids::Start() { // Add a player (watcher) to the game world mGameWorld->AddListener(&mPlayer); // Add a score keeper to the game world mGameWorld->AddListener(&mScoreKeeper); // Add this class as a listener of the score keeper mScoreKeeper.AddListener(this); // Add this class as a listener of the game world mGameWorld->AddListener(this); // Add this class as a listener of the player mPlayer.AddListener(this); // Create user interface CreateGUI(); // Create an ambient light to show sprite textures GLfloat ambient_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat diffuse_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light); glEnable(GL_LIGHT1); mSelectedShape = new Shape("ASSETS/selected.shape"); Animation *explosion_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("explosion", 64, 1024, 64, 64, "ASSETS/explosion_fs.raw", "ASSETS/explosion_fs_alpha.raw"); Animation *asteroid1_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("asteroid1", 128, 8192, 128, 128, "ASSETS/asteroid1_fs.raw", "ASSETS/asteroid1_fs_alpha.raw"); Animation *asteroidOre1_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("asteroidOre1", 128, 8192, 128, 128, "ASSETS/asteroidOre1_fs.raw", "ASSETS/asteroidOre1_fs_alpha.raw"); //Animation *droid_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("droid1", ); Animation *spaceship_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("spaceship", 128, 128, 128, 128, "ASSETS/spaceship_fs.raw", "ASSETS/spaceship_fs_alpha.raw"); // Add this as a listener to the world and the keyboard mGameWindow->AddKeyboardListener(this); // Add this as a listener to the world and the mouse mGameWindow->AddMouseListener(this); // Add the selection box to the world mGameWorld->GiveSelectionBox(mSelectionBox); // Create a spaceship and add it to the world //mGameWorld->AddObject(CreateSpaceship()); // Create some asteroids and add them to the world mLevel = 1; mAsteroidCount = 1; int w = mGameDisplay->GetWidth(); int h = mGameDisplay->GetHeight(); cout << "width : " << w; cout << "height : " << h; // creating asteroids for (int i = 0; i < 10; i++) { int x = (rand() % w) - w/2; int y = (rand() % h) - h/2; mGameWorld->AddObject(CreateAsteroid(x,y)); mAsteroidCount++; } //creating ore asteroids for (int i = 0; i < 10; i++) { int x = (rand() % w) - w/2; int y = (rand() % h) - h/2; mGameWorld->AddObject(CreateAsteroidOre(x,y)); mAsteroidCount++; } // creating drones float rAngle = 0; GLVector3f zero(0.0, 0.0, 0.0); for(int i = 0; i < 2; i++){ GLVector3f new_drone_offset(cos(DEG2RAD*rAngle), sin(DEG2RAD*rAngle), 0.0); new_drone_offset.normalize(); GLVector3f drone_position = zero + (new_drone_offset * 20); mGameWorld->AddObject(CreateDrone(drone_position.x,drone_position.y)); rAngle += 360 / 2; } // creaing a single ore for testing mGameWorld->AddObject(CreateOre(100,0)); // Start the game GameSession::Start(); }
// draw the complete scene: void render_data( ) { updates +=1; if (DMSG) { fprintf( FDEBUG, "RENDER::DEBUG::STATUS Display update (%i)\n",updates); } glClear(GL_COLOR_BUFFER_BIT); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); // set up all the lighting in the room glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT0, GL_POSITION, light0Position); glLightfv(GL_LIGHT1, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT1, GL_POSITION, light1Position); glLightfv(GL_LIGHT2, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT2, GL_POSITION, light2Position); glLightfv(GL_LIGHT3, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT3, GL_POSITION, light3Position); glLightfv(GL_LIGHT4, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT4, GL_POSITION, light4Position); glLightfv(GL_LIGHT5, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT5, GL_POSITION, light5Position); glLightfv(GL_LIGHT6, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT6, GL_POSITION, light6Position); glLightfv(GL_LIGHT7, GL_DIFFUSE, light0Color); glLightfv(GL_LIGHT7, GL_POSITION, light7Position); // glViewport(0, 0, w, h); // glMatrixMode(GL_PROJECTION); // glLoadIdentity(); // GLdouble left = (0 - pointOfInterestX) / zoomLevel + pointOfInterestX; // GLdouble right = (WindowW - pointOfInterestX) / zoomLevel + pointOfInterestX; // GLdouble bottom = (WindowH - pointOfInterestY) / zoomLevel + pointOfInterestY; // GLdouble top = (0 - pointOfInterestY) / zoomLevel + pointOfInterestY; // glOrtho(left, right, bottom, top, -1, 1); // glMatrixMode(GL_MODELVIEW); // glLoadIdentity(); // set the viewport to fill the entire window // based on its current dimensions GLsizei w,h; w = glutGet( GLUT_WINDOW_WIDTH ); h = glutGet( GLUT_WINDOW_HEIGHT )==0 ? 1 : glutGet( GLUT_WINDOW_HEIGHT ); // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset coordinate system glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glTranslatef(TransXYZ[0], TransXYZ[1], 0); if( orthoProjection ) { if (w <= h) glOrtho (-VPORT_SIZE, VPORT_SIZE, -VPORT_SIZE*h/w, VPORT_SIZE*h/w, 0.1, 1000); else glOrtho (-VPORT_SIZE*w/h, VPORT_SIZE*w/h, -VPORT_SIZE, VPORT_SIZE, 0.1, 1000); } else { if (w <= h) gluPerspective( 60., h/w, 0.1, 1000. ); else gluPerspective( 60., w/h, 0.1, 1000. ); } glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); // set the eye position, look-at position to be the center of mass of the crystal gluLookAt( VPORT_SIZE/2, VPORT_SIZE/2, eyePosZ, VPORT_SIZE/2, VPORT_SIZE/2,0., 0., 1., 0. ); // uniformly scale the scene: glScalef( (GLfloat)Scale, (GLfloat)Scale, (GLfloat)Scale ); GLfloat scale2 = 1. + Scale2; if( scale2 < MINSCALE ) scale2 = MINSCALE; glScalef( (GLfloat)scale2, (GLfloat)scale2, (GLfloat)scale2 ); //allow free rotation in all 3 dimensions at all times glRotatef(-stheta, 1.0, 0.0, 0.0); glRotatef(sphi, 0.0, 1.0, 0.0); glRotatef(sgamma, 0.0, 0.0, 1.0); // if the background changed colors, redraw the unit cell // in the appropriate color if (backChange) {init_call_lists(1);backChange=0;} // if we changed the particle size, we need to rebuild // the glCallList() since these are constructed as "static" // objects when built. if (pincrease) {init_call_lists(3);pincrease=0;} if (pdecrease) {init_call_lists(3);pdecrease=0;} // place the objects into the scene by using glCallList() if (displayMode == SHOWALL) show_all(1); else if (displayMode == ATOMSONLY) atoms_only(1); // swap the double-buffered framebuffers: glutSwapBuffers( ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // be sure the graphics buffer has been sent: // note: be sure to use glFlush( ) here, not glFinish( ) ! glFlush( ); }
int main (int argc, char * argv[]) { /* int me, numprocs; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); std::cout << "num processors: " << numprocs << std::endl; MPI_Comm_rank(MPI_COMM_WORLD, &me);*/ printf("Instructions:\n" "Hold down the left mouse button to rotate image: \n" "\n" "Hold 'm' while holding down the right mouse to move the end\n" "Hold 't' while holding down the right mouse to rotate the tangent \n" "\n" "Press 'q' to recalculate the thread from initial\n" ); /* initialize glut */ glutInit (&argc, argv); //can i do that? glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(900,900); glutCreateWindow ("Thread"); glutDisplayFunc (DrawStuff); glutMotionFunc (MouseMotion); glutMouseFunc (processMouse); glutKeyboardFunc(processNormalKeys); glutKeyboardUpFunc(processKeyUp); /* create popup menu */ glutCreateMenu (JoinStyle); glutAddMenuEntry ("Exit", 99); glutAttachMenu (GLUT_MIDDLE_BUTTON); /* initialize GL */ glClearDepth (1.0); glEnable (GL_DEPTH_TEST); glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glMatrixMode (GL_PROJECTION); /* roughly, measured in centimeters */ glFrustum (-30.0, 30.0, -30.0, 30.0, 50.0, 500.0); glMatrixMode(GL_MODELVIEW); /* initialize lighting */ glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition); glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor); glEnable (GL_LIGHT0); glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition); glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor); glEnable (GL_LIGHT1); glLightfv (GL_LIGHT2, GL_POSITION, lightThreePosition); glLightfv (GL_LIGHT2, GL_DIFFUSE, lightThreeColor); glEnable (GL_LIGHT2); glLightfv (GL_LIGHT3, GL_POSITION, lightFourPosition); glLightfv (GL_LIGHT3, GL_DIFFUSE, lightFourColor); glEnable (GL_LIGHT3); glEnable (GL_LIGHTING); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); InitStuff (); positions[0](0) = 50.0; positions[0](1) = 0.0; positions[0](2) = 0.0; positions[1](0) = -40.0; positions[1](1) = 80.0; positions[1](2) = 80.0; tangents[0](0) = 0.0; tangents[0](1) = 0.0; tangents[0](2) = 1.0; tangents[1](0) = 1.0; tangents[1](1) = 0.0; tangents[1](2) = 1.0; thread = new Thread(curvature, torsion, length, num, positions, tangents); thread->minimize_energy(); for (int i=0; i < NUM_PTS; i++) { radii[i]=THREAD_RADII; } //initialize images threadStereo = new ThreadStereo(); Point2i start; updateIms(start); vision_draw.resize(0); threadStereo->optimizeThread(vision_draw, start); threadStereo->display(); glutMainLoop (); // return 0; /* ANSI C requires main to return int. */ }
void Light::applyLightColor(GLenum property,GLenum col) { glLightfv(property, col, this->lightColor); }
// this is the code that actually draws the window // it puts a lot of the work into other routines to simplify things void TrainView::draw() { glViewport(0,0,w(),h()); // clear the window, be sure to clear the Z-Buffer too glClearColor(0,0,.3f,0); // background should be blue // we need to clear out the stencil buffer since we'll use // it for shadows glClearStencil(0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH); // Blayne prefers GL_DIFFUSE glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); // prepare for projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); setProjection(); // put the code to set up matrices here // TODO: you might want to set the lighting up differently // if you do, // we need to set up the lights AFTER setting up the projection // enable the lighting glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // top view only needs one light if (tw->topCam->value()) { glDisable(GL_LIGHT1); glDisable(GL_LIGHT2); } else { glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); } // set the light parameters GLfloat lightPosition1[] = {0,1,1,0}; // {50, 200.0, 50, 1.0}; GLfloat lightPosition2[] = {1, 0, 0, 0}; GLfloat lightPosition3[] = {0, -1, 0, 0}; GLfloat yellowLight[] = {0.5f, 0.5f, .1f, 1.0}; GLfloat whiteLight[] = {1.0f, 1.0f, 1.0f, 1.0}; GLfloat blueLight[] = {.1f,.1f,.3f,1.0}; GLfloat grayLight[] = {.3f, .3f, .3f, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition1); glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); glLightfv(GL_LIGHT0, GL_AMBIENT, grayLight); glLightfv(GL_LIGHT1, GL_POSITION, lightPosition2); glLightfv(GL_LIGHT1, GL_DIFFUSE, yellowLight); glLightfv(GL_LIGHT2, GL_POSITION, lightPosition3); glLightfv(GL_LIGHT2, GL_DIFFUSE, blueLight); // now draw the ground plane setupFloor(); glDisable(GL_LIGHTING); drawFloor(200,10); glEnable(GL_LIGHTING); setupObjects(); // we draw everything twice - once for real, and then once for // shadows drawStuff(); // this time drawing is for shadows (except for top view) if (!tw->topCam->value()) { setupShadows(); drawStuff(true); unsetupShadows(); } }
void Light::applyLightPosition(GLenum property,int type) { setLightPosition(type);//0 For Directional, 1 For Positional glLightfv(property, GL_POSITION, this->lightPos); }
/* * OpenGL (GLUT) calls this routine to display the scene */ void display() { int ndm[] = {31,28,31,30,31,30,31,31,30,31,30,31}; int doy = zh/360; int mo,dy,hr,mn; int id; // Sun angle float fh = doy*360.0/365.0; // Light direction float Position[] = {Cos(fh),0.0,Sin(fh),0.0}; // Time of day id = (zh+(int)fh)%360; hr = (id/15)%24; mn = 4*(id%15); // Compute month and day dy = doy+1; for (mo=0;dy>ndm[mo];mo++) dy -= ndm[mo]; fh = (dy-1)/(float)ndm[mo]; mo++; // Erase the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); // Set tranformation glLoadIdentity(); glRotatef(ph,1,0,0); glRotatef(th,0,1,0); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // Enable light 0 glEnable(GL_LIGHT0); // Set position of light 0 glLightfv(GL_LIGHT0,GL_POSITION,Position); // Texture for this month glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,day[mo-1]); // Texture for next month glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,day[mo%12]); // Rotate Z up and inclined 23.5 degrees glRotated(-90,1,0,0); glRotated(-23.5,0,1,0); // Draw planet glColor3f(1,1,1); glEnable(GL_TEXTURE_2D); // Rotation around spin axis glRotated(zh,0,0,1); // Solid gluQuadricDrawStyle(ball,GLU_FILL); // Calculate normals gluQuadricNormals(ball,GLU_SMOOTH); // Apply Textures gluQuadricTexture(ball,1); // Enable shader glUseProgram(shader); // Set textures id = glGetUniformLocation(shader,"DayTex0"); if (id>=0) glUniform1i(id,0); id = glGetUniformLocation(shader,"DayTex1"); if (id>=0) glUniform1i(id,1); id = glGetUniformLocation(shader,"NightTex"); if (id>=0) glUniform1i(id,2); id = glGetUniformLocation(shader,"CloudGloss"); if (id>=0) glUniform1i(id,3); id = glGetUniformLocation(shader,"mode"); if (id>=0) glUniform1i(id,mode); id = glGetUniformLocation(shader,"frac"); if (id>=0) glUniform1f(id,fh); // Draw the ball gluSphere(ball,2.0,72,72); // Shader off glUseProgram(0); // No lighting from here on glDisable(GL_LIGHTING); // Axes glBegin(GL_LINES); glVertex3f(0,0,+2.5); glVertex3f(0,0,-2.5); glEnd(); // Display parameters glColor3f(1,1,1); glWindowPos2i(5,5); Print("FPS=%d Dim=%.1f %d/%.2d %.2d:%.2d UTC %s", FramesPerSecond(),dim,mo,dy,hr,mn,text[mode]); // Render the scene and make it visible ErrCheck("display"); glFlush(); glutSwapBuffers(); }
/* * Draw the solar system */ static void SolarSystem() { int k; // Set up lighting float black[] = {0.0 , 0.0 , 0.0 , 1.0}; float white[] = {1.0 , 1.0 , 1.0 , 1.0}; float pos[] = {0.0 , 0.0 , 0.0 , 1.0}; glEnable(GL_NORMALIZE); glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHT0); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,black); glLightfv(GL_LIGHT0,GL_AMBIENT ,black); glLightfv(GL_LIGHT0,GL_DIFFUSE ,white); glLightfv(GL_LIGHT0,GL_SPECULAR,black); glLightfv(GL_LIGHT0,GL_POSITION,pos); // Draw the sun and planets for (k=0;k<=9;k++) { // Copy variables to simplify expresions double i = planet[k].i; // Inclination double o = planet[k].o; // Longitude of Ascending Node double p = planet[k].p; // Longitude of Perihelion double a = planet[k].a; // Mean distance (AU) double n = planet[k].n; // Daily modtion double e = planet[k].e; // Eccentricity double l = planet[k].l; // Mean longitude // Radius of planet (AU) double r = 6.7e-9*planet[k].R; // Radius (km->AU) if (mode<0 && mag>0) r *= mag; // Magnification if (r>0.3) r = 0.3; // Limit maximum size // Apply keplerian elements to determine orbit glPushMatrix(); if (k>0) { // Calculate true anomaly double M = fmod(day*n+l-p,TWOPI); // Mean anomaly in radians double delta; double v = M; do { delta = v - e*sin(v) - M; v -= delta/(1-e*cos(v)); } while (fabs(delta)>1e-12); // True anomaly v = 2*atan(sqrt((1+e)/(1-e))*tan(0.5*v)); double R = a*(1-e*e)/(1+e*cos(v)); // Orbit radius (AU) double h = v + p - o; // Elliptical angle // Compute and apply location double x = R * (cos(o)*cos(h) - sin(o)*sin(h)*cos(i)); double y = R * (sin(o)*cos(h) + cos(o)*sin(h)*cos(i)); double z = R * (sin(h)*sin(i)); glTranslated(x,y,z); } // Transform and draw planet glPushMatrix(); glRotated(planet[k].th,1,0,0); // Declination glRotated(360*day/planet[k].rot,0,0,1); // Siderial rotation glScaled(r,r,r); // Radius of planet if (k>0 && light) glEnable(GL_LIGHTING); // Lighting for planets DrawPlanet(k); // Draw planet glPopMatrix(); // Draw the moon relative to earth if (k==3) { double R = 1.5*r>planet[10].a ? 1.5*r : planet[10].a; glPushMatrix(); glRotated(360*day/planet[10].rot,0,0,1); // Siderial rotation and orbit is the same glTranslated(R,0,0); // Orbital radius r *= planet[10].R/planet[k].R; // Adjust radius glScaled(r,r,r); DrawPlanet(10); // Draw planet glPopMatrix(); } glPopMatrix(); glDisable(GL_LIGHTING); // Draw orbit if (orbit) { double v; glColor3f(0.3,0.3,0.3); glBegin(GL_LINE_LOOP); for (v=0;v<TWOPI;v+=0.01) { double R = a*(1-e*e)/(1+e*cos(v)); double h = v + p - o; double x = R * (cos(o)*cos(h) - sin(o)*sin(h)*cos(i)); double y = R * (sin(o)*cos(h) + cos(o)*sin(h)*cos(i)); double z = R * (sin(h)*sin(i)); glVertex3d(x,y,z); } glEnd(); } } }
static void pinit(ModeInfo * mi) { morph3dstruct *mp = &morph3d[MI_SCREEN(mi)]; glClearDepth(1.0); glClearColor(0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position0); 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_TWO_SIDE, lmodel_twoside); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glShadeModel(GL_SMOOTH); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); switch (mp->object) { case 2: mp->draw_object = draw_cube; mp->MaterialColor[0] = MaterialRed; mp->MaterialColor[1] = MaterialGreen; mp->MaterialColor[2] = MaterialCyan; mp->MaterialColor[3] = MaterialMagenta; mp->MaterialColor[4] = MaterialYellow; mp->MaterialColor[5] = MaterialBlue; mp->edgedivisions = cubedivisions; mp->Magnitude = 2.0; break; case 3: mp->draw_object = draw_octa; mp->MaterialColor[0] = MaterialRed; mp->MaterialColor[1] = MaterialGreen; mp->MaterialColor[2] = MaterialBlue; mp->MaterialColor[3] = MaterialWhite; mp->MaterialColor[4] = MaterialCyan; mp->MaterialColor[5] = MaterialMagenta; mp->MaterialColor[6] = MaterialGray; mp->MaterialColor[7] = MaterialYellow; mp->edgedivisions = octadivisions; mp->Magnitude = 2.5; break; case 4: mp->draw_object = draw_dodeca; mp->MaterialColor[0] = MaterialRed; mp->MaterialColor[1] = MaterialGreen; mp->MaterialColor[2] = MaterialCyan; mp->MaterialColor[3] = MaterialBlue; mp->MaterialColor[4] = MaterialMagenta; mp->MaterialColor[5] = MaterialYellow; mp->MaterialColor[6] = MaterialGreen; mp->MaterialColor[7] = MaterialCyan; mp->MaterialColor[8] = MaterialRed; mp->MaterialColor[9] = MaterialMagenta; mp->MaterialColor[10] = MaterialBlue; mp->MaterialColor[11] = MaterialYellow; mp->edgedivisions = dodecadivisions; mp->Magnitude = 2.0; break; case 5: mp->draw_object = draw_icosa; mp->MaterialColor[0] = MaterialRed; mp->MaterialColor[1] = MaterialGreen; mp->MaterialColor[2] = MaterialBlue; mp->MaterialColor[3] = MaterialCyan; mp->MaterialColor[4] = MaterialYellow; mp->MaterialColor[5] = MaterialMagenta; mp->MaterialColor[6] = MaterialRed; mp->MaterialColor[7] = MaterialGreen; mp->MaterialColor[8] = MaterialBlue; mp->MaterialColor[9] = MaterialWhite; mp->MaterialColor[10] = MaterialCyan; mp->MaterialColor[11] = MaterialYellow; mp->MaterialColor[12] = MaterialMagenta; mp->MaterialColor[13] = MaterialRed; mp->MaterialColor[14] = MaterialGreen; mp->MaterialColor[15] = MaterialBlue; mp->MaterialColor[16] = MaterialCyan; mp->MaterialColor[17] = MaterialYellow; mp->MaterialColor[18] = MaterialMagenta; mp->MaterialColor[19] = MaterialGray; mp->edgedivisions = icodivisions; mp->Magnitude = 2.5; break; default: mp->draw_object = draw_tetra; mp->MaterialColor[0] = MaterialRed; mp->MaterialColor[1] = MaterialGreen; mp->MaterialColor[2] = MaterialBlue; mp->MaterialColor[3] = MaterialWhite; mp->edgedivisions = tetradivisions; mp->Magnitude = 2.5; break; } if (MI_IS_MONO(mi)) { int loop; for (loop = 0; loop < 20; loop++) mp->MaterialColor[loop] = MaterialGray; } }
// // Display the output image from our vertex and fragment shaders // void DisplayCallback() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); SetUpAndRight(); gluLookAt(mPosition.x,mPosition.y,mPosition.z, mLookAt.x,mLookAt.y,mLookAt.z, mUp.x,mUp.y,mUp.z); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); // Texture 0: surface normal map glActiveTexture(GL_TEXTURE0); surfaceNormTex->Bind(); // Texture 1: surface normal map glActiveTexture(GL_TEXTURE1); surfaceDisplaceTex->Bind(); // Bind the textures we've loaded into openGl to // the variable names we specify in the fragment // shader. shader->SetTexture("normalTex", 0); shader->SetTexture("displacementTex", 1); shader->SetTexture("colorTex", 2); // Invoke the shader. Now OpenGL will call our // shader programs on anything we draw. shader->Bind(); if(mesh) { shader->SetUniform("normalMapping", -1.0); shader->SetUniform("displacementMapping", -1.0); shader->SetUniform("colorMapping", 1.0); glPushMatrix(); // Pay attention to scale STVector3 size_vector=gBoundingBox.second-gBoundingBox.first; float maxSize=(std::max)((std::max)(size_vector.x,size_vector.y),size_vector.z); glScalef(3.0f/maxSize,3.0f/maxSize,3.0f/maxSize); glTranslatef(-gMassCenter.x,-gMassCenter.y,-gMassCenter.z); for(unsigned int id=0;id<gTriangleMeshes.size();id++) { gTriangleMeshes[id]->Draw(smooth); } glPopMatrix(); } else { if(normalMapping){ shader->SetUniform("displacementMapping", -1.0); shader->SetUniform("normalMapping", 1.0); shader->SetUniform("colorMapping", -1.0); } else{ shader->SetUniform("displacementMapping", 1.0); shader->SetUniform("normalMapping", -1.0); shader->SetUniform("colorMapping", -1.0); shader->SetUniform("TesselationDepth", TesselationDepth); } if(gManualTriangleMesh) gManualTriangleMesh->Draw(smooth); if(gTriangleMeshes.size()) { for(unsigned int id=0;id<gTriangleMeshes.size();id++) { gTriangleMeshes[id]->Draw(smooth); } } } shader->UnBind(); glActiveTexture(GL_TEXTURE0); surfaceNormTex->UnBind(); glActiveTexture(GL_TEXTURE1); surfaceDisplaceTex->UnBind(); glutSwapBuffers(); }
void display(void) { float mview[16],imview[16]; char buffer[128]; shadowmap(); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,4.0 / 3.0,1,2048); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camerapos[0],camerapos[1],camerapos[2], cameradir[0],cameradir[1],cameradir[2], 0,0,1); glLightfv(GL_LIGHT0,GL_POSITION,lightpos); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); // draw model glBindTexture(GL_TEXTURE_2D,texturemodel); glPushMatrix(); glTranslatef(objpos[0],objpos[1],objpos[2]); glRotatef(modelangle,0,0,1); glCallList(modellist); glPopMatrix(); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_LIGHTING); glBindTexture(GL_TEXTURE_2D,textureground); // draw ground glCallList(groundlist); glDisable(GL_TEXTURE_2D); glPushMatrix(); // light sources glTranslatef(lightpos[0],lightpos[1],lightpos[2]); glColor4f(0,1,0,1); glCallList(lightlist); glColor4f(1,1,1,1); glPopMatrix(); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glGetFloatv(GL_MODELVIEW_MATRIX,mview); MatrixInverse(mview,imview); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(0.5,0.5,0); glScalef(0.5,0.5,1.0); glOrtho(-modelsize,modelsize,-modelsize,modelsize,-1,1); gluLookAt(lightpos[0],lightpos[1],lightpos[2], objpos[0],objpos[1],objpos[2], 0,1,0); glMultMatrixf(imview); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); // shadow glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_COLOR); glBindTexture(GL_TEXTURE_2D,textureshadow); glCallList(groundlist); glDisable(GL_BLEND); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1,1,-1,1,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4f(1,1,1,1); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); sprintf(buffer,"fps: %.2f",getfps()); drawstring(-0.95,0.95,buffer); glEnable(GL_DEPTH_TEST); glutSwapBuffers(); }
/* display */ void Display(void) { if (solid) { glEnable(GL_LIGHTING); // Draw polygon interiors with lighting enabled. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Draw polygon interiors. glEnable(GL_POLYGON_OFFSET_FILL); // Turn on offset for filled polygons. glPolygonOffset(1, 1); // Set polygon offset amount. } else { glDisable(GL_LIGHTING); // Draw polygon outlines with lighting disabled. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Draw polygon outlines. glColor4f(1.0, 1.0, .5, 1); // Draw the outlines in black. } //clean the scene glClearColor(0.1, 0.1, 0.1, 1.0); //set background glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //set matrix mode to GL_MODELVIEW glMatrixMode(GL_MODELVIEW); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glColor4f(1.0f, 0.4f, 0.0f, 1.0f); glPushMatrix(); glRotatef(rotation_x, 0.0, 1.0, 0.0); glRotatef(rotation_y, 1.0, 0.0, 0.0); if (drawFloor_b) { drawFloor(7.0f, 7.0f, 0.8f); } if (test_light) { glutSolidSphere(3.0, 16, 16); } if (ellipsoid) { glBegin(GL_POINTS); glColor4f(1.0, 1, 0, 1); glVertex3fv(eye); glEnd(); displayElipsoidDemo(); } if (refraction) { refractionPlaneDome(); } if (surfaceRenderDemo) { eye[1] += moveright; displayElipsoidDemo(); // GLfloat a[3]={1,1,0}, b[3]={0,1,2}, c[3]={0,1,0}; // drawSurfaceRenderWithTexture(a,b,c,eye,0); glBindTexture ( GL_TEXTURE_2D, texture_id[current_texture] ); glBegin ( GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3f( floor_d, floor_l, -floor_d); glTexCoord2f(0.0f, 1.0f); glVertex3f( -floor_d, floor_l, -floor_d); glTexCoord2f(0.0f, 0.0f); glVertex3f( -floor_d, floor_l, floor_d); glTexCoord2f(1.0f, 0.0f); glVertex3f( floor_d, floor_l, floor_d); glEnd(); glutPostRedisplay(); // glBegin ( GL_TRIANGLES); // glTexCoord2f(1.0f, .5f); glVertex3f( floor_d, floor_l-3, -floor_d); // glTexCoord2f(.7f, .5f); glVertex3f( -floor_d, floor_l-3, -floor_d); // glTexCoord2f(1.0f, 0.0f); glVertex3f( floor_d, floor_l-3, floor_d); // glEnd(); // glutSwapBuffers(); } /** #p: ray plane basic refraction demo */ if (rayplane) { glPushMatrix(); //glLoadIdentity(); glScalef(1.0f, 1.0f, 1.0f); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); glutWireSphere(R, 20, 20); drawDemoRaySemisphere(); glPopMatrix(); } /** #p ends */ /** #o circle plane basic refraction demo*/ if (circleplane) { glPushMatrix(); //glLoadIdentity(); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); glutWireSphere(R, 20, 20); drawDemoCircleSemisphere(numberOfDots); glPopMatrix(); } glPopMatrix(); glutSwapBuffers(); };
void LightPositioning(void) { glLightfv(GL_LIGHT0, GL_POSITION, light_position); }
void drawScene(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); HalfLifeCrowbar();//this pront crowbar (only if HALF is != 0) gluLookAt (eye[0], eye[1], eye[2], eye_ed[0], eye_ed[1], eye_ed[2], 0.0, 1.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_EMISSION, light_0_col); // //this print a little sphere to localize the sun (now is outside the dome) // glPushMatrix(); // glTranslatef(light_pos[0],light_pos[1],light_pos[2]); //to see where the light is // glutSolidSphere(0.1,10,10); // glPopMatrix(); //the 2 big tree in front of the house printTree(20,-20,12,0); printTree(-20,-20,12,0); //randome tree in the world printTree(-30,45,10,1); printTree(-20,33,8,2); printTree(-10,-49,3,3); printTree(30,60,5,0); printTree(-25,75,6,2); printTree(35,30,7,0); printTree(14,-60,8,2); printTree(13,-40,7,0); printTree(-14,54,10,1); printTree(-20,19,8,2); printTree(24,30,5,0); printTree(-21,27,6,2); printTree(19,22,7,0); printTree(50,40,7,0); printTree(-50,15,10,1); printTree(-50,10,8,2); printTree(-50,-19,3,3); printTree(50,30,5,0); printTree(-55,25,6,2); printTree(55,30,7,0); printTree(54,-30,8,2); printTree(-70,69,8,2); printTree(94,80,5,0); printTree(-71,87,6,2); printTree(69,72,7,0); printTree(-59,-80,7,0); printTree(-60,-65,10,1); printTree(60,-70,8,2); printTree(50,-89,3,3); printTree(57,-60,5,0); printTree(-65,25,6,2); printTree(-55,80,7,0); printTree(-54,-70,8,2); //bush near the swimming pool printTree(-10,17,3,3); printTree(10,17,3,3); printTree(-10,33,3,3); printTree(10,33,3,3); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); printHouse(0,0,15,25,8); //new grass near the house glPushMatrix(); glTranslatef(0,0.001,0); printGround(0,5,70,60,texGrass2); glPopMatrix(); //swimming pool glPushMatrix(); glTranslatef(0,0.003,0); printGround(0,25,12,20,texSwim); glPopMatrix(); //ground under the swimmingpool glPushMatrix(); glTranslatef(0,0.002,0); printGround(0,25,14,22,texStoneGround); glPopMatrix(); //bush near the path printTree(-5,-10,3,3); printTree(5,-10,3,3); printTree(-5,-20,3,3); printTree(5,-20,3,3); //the path from gate to the door glPushMatrix(); glTranslatef(0,0.002,0); printGround(0,-19,24,7,texPath); glPopMatrix(); //fence printFence(-30,-30,-30,40); printFence(-30,40,30,40); printFence(30,40,30,-30); //front fence and gate printFence(30,-30,5,-30); printFence(-5,-30,-30,-30); printGate(-5,-30,5,-30); //hedge glPushMatrix(); glTranslatef(0,0,38); printHedge(59,2,5); glPopMatrix(); glPushMatrix(); glTranslatef(28,0,5); glRotatef(90,0,1,0); printHedge(69,2,5); glPopMatrix(); glPushMatrix(); glTranslatef(-28,0,5); glRotatef(90,0,1,0); printHedge(69,2,5); glPopMatrix(); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); underTheDome();// print the sky printGrass(); glFlush(); glutSwapBuffers(); locateCamera(); }
int main(int argc, char* argv[]) { /****************************************/ /* Initialize GLUT and create window */ /****************************************/ glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowPosition( 50, 50 ); glutInitWindowSize( 300, 300 ); main_window = glutCreateWindow( "GLUI Example 3" ); glutDisplayFunc( myGlutDisplay ); glutReshapeFunc( myGlutReshape ); glutKeyboardFunc( myGlutKeyboard ); glutMotionFunc( myGlutMotion ); glutMouseFunc( myGlutMouse ); /****************************************/ /* Set up OpenGL lights */ /****************************************/ glEnable(GL_LIGHTING); glEnable( GL_NORMALIZE ); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); glLightfv(GL_LIGHT1, GL_POSITION, light1_position); /****************************************/ /* Enable z-buferring */ /****************************************/ glEnable(GL_DEPTH_TEST); /****************************************/ /* Here's the GLUI code */ /****************************************/ printf( "GLUI version: %3.2f\n", GLUI_Master.get_version() ); glui = GLUI_Master.create_glui( "GLUI", 0, 400, 50 ); /* name, flags, x, and y */ new GLUI_StaticText( glui, "GLUI Example 3" ); obj_panel = new GLUI_Panel(glui, "Object" ); /***** Control for the object type *****/ GLUI_Panel *type_panel = new GLUI_Panel( obj_panel, "Type" ); radio = new GLUI_RadioGroup(type_panel,&obj_type,4,control_cb); new GLUI_RadioButton( radio, "Sphere" ); new GLUI_RadioButton( radio, "Torus" ); new GLUI_RadioButton( radio, "Teapot" ); checkbox = new GLUI_Checkbox(obj_panel, "Wireframe", &wireframe, 1, control_cb ); spinner = new GLUI_Spinner( obj_panel, "Segments:", &segments); spinner->set_int_limits( 3, 60 ); spinner->set_alignment( GLUI_ALIGN_RIGHT ); scale_spinner = new GLUI_Spinner( obj_panel, "Scale:", &scale); scale_spinner->set_float_limits( .2f, 4.0 ); scale_spinner->set_alignment( GLUI_ALIGN_RIGHT ); new GLUI_Separator( obj_panel ); edittext = new GLUI_EditText( obj_panel, "Text:", text ); edittext->set_w( 150 ); /******** Add some controls for lights ********/ GLUI_Panel *light0 = new GLUI_Panel( glui, "Light 1" ); GLUI_Panel *light1 = new GLUI_Panel( glui, "Light 2" ); new GLUI_Checkbox( light0, "Enabled", &light0_enabled, LIGHT0_ENABLED_ID, control_cb ); light0_spinner = new GLUI_Spinner( light0, "Intensity:", &light0_intensity, LIGHT0_INTENSITY_ID, control_cb ); light0_spinner->set_float_limits( 0.0, 1.0 ); new GLUI_Checkbox( light1, "Enabled", &light1_enabled, LIGHT1_ENABLED_ID, control_cb ); light1_spinner = new GLUI_Spinner( light1, "Intensity:", &light1_intensity, LIGHT1_INTENSITY_ID, control_cb ); light1_spinner->set_float_limits( 0.0, 1.0 ); light1_spinner->disable(); /* Disable this light initially */ /****** Add a grayed-out counter *****/ GLUI_EditText *counter_edittext = new GLUI_EditText( glui, "Count:", &counter ); counter_edittext->disable(); /****** Button to Open Command Line Window ******/ open_console_btn = new GLUI_Button(glui, "Open Console", OPEN_CONSOLE_ID, pointer_cb); /****** A 'quit' button *****/ new GLUI_Button(glui, "Quit", 0,(GLUI_Update_CB)exit ); /**** Link windows to GLUI, and register idle callback ******/ glui->set_main_gfx_window( main_window ); /* We register the idle callback with GLUI, not with GLUT */ GLUI_Master.set_glutIdleFunc( myGlutIdle ); /**** Regular GLUT main loop ****/ glutMainLoop(); return EXIT_SUCCESS; }
void CFlowEntropyViewerWin::_BeginDisplay() { glClearColor(1.0, 1.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); // flip the Z axis glScalef(1.0f, 1.0f, -1.0f); float fMaxDim = max(pf3DEntropyField.iWidth, max(pf3DEntropyField.iHeight, pf3DEntropyField.iDepth)); glScalef( pf3DEntropyField.iWidth / fMaxDim, pf3DEntropyField.iHeight / fMaxDim, pf3DEntropyField.iDepth / fMaxDim); glPushAttrib(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glColor4f(0.70f, 0.70f, 0.70f, 1.0f); glutWireCube(2.0); glPopAttrib(); // glPushAttrib(GL_DEPTH_BUFFER_BIT); switch(iDataName) { case DATA_NAME_ISABEL: glPushAttrib(GL_TEXTURE_BIT); glBindTexture(GL_TEXTURE_2D, cData.cFusion.t2dMap); glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex3i(-1,-1,-1); glTexCoord2i(1, 0); glVertex3i( 1,-1,-1); glTexCoord2i(1, 1); glVertex3i( 1, 1,-1); glTexCoord2i(0, 1); glVertex3i(-1, 1,-1); glEnd(); glPopAttrib(); // glPushAttrib(GL_TEXTURE_BIT); break; case DATA_NAME_EARTHQUAKE: { glPushAttrib(GL_CURRENT_BIT); glPushAttrib(GL_COLOR_BUFFER_BIT); glPushAttrib(GL_ENABLE_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); static float pfColor[] = {0.4f, 0.4f, 0.4f, 1.0f}; glColor4fv(pfColor); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pfColor); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glShadeModel(GL_SMOOTH); glPushMatrix(); glLoadIdentity(); static float pfLight0Pos[4] = {0.0, 0.0, -1.0, 0.0}; glLightfv(GL_LIGHT0, GL_POSITION, pfLight0Pos); glPopMatrix(); glCallList(cData.cEarthquake.lid); glPopAttrib(); glPopAttrib(); glPopAttrib(); } break; } glPushAttrib(GL_ENABLE_BIT); glEnable(GL_DEPTH_TEST); glPushMatrix(); glTranslatef(-1.0f, -1.0f, -1.0f); // plot the origin glColor4f(1.0f, 1.0f, 1.0f, 1.0f); _DrawString3D("0"); double pdScales[3]; pdScales[0] = 1.0/(double)this->pf3DEntropyField.iWidth; pdScales[1] = 1.0/(double)this->pf3DEntropyField.iHeight; pdScales[2] = 1.0/(double)this->pf3DEntropyField.iDepth; double dLength = 33.0; // calculate the vector for(int k =0; k < 3; k++) // direction { double pdColor[4]; memset(pdColor, 0, sizeof(pdColor)); pdColor[k] = 1.0; pdColor[3] = 1.0; glColor4dv(pdColor); double pdDir[3]; memset(pdDir, 0, sizeof(pdDir)); pdDir[k] = dLength * pdScales[k]; glBegin(GL_LINES); glVertex3d(0.0, 0.0, 0.0); glVertex3dv(pdDir); double dOffsetLength = dLength * 0.25; double pdDirOffset[3]; for(int j = 0; j < 2; j++) { for(int i = 0; i< 3; i++) pdDirOffset[i] = dOffsetLength * pdScales[i]; pdDirOffset[k] *= -1.0; pdDirOffset[(k + j + 1)%3] = 0.0; for(int i = 0; i< 3; i++) pdDirOffset[i] = pdDir[i] + pdDirOffset[i]; glVertex3dv(pdDir); glVertex3dv(pdDirOffset); } glEnd(); static char* pszDir[3] = { "X", "Y", "Z", }; _DrawString3D(pszDir[k], pdDir[0], pdDir[1], pdDir[2]); } glPopMatrix(); glPopAttrib(); // glPushAttrib(GL_ENABLE_BIT); ////////////////////////////////////////// // sort the line centroids static double pdModelViewMatrix[16]; glGetDoublev(GL_MODELVIEW_MATRIX, pdModelViewMatrix); cStreamline._SortSlab(iNrOfSlices, pdModelViewMatrix, tProjectionMatrix, piViewport); CClipVolume::_Create(); ////////////////////////////////////////// switch(iRenderMode) { case RENDER_MODE_ENTROPY_FIELD: glUseProgramObjectARB( pidRayIntegral); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fWindowWidth", (float)piViewport[2]); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fWindowHeight", (float)piViewport[3]); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fThicknessGain", fThicknessGain); SET_1I_VALUE_BY_NAME( pidRayIntegral, "t2dPrevLayer", 0); SET_1I_VALUE_BY_NAME( pidRayIntegral, "t3dVolume", 1); SET_1I_VALUE_BY_NAME( pidRayIntegral, "t1dTf", 2); SET_1I_VALUE_BY_NAME( pidRayIntegral, "t2dClipVolume", 4); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fTfDomainMin", fTfDomainMin); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fTfDomainMax", fTfDomainMax); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fDataValueMin", 0); SET_1F_VALUE_BY_NAME( pidRayIntegral, "fDataValueMax", fMaxEntropy); break; case RENDER_MODE_STREAMLINES_IMPORTANCE_CULLING: glUseProgramObjectARB( pidImportanceFilling); SET_1F_VALUE_BY_NAME( pidImportanceFilling, "fWindowWidth", (float)piViewport[2]); SET_1F_VALUE_BY_NAME( pidImportanceFilling, "fWindowHeight", (float)piViewport[3]); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "t2dPrevLayer", 0); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "t3dVolume", 1); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "t2dLineFlag", 3); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "t2dClipVolume", 4); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "t2dsDepth", 5); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "t1dTf", 2); SET_1F_VALUE_BY_NAME( pidImportanceFilling, "fTfDomainMin", fTfDomainMin); SET_1F_VALUE_BY_NAME( pidImportanceFilling, "fTfDomainMax", fTfDomainMax); SET_1F_VALUE_BY_NAME( pidImportanceFilling, "fDataValueMin", 0); SET_1F_VALUE_BY_NAME( pidImportanceFilling, "fDataValueMax", fMaxEntropy); SET_4FV_VALUE_BY_NAME( pidImportanceFilling, "v4ClippingPlaneOutsideColor", 1, (float*)&cClippingPlaneOutsideProp.v4Color); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "ibIsClippingPlaneOutsideColorMono",cClippingPlaneOutsideProp.ibMonoColor); SET_4FV_VALUE_BY_NAME( pidImportanceFilling, "v4ClippingPlaneInsideColor", 1, (float*)&cClippingPlaneInsideProp.v4Color); SET_1I_VALUE_BY_NAME( pidImportanceFilling, "ibIsClippingPlaneInsideColorMono", cClippingPlaneInsideProp.ibMonoColor); glUseProgramObjectARB( pidImportanceCulling); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fWindowWidth", (float)piViewport[2]); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fWindowHeight", (float)piViewport[3]); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fThicknessGain", fThicknessGain); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fOcclusionSaturation", fOcclusionSaturation); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "t2dPrevLayer", 0); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "t3dVolume", 1); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "t1dTf", 2); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "t2dClipVolume", 4); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "t2dsDepth", 5); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fClipVolumeOutsideThreshold", cClippingPlaneOutsideProp.fThreshold); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fClipVolumeInsideThreshold", cClippingPlaneInsideProp.fThreshold); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fTfDomainMin", fTfDomainMin); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fTfDomainMax", fTfDomainMax); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fDataValueMin", 0); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fDataValueMax", fMaxEntropy); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fDashPeriod", float(cStreamline.cDash.iPeriod) ); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fDashOffset", cStreamline.cDash.fOffset); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fDashThreshold", cStreamline.cDash.fThreshold); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "ibIsEntropyDependentDashed", cStreamline.cDash.ibIsEntropyDependent); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "ibIsLightingEnabled", ibIsLightingEnabled ); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "iMaxDistanceToNeighbors_screen", iMaxDistanceToNeighbors_screen); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "ibIsGlyphEnabled", cStreamline.cGlyph.ibIsEnabled); SET_1I_VALUE_BY_NAME( pidImportanceCulling, "iGlyphStep", cStreamline.cGlyph.iStep); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fGlyphLength", cStreamline.cGlyph.fLength); SET_1F_VALUE_BY_NAME( pidImportanceCulling, "fGlyphWidth", cStreamline.cGlyph.fWidth); float pfAmbient[4]; float pfDiffuse[4]; float pfSpecular[4]; for(int i = 0; i < 4; i++) { pfAmbient[i] = cMaterial.fAmbient; pfDiffuse[i] = cMaterial.fDiffuse; pfSpecular[i] = cMaterial.fSpecular; } glMaterialfv(GL_FRONT, GL_AMBIENT, pfAmbient); glMaterialfv(GL_FRONT, GL_DIFFUSE, pfDiffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, pfSpecular); glMaterialf(GL_FRONT, GL_SHININESS, cMaterial.fShininess); break; } glUseProgramObjectARB(0); ////////////////////////////////////////// // bind the volume, range, and the lookup table as textures glActiveTexture(GL_TEXTURE0 + 1); glBindTexture(GL_TEXTURE_3D, t3dEntropyField); glActiveTexture(GL_TEXTURE0 + 2); glBindTexture(GL_TEXTURE_1D, t1dTf); glActiveTexture(GL_TEXTURE0 + 3); glBindTexture(CDvrWin2::cColor.eTarget, CDvrWin2::cColor.t2d); glActiveTexture(GL_TEXTURE0 + 4); glBindTexture(CClipVolume::cTexture.eTarget, CClipVolume::cTexture.t2d); glActiveTexture(GL_TEXTURE0 + 5); glBindTexture(CDvrWin2::cDepth.eTarget, CDvrWin2::cDepth.t2d); glActiveTexture(GL_TEXTURE0); }
void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); //update the plane's camera update_view(); //draw the mountain mountain_display(); //rotate sun and moon glRotatef(sun*radiansToDegrees , 0,-1,0); //translate and draw sun glTranslatef(5,1,0); GLfloat sunAmbient[] = {0.5,0.5,0.5,1}; float sunIntensity = sin(sun)*2; GLfloat sunColor[] = {sunIntensity,sunIntensity,sunIntensity*0.8,1}; GLfloat sunPos[] = {0,0,0,1.0}; glLightfv(GL_LIGHT0, GL_POSITION, sunPos); glLightfv(GL_LIGHT0, GL_AMBIENT, sunAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, sunColor); glLightfv(GL_LIGHT0, GL_SPECULAR, sunColor); GLfloat sunamb[] = {1.0,1.0,1.0,1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, sunamb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, sunamb); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, sunamb); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0); glBegin(GL_QUADS); glVertex3f(0.0,1.0,1.0); glVertex3f(0.0,-1.0,1.0); glVertex3f(0.0,-1.0,-1.0); glVertex3f(0.0,1.0,-1.0); glEnd(); //translate and draw moon glTranslatef(-10,0,0); GLfloat moonAmbient[] = {0.5,0.5,0.5,1}; float moonIntensity = -sin(sun); GLfloat moonColor[] = {moonIntensity,moonIntensity,moonIntensity,1}; GLfloat moonPos[] = {0,0,0,1.0}; glLightfv(GL_LIGHT1, GL_POSITION, moonPos); glLightfv(GL_LIGHT1, GL_AMBIENT, moonAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, moonColor); glLightfv(GL_LIGHT1, GL_SPECULAR, moonColor); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, sunamb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, sunamb); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, sunamb); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0); glBegin(GL_QUADS); glVertex3f(0.0,0.5,0.5); glVertex3f(0.0,-0.5,0.5); glVertex3f(0.0,-0.5,-0.5); glVertex3f(0.0,0.5,-0.5); glEnd(); glFlush(); glutSwapBuffers(); glutPostRedisplay(); }
void Window::setAmbientLight(){ GLfloat light_DiffAndAmb[4] = {1.f, 1.f, 1.f, 1.f}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_DiffAndAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_DiffAndAmb); }
void ExplosionDemo::display() { const static GLfloat lightPosition[] = {1,-1,0,0}; const static GLfloat lightPositionMirror[] = {1,1,0,0}; // Update the transform matrices of each box in turn for (Box *box = boxData; box < boxData+boxes; box++) { box->calculateInternals(); box->isOverlapping = false; } // Update the transform matrices of each ball in turn for (Ball *ball = ballData; ball < ballData+balls; ball++) { // Run the physics ball->calculateInternals(); } // Clear the viewport and set the camera direction RigidBodyApplication::display(); // Render each element in turn as a shadow glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glPushMatrix(); glMultMatrixf(floorMirror); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); for (Box *box = boxData; box < boxData+boxes; box++) { box->render(); } for (Ball *ball = ballData; ball < ballData+balls; ball++) { ball->render(); } glPopMatrix(); glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); // Draw some scale circles glColor3f(0.75, 0.75, 0.75); for (unsigned i = 1; i < 20; i++) { glBegin(GL_LINE_LOOP); for (unsigned j = 0; j < 32; j++) { float theta = 3.1415926f * j / 16.0f; glVertex3f(i*cosf(theta),0.0f,i*sinf(theta)); } glEnd(); } glBegin(GL_LINES); glVertex3f(-20,0,0); glVertex3f(20,0,0); glVertex3f(0,0,-20); glVertex3f(0,0,20); glEnd(); // Render each shadow in turn glEnable(GL_BLEND); glColor4f(0,0,0,0.1f); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for (Box *box = boxData; box < boxData+boxes; box++) { box->renderShadow(); } for (Ball *ball = ballData; ball < ballData+balls; ball++) { ball->renderShadow(); } glDisable(GL_BLEND); // Render the boxes themselves glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, lightPositionMirror); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); for (Box *box = boxData; box < boxData+boxes; box++) { box->render(); } for (Ball *ball = ballData; ball < ballData+balls; ball++) { ball->render(); } glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // Finish the frame, rendering any additional information drawDebug(); }