// Render the actual scene void terrain::render() { // Enable depth testing glEnable(GL_DEPTH_TEST); // Enable automatic normalization of normals glEnable(GL_NORMALIZE); // Clear the screen glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Nothing to do if we are not properly initialized if (!initialized) return; // Setup perspective and modelview matrix setup_projection(); // Setup light setup_light(); // Render the solid terrain with lighting and texture mapping if (show_solid) render_solid_terrain(); // Render the outline of the terrain if (show_wireframe) render_wireframe_terrain(); // Eventually render level lines if (show_levels) render_level_lines(); }
void example_3d_primitives::render() { glEnable(GL_DEPTH_TEST); // Clear the screen glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Setup a perspective projection and lighting setup_projection(); setup_light(); glScaled(0.4, 0.4, 0.4); // Move 5 units to the left, save the current transformation // and show a rotated tetrahedron glTranslated(-5, 0, 0); glPushMatrix(); glRotated(angle, 0, 1, 0); glColor3d(1, 1, 0); render_tetrahedron(); glPopMatrix(); // Move 3 units to the right, save the current transformation // and show a rotated cylinder glTranslated(3, 0, 0); glPushMatrix(); glRotated(angle, 1, 0, 0); glColor3d(0, 1, 0); render_cylinder(); glPopMatrix(); // Move 3 units to the right, save the current transformation // and show a rotated cube glTranslated(3, 0, 0); glPushMatrix(); glRotated(angle, 0, 1, 1); glColor3d(1, 0, 0); render_cube(); glPopMatrix(); // Move 3 units to the right, save the current transformation // and show a rotated sphere glTranslated(3, 0, 0); glPushMatrix(); glRotated(angle, 0, 1, 0); glColor3d(0, 0, 1); render_sphere(); glPopMatrix(); }
void myinit() { glClearColor(0.0, 0.0, 0.0, 1.0); /*set the background color BLACK */ /*Clear the Depth & Color Buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); /*---Create a light source----*/ glEnable(GL_LIGHTING); setup_light(); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); glEnable(GL_NORMALIZE); /*Enable mornalization */ /*---Create quadratic objects---*/ if (sphere == NULL) { sphere = gluNewQuadric(); gluQuadricDrawStyle(sphere, GLU_FILL); gluQuadricNormals(sphere, GLU_SMOOTH); } if (cylind == NULL) { cylind = gluNewQuadric(); gluQuadricDrawStyle(cylind, GLU_FILL); gluQuadricNormals(cylind, GLU_SMOOTH); } if (disk == NULL) { disk = gluNewQuadric(); gluQuadricDrawStyle(disk, GLU_FILL); gluQuadricNormals(disk, GLU_SMOOTH); } /*-----Create Texture -----*/ make_check(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glGenTextures(4, textName); glBindTexture(GL_TEXTURE_2D, textName[0]); 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_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkboard); /*-----Create another texture ----*/ Create_Texture_Star(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, textName[1]); 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_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, star); brick_pattern(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, textName[2]); 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_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, brick); Create_Texture_Waterwave(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, textName[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_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, waterwave); /*----Set up fog conditions ---*/ glEnable(GL_FOG); /*enable fog fade */ setup_fog(); /*---- Compute cos(5.0) and sin(5.0) ----*/ cv = cos(5.0*PI / 180.0); sv = sin(5.0*PI / 180.0); /*---- Copy eye position ---*/ eye[0] = Eye[0]; eye[1] = Eye[1]; eye[2] = Eye[2]; }
void idle_func() { ds += 0.001; if (ds>1.0) ds = ds - 1.0; if (turn_fog == 1) { fog_color[0] += 0.001; fog_color[1] += 0.001; fog_color[2] += 0.001; if (lit4_diffuse[0] > 0.7) fog_color[0] *= -1.0; else if (lit4_diffuse[0] < 0.1) fog_color[0] *= -1.0; if (lit4_diffuse[1] > 0.7) fog_color[1] *= -1.0; else if (lit4_diffuse[1] < 0.1) fog_color[1] *= -1.0; if (lit4_diffuse[2] > 0.7) fog_color[2] *= -1.0; else if (lit4_diffuse[2] < 0.1) fog_color[2] *= -1.0; } else { fog_color[0] = 0.15; fog_color[1] = 0.20; fog_color[2] = 0.20; } bld_ang += 5.0; lit4_diffuse[0] += lit_color4[0]; lit4_diffuse[1] += lit_color4[1]; lit4_diffuse[2] += lit_color4[2]; lit5_diffuse[0] += lit_color5[0]; lit5_diffuse[1] += lit_color5[1]; lit5_diffuse[2] += lit_color5[2]; if (bld_ang>360.0) { bld_ang -= 360.0; } if (lit4_diffuse[0]>1.0) lit_color4[0] *= -1.0; else if (lit4_diffuse[0]<0.1) lit_color4[0] *= -1.0; if (lit4_diffuse[1]>1.0) lit_color4[1] *= -1.0; else if (lit4_diffuse[1]<0.1) lit_color4[1] *= -1.0; if (lit4_diffuse[2]>1.0) lit_color4[2] *= -1.0; else if (lit4_diffuse[2]<0.1) lit_color4[2] *= -1.0; if (lit5_diffuse[0]>1.0) lit_color5[0] *= -1.0; else if (lit5_diffuse[0]<0.1) lit_color5[0] *= -1.0; if (lit5_diffuse[1]>1.0) lit_color5[1] *= -1.0; else if (lit5_diffuse[1]<0.1) lit_color5[1] *= -1.0; if (lit5_diffuse[2]>1.0) lit_color5[2] *= -1.0; else if (lit5_diffuse[2]<0.1) lit_color5[2] *= -1.0; setup_light(); setup_fog(); display(); /* show the scene again */ }