Ejemplo n.º 1
0
AmbientOcclusionRenderer::AmbientOcclusionRenderer(const Manifold& m, bool smooth, VertexAttributeVector<double>& field, double max_val):
    SimpleShaderRenderer(vss,fss)
{
    GLint old_prog;
    glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
    glUseProgram(prog);

    GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
    glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);

    glNewList(display_list,GL_COMPILE);

    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f) {

        if(!smooth)
            glNormal3dv(normal(m, *f).get());
        if(no_edges(m, *f)== 3)
            glBegin(GL_TRIANGLES);
        else
            glBegin(GL_POLYGON);

        for(Walker w = m.walker(*f); !w.full_circle(); w = w.circulate_face_ccw())
        {
            Vec3d n(normal(m, w.vertex()));
            if(smooth)
                glNormal3dv(n.get());
            glVertexAttrib1d(scalar_attrib, field[w.vertex()]);
            glVertex3dv(m.pos(w.vertex()).get());
        }
        glEnd();
    }
    glEndList();
    glUseProgram(old_prog);

}
Ejemplo n.º 2
0
void Object::paint()
{
    //std::cout << _data.size() << '\n';
    if(_data.size() != 0)
    {
        _materials[_data[0].matNum()].setMaterial();
        glBegin(GL_POLYGON);
        for(size_t j = 0; j < _data[0].poly().size(); ++j)
        {
            glNormal3dv(_data[0].norm());
            glVertex3dv(_points[_data[0].poly()[j]]);
        }
        glEnd();
        for(size_t i = 1; i < _data.size(); ++i)
        {
            if(_data[i - 1].matNum() != _data[i].matNum())
                _materials[_data[i].matNum()].setMaterial();
            glBegin(GL_POLYGON);
            for(size_t j = 0; j < _data[i].poly().size(); ++j)
            {
                glNormal3dv(_data[i].norm());
                glVertex3dv(_points[_data[i].poly()[j]]);
            }
            glEnd();
        }
    }
}
Ejemplo n.º 3
0
void Triangle::render() const
{
    bool materials_nonnull = true;
    for ( int i = 0; i < 3; ++i )
        materials_nonnull = materials_nonnull && vertices[i].material;

    // this doesn't interpolate materials. Ah well.
    if ( materials_nonnull )
        vertices[0].material->set_gl_state();

    glBegin(GL_TRIANGLES);

    glNormal3dv( &vertices[0].normal.x );
    glTexCoord2dv( &vertices[0].tex_coord.x );
    glVertex3dv( &vertices[0].position.x );

    glNormal3dv( &vertices[1].normal.x );
    glTexCoord2dv( &vertices[1].tex_coord.x );
    glVertex3dv( &vertices[1].position.x);

    glNormal3dv( &vertices[2].normal.x );
    glTexCoord2dv( &vertices[2].tex_coord.x );
    glVertex3dv( &vertices[2].position.x);

    glEnd();

    if ( materials_nonnull )
        vertices[0].material->reset_gl_state();
}
Ejemplo n.º 4
0
//球のバンプマッピング用
void drawBumpSphere(double radius, int nSlice, int nStack, int nRepeatS, int nRepeatT)
{
	int i, j;
	double s, t0, t1, r0, r1, th0, th1, phi;
	double p[2][3], tnt[3];

  GLuint tangentLoc = glGetAttribLocation(shaderProg, "tangent");

	for(j = 0; j < nStack; j++)
	{
		//j=0は北極点(x=0, y=0, z=radius)
		//2つのt座標
		t0 = (double)j / (double)nStack;
		t1 = (double)(j+1) / (double)nStack;
		//これらの天頂角
		th0 = M_PI * t0;
		th1 = M_PI * t1;
		//x-y平面に投影した半径
		r0 = radius * sin(th0);
		r1 = radius * sin(th1);
		//頂点z座標
		p[0][2] = radius * cos(th0);
		p[1][2] = radius * cos(th1);
		//接線ベクトルのz成分
		tnt[2] = 0.0;

		//北極点を1とするt座標
		t0 = (1.0 - t0) * nRepeatT;
		t1 = (1.0 - t1) * nRepeatT;

		glBegin(GL_QUAD_STRIP);
		for(i = 0; i <= nSlice; i++)
		{
			//s座標
			s = (double)i / (double)nSlice;
			phi = -M_PI + 2.0 * M_PI * s;
			//頂点のxy座標(i=0を真後ろ)
			p[0][0] = r0 * cos(phi);//x座標
			p[0][1] = r0 * sin(phi);//y座標
			p[1][0] = r1 * cos(phi);//x座標
			p[1][1] = r1 * sin(phi);//y座標
			//接線ベクトルのxy成分
			tnt[0] =-sin(phi);
			tnt[1] = cos(phi);

			s *= nRepeatS;

			glVertexAttrib3dv(tangentLoc, tnt);
			glTexCoord2d(s, t0);//テクスチャ座標
			glNormal3dv(p[0]);//法線ベクトル,正規化すれば頂点座標に同じ
			glVertex3dv(p[0]);//頂点座標

			glTexCoord2d(s, t1);//テクスチャ座標
			glNormal3dv(p[1]);//法線ベクトル,正規化すれば頂点座標に同じ
			glVertex3dv(p[1]);//頂点座標
		}
		glEnd();
	}
}
Ejemplo n.º 5
0
void Mesh::render(const vec3b& color, bool texturing, bool selected) const {
  bool use_texture = texturing && !tex_coord.empty();

  glEnable(GL_NORMALIZE);
  glEnable(GL_LIGHTING);

  if (use_texture) {
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture_id);
  }

  auto& mesh = *this;

  auto triangles = mesh.triangles;
  triangles << top_cover.triangles;
  triangles << bottom_cover.triangles;
  glBegin(GL_TRIANGLES);
  for (auto& tri : triangles) {
    if (selected) glColor3ub(255, 0, 0);
    else if (use_texture) glColor3ub(255, 255, 255);
    else glColor3ubv(color.coords);

    glNormal3dv(tri.normal.coords);
    if (use_texture) glTexCoord2dv(tex(tri[0]).coords);
    glVertex3iv(mesh[tri[0]].coords);

    glNormal3dv(tri.normal.coords);
    if (use_texture) glTexCoord2dv(tex(tri[1]).coords);
    glVertex3iv(mesh[tri[1]].coords);

    glNormal3dv(tri.normal.coords);
    if (use_texture) glTexCoord2dv(tex(tri[2]).coords);
    glVertex3iv(mesh[tri[2]].coords);
  }
  glEnd();

  if (use_texture) {
    glDisable(GL_TEXTURE_2D);
  }

  glDisable(GL_LIGHTING);
  glDisable(GL_NORMALIZE);

