Exemple #1
0
void Cell::load(int layer) {
    assert(layer >= 0 && layer < numLayers);
    
    displayList[layer] = glGenLists(1);
    glNewList(displayList[layer], GL_COMPILE);

    for (int y = 0; y < CELL_SIZE; y++) {
	for (int x = 0; x < CELL_SIZE; x++) {

		glBindTexture(GL_TEXTURE_2D, textures->get("grass")); 

	    // TODO should merge identical neighbors to reduce calls
	    glPushMatrix();
	    glTranslatef((float)x, (float)y, 0.0f);
	    
        if (layer == 0)
		    texturedPlane(1.0);
	    else 
		    texturedCube(1.0);
	    
        glPopMatrix();
	}
    }

    glEndList();

    inMemory = true;
}
Exemple #2
0
// draws the asteroids
void ship::Refresh()
{
	

	for (int i = 0; i < astr.size(); i++)
	{
		collision(astr[i]);

		if (!astr[i].collected){
			//glPushMatrix();
			glTranslated(astr[i].eyex, astr[i].eyey, astr[i].eyez);
			texturedCube(texture[0], astrSize);
			glColor3f(1, 1, 1);
			glutSolidSphere(radius, slices, stacks);
			//glPopMatrix();
			//glutSolidCube(astrSize);
		}
	}
}
Exemple #3
0
int main(int argc, char **argv) {
  TestScene *scene = new TestScene(argc, argv, 2);

  GLuint tex_1 = initTexture(128, 128, carve_texture);
  GLuint tex_2 = initTexture(128, 128, brick_texture);
  GLuint tex_3 = initTexture(128, 128, leaf_texture);

  g_scale = 10.0;

  carve::interpolate::FaceVertexAttr<tex_t> fv_tex;
  carve::interpolate::FaceAttr<GLuint> f_tex_num;
  carve::mesh::MeshSet<3> *base = NULL;

  bool b = true;
  for (int x = -10; x <= +10; x += 5) {
    for (int y = -10; y <= +10; y += 5) {
      for (int z = -10; z <= +10; z += 5) {
        double rot = x * .17 + y * .06 + z * .09;
        carve::mesh::MeshSet<3> *r = texturedCube(fv_tex, f_tex_num, b ? tex_2 : tex_3,
                                 carve::math::Matrix::TRANS(x/2.5, y/2.5, z/2.5) *
                                 carve::math::Matrix::ROT(rot, 1,2,3));
        b = !b;
        if (base) {
          carve::mesh::MeshSet<3> *temp = base;
          carve::csg::CSG csg;
          fv_tex.installHooks(csg);
          f_tex_num.installHooks(csg);

          base = csg.compute(temp, r, carve::csg::CSG::UNION);
          delete temp;
          delete r;
        } else {
          base = r;
        }
      }
    }
  }

  carve::mesh::MeshSet<3> *r1 = texturedCube(fv_tex, f_tex_num, tex_1,
                            carve::math::Matrix::TRANS(0,0,4) *
                            carve::math::Matrix::SCALE(4,4,4));

  carve::mesh::MeshSet<3> *r2 = texturedCube(fv_tex, f_tex_num, tex_1,
                            carve::math::Matrix::TRANS(0,0,5) *
                            carve::math::Matrix::SCALE(2, 2, 2));

  carve::csg::CSG csg;
  fv_tex.installHooks(csg);
  f_tex_num.installHooks(csg);

  carve::mesh::MeshSet<3> *r3 = csg.compute(base, r1, carve::csg::CSG::INTERSECTION, NULL, carve::csg::CSG::CLASSIFY_EDGE);
  carve::mesh::MeshSet<3> *r4 = csg.compute(r3, r2, carve::csg::CSG::UNION, NULL, carve::csg::CSG::CLASSIFY_EDGE);

  glNewList(scene->draw_list_base, GL_COMPILE);
  drawTexturedPolyhedron(r4, fv_tex, f_tex_num);
  glEndList();

  glNewList(scene->draw_list_base+1, GL_COMPILE);
  drawWireframePolyhedron(r3);
  glEndList();

  scene->draw_flags[0] = true;
  scene->draw_flags[1] = true;

  scene->run();

  destroyTexture(tex_1);
  destroyTexture(tex_2);
  destroyTexture(tex_3);

  delete scene;

  return 0;
}