#ifndef NDEBUG
  if (selected && use_texture) {
    glLineWidth(5);
    glColor3d(1, 0, 0);
    glBegin(GL_LINE_STRIP);
    for(auto &e: anchor_points) glVertex2iv(e[0].coords);
    glEnd();
    glBegin(GL_LINE_STRIP);
    for (auto &e: anchor_points) glVertex2iv(e[1].coords);
    glEnd();
    glLineWidth(1);
  }
#endif
  glColor3d(1, 1, 1);
}
Ejemplo n.º 6
0
// Utility function for drawing a cube
void drawbox(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1,
             GLdouble z0, GLdouble z1, GLenum type)
{
   static GLdouble n[6][3] =
      {
         { -1.0, 0.0, 0.0 },
         { 0.0, 1.0, 0.0 },
         { 1.0, 0.0, 0.0 },
         { 0.0, -1.0, 0.0 },
         { 0.0, 0.0, 1.0 },
         { 0.0, 0.0, -1.0 }
      };
   static GLint faces[6][4] =
      {
         { 0, 1, 2, 3 },
         { 3, 2, 6, 7 },
         { 7, 6, 5, 4 },
         { 4, 5, 1, 0 },
         { 5, 6, 2, 1 },
         { 7, 4, 0, 3 }
      };
   GLdouble v[8][3], tmp;

   if (x0 > x1)
   {
      tmp = x0; x0 = x1; x1 = tmp;
   }
   if (y0 > y1)
   {
      tmp = y0; y0 = y1; y1 = tmp;
   }
   if (z0 > z1)
   {
      tmp = z0; z0 = z1; z1 = tmp;
   }

   v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0;
   v[4][0] = v[5][0] = v[6][0] = v[7][0] = x1;
   v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
   v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
   v[0][2] = v[3][2] = v[4][2] = v[7][2] = z0;
   v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1;

   for ( GLint i = 0; i < 6; ++i )
   {
      glBegin(type);
         glNormal3dv(&n[i][0]);
         glVertex3dv(&v[faces[i][0]][0]);
         glNormal3dv(&n[i][0]);
         glVertex3dv(&v[faces[i][1]][0]);
         glNormal3dv(&n[i][0]);
         glVertex3dv(&v[faces[i][2]][0]);
         glNormal3dv(&n[i][0]);
         glVertex3dv(&v[faces[i][3]][0]);
      glEnd();
   }
}
Ejemplo n.º 7
0
void drawTri(const carve::geom::tri<3> &tri) {
  carve::geom::vector<3> n = tri.normal();
  glBegin(GL_TRIANGLES);
    glNormal3dv(n.v);
    glVertex(tri.v[0]);
    glVertex(tri.v[1]);
    glVertex(tri.v[2]);
    glNormal3dv((-n).v);
    glVertex(tri.v[0]);
    glVertex(tri.v[2]);
    glVertex(tri.v[1]);
  glEnd();
}
Ejemplo n.º 8
0
void dessine_route(route r, int steps) {
  int i, start = 1;
  double tex_x = 0.0;
  point3d_cell previous_centre;
  vecteur3d_cell ecart_centre;
  glEnable (GL_TEXTURE_2D);
  glBindTexture (GL_TEXTURE_2D, texture_route);
  glColor3f(   1.0f,  1.0f,  1.0f ); 
  glBegin(GL_QUAD_STRIP);
  for(i=0;i<=steps;i++) {
    double t = (float) i / (float) steps;
    point3d_cell centre,x1,x2;
    vecteur3d_cell devant, cote, vertical;
    repere_route(r, t, &centre, &devant, &cote, &vertical);
    if (start) {previous_centre = centre; start = 0;};
    vec3d(&ecart_centre, &previous_centre, &centre);
    tex_x = tex_x + norm3d(&ecart_centre)/(texture_ratio*2*r->largeur);
    glNormal3dv((double*) &vertical);
    x1 =centre; x2 = centre;
    translate3d(&x1, r->largeur, &cote);
    translate3d(&x2, -r->largeur, &cote);
    glTexCoord2f(0.0, tex_x);
    glVertex3dv((double*) &x1);
    glTexCoord2f(1.0, tex_x);
    glVertex3dv((double*) &x2);
    previous_centre = centre;
  }
  glEnd();
  glDisable (GL_TEXTURE_2D);
}
Ejemplo n.º 9
0
void drawMesh(carve::mesh::Mesh<3> *mesh, float r, float g, float b, float a) {
  glColor4f(r, g, b, a);

  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glBegin(GL_TRIANGLES);

  std::vector<carve::mesh::Vertex<3> *> v;

  for (size_t i = 0, l = mesh->faces.size(); i != l; ++i) {
    carve::mesh::Face<3> *f = mesh->faces[i];
    if (f->nVertices() == 3) {
      glNormal3dv(f->plane.N.v);
      f->getVertices(v);
      glVertex(v[0]->v);
      glVertex(v[1]->v);
      glVertex(v[2]->v);
    }
  }
  glEnd();

  for (size_t i = 0, l = mesh->faces.size(); i != l; ++i) {
    carve::mesh::Face<3> *f = mesh->faces[i];
    if (f->nVertices() != 3) {
      drawFace(f, cRGBA(r, g, b, a));
    }
  }
}
Ejemplo n.º 10
0
void DebugHooks::drawFaceLoop(const std::vector<const carve::geom3d::Vector *> &face_loop,
                              const carve::geom3d::Vector &normal,
                              float r, float g, float b, float a,
                              bool lit) {
  if (lit) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING);

  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  GLUtesselator *tess = gluNewTess();

  gluTessCallback(tess, GLU_TESS_BEGIN, (GLUTessCallback)glBegin);
  gluTessCallback(tess, GLU_TESS_VERTEX, (GLUTessCallback)glVertex3dv);
  gluTessCallback(tess,  GLU_TESS_END, (GLUTessCallback)glEnd);

  glNormal3dv(normal.v);
  glColor4f(r, g, b, a);

  gluTessBeginPolygon(tess, (void *)NULL);
  gluTessBeginContour(tess);

  std::vector<carve::geom3d::Vector> v;
  v.resize(face_loop.size());
  for (size_t i = 0, l = face_loop.size(); i != l; ++i) {
    v[i] = g_scale * (*face_loop[i] + g_translation);
    gluTessVertex(tess, (GLdouble *)v[i].v, (GLvoid *)v[i].v);
  }

  gluTessEndContour(tess);
  gluTessEndPolygon(tess);

  gluDeleteTess(tess);

  glEnable(GL_LIGHTING);
}
Ejemplo n.º 11
0
void GeomRenderer::sendNormal(GLuint normalIndex)
{
    assert(normalData.size == 3);

    switch(normalData.type)
    {
        case GL_BYTE:
            glNormal3bv((const GLbyte*)((const char*)normalData.pointer + normalIndex*normalData.stride));
            break;

        case GL_SHORT:
            glNormal3sv((const GLshort*)((const char*)normalData.pointer + normalIndex*normalData.stride));
            break;

        case GL_INT:
            glNormal3iv((const GLint*)((const char*)normalData.pointer + normalIndex*normalData.stride));
            break;

        case GL_FLOAT:
            glNormal3fv((const GLfloat*)((const char*)normalData.pointer + normalIndex*normalData.stride));
            break;

        case GL_DOUBLE:
            glNormal3dv((const GLdouble*)((const char*)normalData.pointer + normalIndex*normalData.stride));
            break;
    }
}
Ejemplo n.º 12
0
void DynFace::draw(void)
{
    glBegin(GL_POLYGON);
    glNormal3dv(&(*getNormalOS())[0]);
    for (unsigned int i = 0; i < vertices.size(); i++)
        glVertex3dv(&(*getVertexOS(i))[0]);
        
    glEnd();

#ifdef DRAW_FACE_NORMALS
    glDisable(GL_LIGHTING);
    glColor3f(1.0, 0.0, 0.0);

    hduVector3Dd vertAccum(3,0);
    for (i = 0; i < vertices.size(); i++)
        vertAccum += *getVertexOS(i);

    hduVector3Dd normalTail = vertAccum / (double)vertices.size();
    hduVector3Dd normalHead = normalTail + *getNormal();

    glBegin(GL_LINES);
    glVertex3dv(&normalTail[0]);
    glVertex3dv(&normalHead[0]);
    glEnd();

    glEnable(GL_LIGHTING);
#endif
}
void PlainPointSetRender::draw_point_set() {
	if (use_color_attribute_)
		vertex_color_.bind_if_defined(target(), "color") ;

	bool has_normal = PointSetNormal::is_defined(target());
	if (has_normal)
		glEnable(GL_LIGHTING);
	else
		glDisable(GL_LIGHTING);

	glPointSize(vertices_style_.size);
	glColor4fv(vertices_style_.color.data());

	glBegin(GL_POINTS);
	if (has_normal)	{
		PointSetNormal normals(target());
		if (vertex_color_.is_bound()) {
			PointSetColor	colors(target());
			FOR_EACH_VERTEX_CONST(PointSet, target(), it) {
				const vec3&  p = it->point();
				const vec3& n = normals[it];
				const Color& c = vertex_color_[it];
				glColor4fv(c.data());
				glNormal3dv(n.data());
				glVertex3dv(p.data());
			}
		} else  {
Ejemplo n.º 14
0
void Polytope::Display(double ogl_trans[16])
{
  glPushMatrix();
  glLoadMatrixd(ogl_trans);
  
  glBegin(GL_TRIANGLES);
  
  int i;
  for (i=0; i<num_tris; i++)
    {
      Vector normal =  (vertex[tris[i].p[1]] - vertex[tris[i].p[0]])*
	               (vertex[tris[i].p[2]] - vertex[tris[i].p[0]]);

      normal.normalize();
      
      glNormal3dv( normal.v );
      glVertex3dv( vertex[tris[i].p[0]].v );
      glVertex3dv( vertex[tris[i].p[1]].v );
      glVertex3dv( vertex[tris[i].p[2]].v );
      
    }
  
  glEnd();
  
  glPopMatrix();
  
}
void PlainSurfaceRender::draw_surface() {

	if (use_color_attribute_)
		facet_color_.bind_if_defined(target(), "color") ;
	if (use_color_attribute_ && (!facet_color_.is_bound()))
		vertex_color_.bind_if_defined(target(), "color") ;

	glEnable(GL_LIGHTING);
	glColor4fv(surface_style_.color.data());

	if (vertex_color_.is_bound()) {
		glShadeModel(GL_SMOOTH);
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		if (smooth_shading_) {
			if (!MapVertexNormal::is_defined(target()))
				target()->compute_vertex_normals();
			MapVertexNormal normal(target()) ;

			FOR_EACH_FACET_CONST(Map, target(), it) {
				glBegin(GL_POLYGON);
				Map::Halfedge* jt = it->halfedge() ;
				do {
					Map::Vertex* v = jt->vertex();
					glColor4fv(vertex_color_[v].data());

					const vec3& n = normal[v];
					glNormal3dv(n.data());

					const vec3& p = v->point();
					glVertex3dv(p.data());
					jt = jt->next() ;
				} while(jt != it->halfedge()) ;
				glEnd();
			}	
		} 
Ejemplo n.º 16
0
GLvoid CALLBACK onTessVertex(GLdouble* data)
{
  GLdouble* p = data+3;
  GLfloat glcol[4] = {0,0,0,1};
  // Is a normal available?
  if (tess_data_flag & 0x01)
  {
    glNormal3dv(p);
    p+=3;
  }
  // Is a texture coordinate available?
  if (tess_data_flag & 0x02)
  {
    glTexCoord2d(p[0], p[1]);
    p+=2;
  }
  // Is a color available?
  if (tess_data_flag & 0x04)
  {
    glcol[0] = GLfloat(p[0]);
    glcol[1] = GLfloat(p[1]);
    glcol[2] = GLfloat(p[2]);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, glcol);
  }
  // Pass the vertex
  glVertex3dv(data);
}
Ejemplo n.º 17
0
// Construct the two display lists
void RenderablePicoSurface::createDisplayLists()
{
	// Generate the lists for lighting mode
    _dlProgramNoVCol = compileProgramList(false);
    _dlProgramVcol = compileProgramList(true);

	// Generate the list for flat-shaded (unlit) mode
	_dlRegular = glGenLists(1);
	assert(_dlRegular != 0); // check if we run out of display lists
	glNewList(_dlRegular, GL_COMPILE);

	glBegin(GL_TRIANGLES);
	for (Indices::const_iterator i = _indices.begin();
		 i != _indices.end();
		 ++i)
	{
		// Get the vertex for this index
		ArbitraryMeshVertex& v = _vertices[*i];

		// Submit attributes
		glNormal3dv(v.normal);
		glTexCoord2dv(v.texcoord);
		glVertex3dv(v.vertex);
	}
	glEnd();

	glEndList();
}
Ejemplo n.º 18
0
void Patch::render() const
{
	unsigned int i;


	glPushAttrib(GL_POINT_BIT /*| GL_CURRENT_BIT*/);

	//glColor3ub (150, 110, 20);
	glPointSize(7.0f);

	glBegin(GL_POINTS);

	for (i = 0; i < this->numberOfControlPoints; ++i)
	{
		glNormal3dv(this->controlNormal[i].data());
		glVertex3dv(this->controlPoints[i].data());
	}

	glEnd();

	//glColor3ub (20, 150, 20);
	this->mesh->render();

	glPopAttrib();
}
Ejemplo n.º 19
0
void
drawAttractor (void)
{
    int i;

    glClear (GL_COLOR_BUFFER_BIT);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    if (fset.dimension == 2) {
        glColor4f (1.0f, 1.0f, 1.0f, COLOR_ALPHA);
        glRotatef (dset.angle, 0.0, 0.0, 1.0);
    }
    else {
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
        glEnable (GL_LIGHTING);
        positionLight ();
        glRotatef (dset.angle, 1.0, 1.0, 1.0);
    }
    glBegin (GL_POINTS);
    for (i = 0; i < at[frontBuffer]->numPoints; i++) {
        if (fset.dimension == 2)
            glVertex2dv (at[frontBuffer]->array[i]);
        else {
            glVertex3dv (at[frontBuffer]->array[i]);
            /* Normal equal to the vector -> vertex redirects light in the same direction */
            glNormal3dv (at[frontBuffer]->array[i]);
        }
    }
    glEnd ();
}
Ejemplo n.º 20
0
/**********************************************************************
 * FlatShadeStripCB:
 **********************************************************************/
void 
FlatShadeStripCB::faceCB(CBvert* v, CBface* f) 
{
   // normal
   glNormal3dv(f->norm().data());

   if (v->has_color()) {
      GL_COL(v->color(), alpha*v->alpha());
   }

   // texture coords
   if (_do_texcoords) {
      if (_use_auto) { //force automatic 
         //use spherical text coord gen
         glTexCoord2dv(_auto_UV->uv_from_vert(v,f).data());
      } else {
         // the patch has a texture... try to find
         // appropriate texture coordinates...

         // use patch's TexCoordGen if possible,
         // otherwise use the texture coordinates stored
         // on the face (if any):
         TexCoordGen* tg = f->patch()->tex_coord_gen();
         if (tg)
            glTexCoord2dv(tg->uv_from_vert(v,f).data());
         else if (UVdata::lookup(f))
            glTexCoord2dv(UVdata::get_uv(v,f).data());
      }
   }
  
   // vertex coords
   glVertex3dv(v->loc().data());
}
Ejemplo n.º 21
0
void gsDraw(geosphere * sphere, int f, GAIM_FLOAT normal = 0.0) {
	int i;
	e3ga v1;

	if (sphere->face[f].child[0] >= 0) {
		for (i = 0; i < 4; i++)
			gsDraw(sphere, sphere->face[f].child[i], normal);
	}
	else {

		glBegin(GL_TRIANGLES);
		for (i = 0; i < 3; i++) {
			glNormal3dv(sphere->vertex[sphere->face[f].v[i]][GRADE1]);
			glVertex3dv((sphere->vertex[sphere->face[f].v[i]]) [GRADE1]);
		}
		glEnd();

		if (normal != 0.0) {
			GLboolean l;
			glGetBooleanv(GL_LIGHTING, &l);
			glDisable(GL_LIGHTING);
			glBegin(GL_LINES);
			for (i = 0; i < 3; i++) {
				v1 = sphere->vertex[sphere->face[f].v[i]].normal();
				glVertex3dv((sphere->vertex[sphere->face[f].v[i]]) [GRADE1]);
				glVertex3dv((sphere->vertex[sphere->face[f].v[i]] + v1 * normal)[GRADE1]);
			}
			glEnd();
			if (l) glEnable(GL_LIGHTING);
		}
	}
}
Ejemplo n.º 22
0
void drawTexturedPolyhedron(carve::mesh::MeshSet<3> *poly,
                            carve::interpolate::FaceVertexAttr<tex_t> &fv_tex,
                            carve::interpolate::FaceAttr<GLuint> &f_tex_num) {
  glEnable(GL_TEXTURE_2D);

  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

  GLUtesselator *tess = gluNewTess();

  gluTessCallback(tess, GLU_TESS_BEGIN, (GLUTessCallback)glBegin);
  gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLUTessCallback)tess_vertex);
  gluTessCallback(tess,  GLU_TESS_END, (GLUTessCallback)glEnd);

  for (carve::mesh::MeshSet<3>::face_iter i = poly->faceBegin(); i != poly->faceEnd(); ++i) {
    carve::mesh::MeshSet<3>::face_t *f = *i;
    std::vector<vt_t> vc(f->nVertices());

    bool textured = true;
    for (carve::mesh::MeshSet<3>::face_t::edge_iter_t e = f->begin(); e != f->end(); ++e) {
      vc[e.idx()].x = g_scale * (e->vert->v.x + g_translation.x);
      vc[e.idx()].y = g_scale * (e->vert->v.y + g_translation.y);
      vc[e.idx()].z = g_scale * (e->vert->v.z + g_translation.z);

      if (fv_tex.hasAttribute(f, e.idx())) {
        tex_t t = fv_tex.getAttribute(f, e.idx());
        vc[e.idx()].u = t.u;
        vc[e.idx()].v = t.v;
      } else {
        textured = false;
      }
    }

    if (textured) {
      GLuint tex_num = f_tex_num.getAttribute(f, 0);
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, tex_num);
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    } else {
      glColor4f(0.5f, 0.6f, 0.7f, 1.0f);
    }

    glNormal3dv(f->plane.N.v);

    gluTessBeginPolygon(tess, (void *)&textured);
    gluTessBeginContour(tess);

    for (size_t j = 0; j != vc.size(); ++j) {
      gluTessVertex(tess, (GLdouble *)&vc[j], (GLvoid *)&vc[j]);
    }

    gluTessEndContour(tess);
    gluTessEndPolygon(tess);

  }

  gluDeleteTess(tess);

  glDisable(GL_TEXTURE_2D);
}
Ejemplo n.º 23
0
void drawFace(Face* face){

	//glClear(GL_STENCIL_BUFFER_BIT);  
    GLUtesselator* tess = tesser();  
    if (!tess) return; 

    gluTessBeginPolygon(tess,NULL);
	Loop* firLp = face->fLoops;
	Loop* tmpLp = firLp;
	do{
		HalfEdge* firHe = tmpLp->lHalfEdges;
		HalfEdge* tmpHe = firHe;
		gluTessBeginContour(tess);
		do{
			gluTessVertex(tess, tmpHe->heStartVertex->point.pos, tmpHe->heStartVertex->point.pos);
			glNormal3dv(face->normal.pos);
			//以下注释的函数不知道为什么是错的,总之传进去的法向量有问题。再显示的时候不对。使用上面的函数传就可以了。
			/*gluTessNormal(tess, tmpHe->heStartVertex->normal.pos[0], 
				tmpHe->heStartVertex->normal.pos[1], 
				tmpHe->heStartVertex->normal.pos[2]);*/
			
			tmpHe = tmpHe->nxtHalfEdge;
		}while(tmpHe != firHe);		  
		gluTessEndContour(tess); 

		tmpLp = tmpLp->nxtLoop;
	}while(tmpLp != firLp);

    gluTessEndPolygon(tess);   
}
Ejemplo n.º 24
0
GLuint HalfEdgeModel::CreateTriangleDisplayList( unsigned int flags )
{
	bool normals =    (flags & WITH_NORMALS) > 0;
	bool facetNorms = (flags & WITH_FACET_NORMALS) > 0;
	bool failure = false;
	float facetNorm[3];
	Solid *sobj = (Solid *)solid;
	GLuint list = glGenLists( 1 );
	glNewList( list, GL_COMPILE );

	glBegin( GL_TRIANGLES );
	Face *currFace = sobj->sfaces;
	for ( ; currFace; ) 
	{
		Loop *loop   = currFace->floop;
		if (!loop) { failure=true; break; }
		HalfEdge *he1 = loop->ledges;
		if (!he1) { failure=true; break; }
		HalfEdge *he2 = he1->next;
		if (!he2) { failure=true; break; }
		HalfEdge *he3 = he2->next;
		if (!he3) { failure=true; break; }
		if (facetNorms)
		{
			ComputeFaceNormal( facetNorm, (void *)(loop->lface) );	
			glNormal3fv( facetNorm );
		}
		if (normals) glNormal3dv( he1->hvert->ncoord );
		glVertex3dv( he1->hvert->vcoord );
		if (normals) glNormal3dv( he2->hvert->ncoord );
		glVertex3dv( he2->hvert->vcoord );
		if (normals) glNormal3dv( he3->hvert->ncoord );
		glVertex3dv( he3->hvert->vcoord );
		currFace = currFace->next;
		if (!currFace || currFace == sobj->sfaces) break;
	}
	glEnd();
	glEndList();

	if (failure)
	{
		glDeleteLists( list, 1 );
		return 0;
	}

	return (triList = list);
}
Ejemplo n.º 25
0
/** Contains the vertex, normal and texture calls  that draw the primitive.
*/
void C3dLine::draw () const
{
	C3dPoint::draw();
	
	glNormal3dv(m_VN1.dv());
	glTexCoord2dv(m_VTex1.dv()); 
	m_V1.vertex();
}
Ejemplo n.º 26
0
void emitSphereCoord(const carve::geom::vector<3> &c, double r, unsigned stack, unsigned slice) {
  carve::geom::vector<3> v;

  v = sphereAng(stack * M_PI / N_STACKS, slice * 2 * M_PI / N_SLICES);

  glNormal3dv(v.v);
  glVertex(c + r * v);
}
Ejemplo n.º 27
0
void draw_cube(void)
{
   static GLuint display_tag = 0;
   if(display_tag == 0) {
      display_tag = glGenLists(1);
      glNewList(display_tag, GL_COMPILE_AND_EXECUTE);

      static GLdouble n[6][3] = {
	 {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
	 {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}
      };
      static GLint faces[6][4] = {
	 { 0, 1, 2, 3 }, { 3, 2, 6, 7 }, { 7, 6, 5, 4 },
	 { 4, 5, 1, 0 }, { 5, 6, 2, 1 }, { 7, 4, 0, 3 }
      };
      GLdouble v[8][3];
      GLint i;

      v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1;
      v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1;
      v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1;
      v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1;
      v[0][2] = v[3][2] = v[4][2] = v[7][2] = -1;
      v[1][2] = v[2][2] = v[5][2] = v[6][2] = 1;

      static GLenum type = GL_QUADS; /* GL_LINE_LOOP */

      for (i = 0; i < 6; i++) {
	 glBegin(type);
	 glNormal3dv(&n[i][0]);
	 glVertex3dv(&v[faces[i][0]][0]);
	 glNormal3dv(&n[i][0]);
	 glVertex3dv(&v[faces[i][1]][0]);
	 glNormal3dv(&n[i][0]);
	 glVertex3dv(&v[faces[i][2]][0]);
	 glNormal3dv(&n[i][0]);
	 glVertex3dv(&v[faces[i][3]][0]);
	 glEnd();
      }
      glEndList();
   }
   else {
      glCallList(display_tag);
   }
}
Ejemplo n.º 28
0
/*
 *  Draw vertex in polar coordinates with normal
 */
void Vertex(double th,double ph, double r)
{  
   coordinates rectangular = convertFromSpherical(th, ph, r); 

   //  For a sphere at the origin, the position
   //  and normal vectors are the same
   glNormal3dv(rectangular.toArray());
   glVertex3dv(rectangular.toArray());
}
Ejemplo n.º 29
0
void Triangle::render() const
{
    bool materials_nonnull = true;
    for ( int i = 0; i < 3; ++i )
        materials_nonnull = materials_nonnull && vertices[i].material;

    // this doesn't interpolate materials. Ah well.
    if ( materials_nonnull )
        vertices[0].material->set_gl_state();

    glBegin(GL_TRIANGLES);
//    glBegin(GL_LINE_LOOP);

    glNormal3dv( &vertices[0].normal.x );
    glTexCoord2dv( &vertices[0].tex_coord.x );
    glVertex3dv( &vertices[0].position.x );

    glNormal3dv( &vertices[1].normal.x );
    glTexCoord2dv( &vertices[1].tex_coord.x );
    glVertex3dv( &vertices[1].position.x);

    glNormal3dv( &vertices[2].normal.x );
    glTexCoord2dv( &vertices[2].tex_coord.x );
    glVertex3dv( &vertices[2].position.x);

    glEnd();

	// 545
/*    glBegin(GL_LINES);
    	const Vertex * v;
    	Vector3 p, n;
		for(int i=0; i<3; i++) {
			v = &vertices[i];
			p = v->position;
			n = v->normal;
			glVertex3f(p.x, p.y, p.z);
			glVertex3f(p.x+n.x, p.y+n.y, p.z+n.z);
		}
    glEnd(); */


    if ( materials_nonnull )
        vertices[0].material->reset_gl_state();
}
GLvoid Torus::GetTorusNormal( const Parameter &theParamTheta, const Parameter &theParamPhi )
{
	Vector  normal;
	
	normal.x =  theParamTheta.cos( ) * theParamPhi.cos( );
	normal.y = -theParamTheta.sin( ) * theParamPhi.cos( );
	normal.z =  theParamPhi.cos( );
	
	glNormal3dv( normal.v );
} // Parmeter::GetTorusNormal