void emitStrip(Vector v[6], float s1, float s2, float dt, int count, int depth)
{
	if(depth > 0){
		emitStrip(v, s1, (s1+s2)/2, dt/2, count*2-1, depth-1);
		emitStrip(v, (s1+s2)/2, s2, dt/2, count*2-1, depth-1);
	}else{
		glBegin(GL_TRIANGLE_STRIP);
			/*
			static Color colors[] = {
				Color(255,255,0),
				Color(0,255,255),
				Color(255,0,255),
				Color(255,255,255),
				Color(0,255,0)
			};
			static int i = 0;
			glColor(colors[(i++)%5]);
			*/
			for(int i=0; i<count; i++){
				Vector v1 = sampleStrip(v, s1, i*dt);
				Vector v2 = sampleStrip(v, s2, i*dt);
				v1 /= length(v1);
				v2 /= length(v2);
				glNormal(v1);
				glTexCoord3f(v1.x, v1.y, v1.z);
				glVertex(v1);
				glNormal(v2);
				glTexCoord3f(v2.x, v2.y, v2.z);
				glVertex(v2);
			}
		glEnd();
	}
}
Пример #2
0
void ConeNode::createList(GLContextData& renderState) const
	{
	Scalar h=height.getValue();
	Scalar h2=Math::div2(h);
	Scalar br=bottomRadius.getValue();
	int ns=numSegments.getValue();
	
	if(side.getValue())
		{
		/* Draw the cone side: */
		glBegin(GL_QUAD_STRIP);
		Scalar nScale=Scalar(1)/Math::sqrt(h*h+br*br);
		glNormal(Scalar(0),br*nScale,-h*nScale);
		glTexCoord2f(0.0f,1.0f);
		glVertex(Scalar(0),h2,Scalar(0));
		glTexCoord2f(0.0f,0.0f);
		glVertex(Scalar(0),-h2,-br);
		for(int i=1;i<ns;++i)
			{
			Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(ns);
			float texS=float(i)/float(ns);
			Scalar c=Math::cos(angle);
			Scalar s=Math::sin(angle);
			glNormal(-s*h*nScale,br*nScale,-c*h*nScale);
			glTexCoord2f(texS,1.0f);
			glVertex(Scalar(0),h2,Scalar(0));
			glTexCoord2f(texS,0.0f);
			glVertex(-s*br,-h2,-c*br);
			}
		glNormal(Scalar(0),br*nScale,-h*nScale);
		glTexCoord2f(1.0f,1.0f);
		glVertex(Scalar(0),h2,Scalar(0));
		glTexCoord2f(1.0f,0.0f);
		glVertex(Scalar(0),-h2,-br);
		glEnd();
		}
	
	if(bottom.getValue())
		{
		/* Draw the cone bottom: */
		glBegin(GL_TRIANGLE_FAN);
		glNormal(Scalar(0),Scalar(-1),Scalar(0));
		glTexCoord2f(0.5f,0.5f);
		glVertex(Scalar(0),-h2,Scalar(0));
		glTexCoord2f(0.5f,0.0f);
		glVertex(Scalar(0),-h2,-br);
		for(int i=ns-1;i>0;--i)
			{
			Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(ns);
			Scalar c=Math::cos(angle);
			Scalar s=Math::sin(angle);
			glTexCoord2f(-float(s)*0.5f+0.5f,-float(c)*0.5f+0.5f);
			glVertex(-s*br,-h2,-c*br);
			}
		glTexCoord2f(0.5f,0.0f);
		glVertex(Scalar(0),-h2,-br);
		glEnd();
		}
	}
Пример #3
0
void QuadSetNode::glRenderAction(GLRenderState& renderState) const
	{
	/* Bail out if there are less than 4 points: */
	if(coord.getValue()==0||coord.getValue()->point.getNumValues()<4)
		return;
	
	/* Set up OpenGL state: */
	renderState.enableCulling(GL_BACK);
	
	/* Render the quad set: */
	size_t numPoints=coord.getValue()->point.getNumValues();
	glBegin(GL_QUADS);
	std::vector<Vector>::const_iterator qnIt=quadNormals.begin();
	for(size_t q=0;q+4<=numPoints;q+=4,++qnIt)
		{
		/* Get the quad's four corner points in counter-clockwise order: */
		Point ps[4];
		if(ccw.getValue())
			{
			for(size_t i=0;i<4;++i)
				ps[i]=coord.getValue()->point.getValue(q+i);
			}
		else
			{
			for(size_t i=0;i<4;++i)
				ps[i]=coord.getValue()->point.getValue(q+3-i);
			}
		
		if(pointTransform.getValue()!=0)
			{
			/* Transform the quad's corner points: */
			for(int i=0;i<4;++i)
				ps[i]=pointTransform.getValue()->transformPoint(ps[i]);
			}
		
		/* Draw the quad's front: */
		glNormal(*qnIt);
		for(int i=0;i<4;++i)
			{
			glTexCoord(quadTexCoords[i]);
			glVertex(ps[i]);
			}
		
		if(!solid.getValue())
			{
			/* Draw the quad's back: */
			glNormal(-*qnIt);
			for(int i=3;i>=0;--i)
				{
				glTexCoord(quadTexCoords[i]);
				glVertex(ps[i]);
				}
			}
		}
	glEnd();
	}
Пример #4
0
inline
void
Polyhedron<ScalarParam>::drawIntersection(const typename Polyhedron<ScalarParam>::Plane& plane) const
	{
	typedef Misc::HashTable<Card,void> IndexSet;
	
	/* Find any edge that intersects the given plane: */
	Card numEdges=edges.size();
	Card intersectedEdgeIndex=numEdges;
	IndexSet ioEdges(17);
	for(Card i=0;i<numEdges;++i)
		{
		/* Get the plane distance of start and end points of edge i: */
		Scalar d0=plane.calcDistance(edges[i].start);
		Scalar d1=plane.calcDistance(edges[edges[i].next].start);
		
		/* Classify the edge: */
		if(d0<Scalar(0)&&d1>=Scalar(0))
			{
			/* Remember the edge: */
			intersectedEdgeIndex=i;
			}
		else if(d0>=Scalar(0)&&d1<Scalar(0))
			{
			/* Mark the edge as a face exit: */
			ioEdges.setEntry(IndexSet::Entry(i));
			}
		}
	
	/* Bail out if no intersection was found: */
	if(intersectedEdgeIndex==numEdges)
		return;
	
	/* Iterate around the polyhedron along the plane intersection: */
	glBegin(GL_POLYGON);
	glNormal(-plane.getNormal());
	Card edgeIndex=intersectedEdgeIndex;
	do
		{
		/* Calculate and draw the edge's intersection point: */
		const Point& p0=edges[edgeIndex].start;
		Scalar d0=plane.calcDistance(p0);
		const Point& p1=edges[edges[edgeIndex].next].start;
		Scalar d1=plane.calcDistance(p1);
		glVertex(Geometry::affineCombination(p0,p1,(Scalar(0)-d0)/(d1-d0)));
		
		/* Find the next intersected edge around the same face as the current last edge: */
		Card i;
		for(i=edges[edgeIndex].next;!ioEdges.isEntry(i);i=edges[i].next)
			;
		
		/* Go to the next intersected face: */
		edgeIndex=edges[i].opposite;
		}
	while(edgeIndex!=intersectedEdgeIndex);
	glEnd();
	}
Пример #5
0
void TriangleRenderer::initContext(GLContextData& contextData) const
	{
	/* Create context data item: */
	DataItem* dataItem=new DataItem;
	contextData.addDataItem(this,dataItem);
	
	/* Create model display list: */
	glNewList(dataItem->displayListId,GL_COMPILE);
	
	/* Render triangle sides: */
	glBegin(GL_QUADS);
	glNormal(Triangle::renderNormals[0]);
	glVertex(Triangle::renderVertices[0]);
	glVertex(Triangle::renderVertices[1]);
	glVertex(Triangle::renderVertices[4]);
	glVertex(Triangle::renderVertices[3]);
	glNormal(Triangle::renderNormals[1]);
	glVertex(Triangle::renderVertices[1]);
	glVertex(Triangle::renderVertices[2]);
	glVertex(Triangle::renderVertices[5]);
	glVertex(Triangle::renderVertices[4]);
	glNormal(Triangle::renderNormals[2]);
	glVertex(Triangle::renderVertices[2]);
	glVertex(Triangle::renderVertices[0]);
	glVertex(Triangle::renderVertices[3]);
	glVertex(Triangle::renderVertices[5]);
	glEnd();
	
	/* Render triangle caps: */
	glBegin(GL_TRIANGLES);
	glNormal(Triangle::renderNormals[3]);
	glVertex(Triangle::renderVertices[0]);
	glVertex(Triangle::renderVertices[2]);
	glVertex(Triangle::renderVertices[1]);
	glNormal(Triangle::renderNormals[4]);
	glVertex(Triangle::renderVertices[3]);
	glVertex(Triangle::renderVertices[4]);
	glVertex(Triangle::renderVertices[5]);
	glEnd();
	
	/* Finish model display list: */
	glEndList();
	}
Пример #6
0
// Send out a normal, texture coordinate, vertex coordinate, and an optional custom attribute.
void TParametricSurface::Vertex(vec2 domain)
{
    vec3 p0, p1, p2, p3;
    vec3 normal;
    float u = domain.u;
    float v = domain.v;

    Eval(domain, p0);
    vec2 z1(u + du/2, v);
    Eval(z1, p1);
    vec2 z2(u + du/2 + du, v);
    Eval(z2, p3);

    if (flipped) {
        vec2 z3(u + du/2, v - dv);
        Eval(z3, p2);
    } else {
        vec2 z4(u + du/2, v + dv);
        Eval(z4, p2);
    }

    const float epsilon = 0.00001f;

    vec3 tangent = p3 - p1;
    vec3 binormal = p2 - p1;
    normal = cross(tangent, binormal);
    if (normal.magnitude() < epsilon)
        normal = p0;
    normal.unitize();

    if (tangentLoc != -1)
    {
        if (tangent.magnitude() < epsilon)
            tangent = cross(binormal, normal);
        tangent.unitize();
        glVertexAttrib(tangentLoc, tangent);
    }

    if (binormalLoc != -1)
    {
        binormal.unitize();
        glVertexAttrib(binormalLoc, -binormal);
    }

    if (CustomAttributeLocation() != -1)
        glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain));

    glNormal(normal);
    glTexCoord(domain);
    glVertex(p0);
}
Пример #7
0
void DropdownButton::drawDecoration(GLContextData&) const
	{
	/* Draw the margin around the dropdown arrow: */
	glColor(backgroundColor);
	glNormal3f(0.0f,0.0f,1.0f);
	glBegin(GL_TRIANGLE_FAN);
	glVertex(arrowOuter[0]);
	glVertex(arrowOuter[6]);
	glVertex(decorationBox.getCorner(0));
	glVertex(decorationBox.getCorner(1));
	glVertex(arrowOuter[1]);
	glEnd();
	glBegin(GL_TRIANGLE_FAN);
	glVertex(decorationBox.getCorner(3));
	glVertex(arrowOuter[4]);
	glVertex(arrowOuter[3]);
	glVertex(arrowOuter[2]);
	glVertex(arrowOuter[1]);
	glVertex(decorationBox.getCorner(1));
	glEnd();
	glBegin(GL_TRIANGLE_FAN);
	glVertex(decorationBox.getCorner(2));
	glVertex(decorationBox.getCorner(0));
	glVertex(arrowOuter[6]);
	glVertex(arrowOuter[5]);
	glVertex(arrowOuter[4]);
	glVertex(decorationBox.getCorner(3));
	glEnd();
	
	/* Draw the arrow sides: */
	glBegin(GL_QUADS);
	int i1=6;
	for(int i2=0;i2<7;++i2)
		{
		glNormal(arrowNormal[i1]);
		glVertex(arrowOuter[i1]);
		glVertex(arrowOuter[i2]);
		glVertex(arrowInner[i2]);
		glVertex(arrowInner[i1]);
		i1=i2;
		}
	glEnd();
	
	/* Draw the arrow face: */
	glNormal3f(0.0f,0.0f,1.0f);
	glBegin(GL_TRIANGLE_FAN);
	for(int i=0;i<7;++i)
		glVertex(arrowInner[i]);
	glEnd();
	}
Пример #8
0
void CylinderRenderer::initContext(GLContextData& contextData) const
	{
	/* Create context data item: */
	DataItem* dataItem=new DataItem;
	contextData.addDataItem(this,dataItem);
	
	/* Create model display list: */
	glNewList(dataItem->displayListId,GL_COMPILE);
	
	/* Render cylinder: */
	Scalar hradius=Cylinder::radius/Scalar(3);
	glNormal3f(0.0f,0.0f,-1.0);
	glBegin(GL_POLYGON);
	for(int i=7;i>=0;--i)
		{
		Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(8);
		Scalar c=Math::cos(angle);
		Scalar s=Math::sin(angle);
		glVertex(Point(c*hradius,s*hradius,-Cylinder::radius));
		}
	glEnd();
	
	glBegin(GL_QUAD_STRIP);
	for(int i=0;i<=8;++i)
		{
		Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i%8)/Scalar(8);
		Scalar c=Math::cos(angle);
		Scalar s=Math::sin(angle);
		glNormal(Vector(c,s,Scalar(0)));
		glVertex(Point(c*hradius,s*hradius,Cylinder::radius));
		glVertex(Point(c*hradius,s*hradius,-Cylinder::radius));
		}
	glEnd();
	
	glNormal3f(0.0f,0.0f,1.0);
	glBegin(GL_POLYGON);
	for(int i=0;i<8;++i)
		{
		Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(8);
		Scalar c=Math::cos(angle);
		Scalar s=Math::sin(angle);
		glVertex(Point(c*hradius,s*hradius,Cylinder::radius));
		}
	glEnd();
	
	/* Finish model display list: */
	glEndList();
	}
Пример #9
0
	void BoxGrid::renderAnchor()
	{
		glColor4f(1.0,0,0,1.0);
		glBegin(GL_QUADS);
		for(int i=0;i<anchors.size();i++)
		{
			int idBox = anchors[i];
			RowVector3 p[8];
			p[0] = getCurrentPose(getBoxNodes(idBox,7));
			p[1] = getCurrentPose(getBoxNodes(idBox,6));
			p[2] = getCurrentPose(getBoxNodes(idBox,5));
			p[3] = getCurrentPose(getBoxNodes(idBox,4));
			p[4] = getCurrentPose(getBoxNodes(idBox,3));
			p[5] = getCurrentPose(getBoxNodes(idBox,2));
			p[6] = getCurrentPose(getBoxNodes(idBox,1));
			p[7] = getCurrentPose(getBoxNodes(idBox,0));
			glNormal((p[3]-p[7]).cross(p[6]-p[7]));//bottom
			glVertex(p[7]);
			glVertex(p[3]);
			glVertex(p[2]);
			glVertex(p[6]);
			glNormal((p[4]-p[5]).cross(p[1]-p[5]));//top
			glVertex(p[5]);
			glVertex(p[4]);
			glVertex(p[0]);
			glVertex(p[1]);
			glNormal((p[5]-p[7]).cross(p[3]-p[7]));//far
			glVertex(p[7]);
			glVertex(p[5]);
			glVertex(p[1]);
			glVertex(p[3]);
			glNormal((p[1]-p[3]).cross(p[2]-p[3]));//right
			glVertex(p[3]); 
			glVertex(p[1]);
			glVertex(p[0]);
			glVertex(p[2]);
			glNormal((p[2]-p[6]).cross(p[4]-p[6]));//front
			glVertex(p[6]);
			glVertex(p[2]);
			glVertex(p[0]);
			glVertex(p[4]);
			glNormal((p[6]-p[7]).cross(p[5]-p[7]));//left
			glVertex(p[7]);
			glVertex(p[6]);
			glVertex(p[4]);
			glVertex(p[5]);
		}
		glEnd();
		RowVector4 color(1.0,0.0,0.0,1.0);
		for(int i=0;i<anchorNodes.size();i++)
		{
			RowVector3 p = getCurrentPose(anchorNodes[i]);
			paintPoint(p, 0.007,color);
		}
	}
Пример #10
0
inline
void
Polyhedron<ScalarParam>::drawFaces(
	void) const
	{
	typedef Misc::HashTable<Card,void> IndexSet;
	typedef Geometry::Vector<Scalar,3> Vector;
	
	IndexSet visitedEdges(101);
	Card numEdges=edges.size();
	for(Card i=0;i<numEdges;++i)
		{
		/* Only start a face if the current edge has not been visited yet: */
		if(!visitedEdges.isEntry(i))
			{
			/* Draw a polygon for the face: */
			glBegin(GL_POLYGON);
			
			/* Calculate the face's normal vector: */
			Card i1=edges[i].next;
			Vector d0=edges[i1].start-edges[i].start;
			Card i2=edges[i1].next;
			Vector d1=edges[i2].start-edges[i1].start;
			Vector normal=Geometry::cross(d0,d1);
			normal.normalize();
			glNormal(normal);
			
			/* Traverse all edges of the face: */
			Card j=i;
			do
				{
				glVertex(edges[j].start);
				visitedEdges.setEntry(IndexSet::Entry(j));
				j=edges[j].next;
				}
			while(j!=i);
			
			glEnd();
			}
		}
	}
Пример #11
0
//draw a cube face at the specified color
 void drawQuad(int poly)
{	
	
	u32 f1 = CubeFaces[poly * 4] ;
	u32 f2 = CubeFaces[poly * 4 + 1] ;
	u32 f3 = CubeFaces[poly * 4 + 2] ;
	u32 f4 = CubeFaces[poly * 4 + 3] ;


	glNormal(normals[poly]);

	GFX_TEX_COORD = (uv[0]);
	glVertex3v16(CubeVectors[f1*3], CubeVectors[f1*3 + 1], CubeVectors[f1*3 +  2] );
	
	GFX_TEX_COORD = (uv[1]);
	glVertex3v16(CubeVectors[f2*3], CubeVectors[f2*3 + 1], CubeVectors[f2*3 + 2] );
	
	GFX_TEX_COORD = (uv[2]);
	glVertex3v16(CubeVectors[f3*3], CubeVectors[f3*3 + 1], CubeVectors[f3*3 + 2] );

	GFX_TEX_COORD = (uv[3]);
	glVertex3v16(CubeVectors[f4*3], CubeVectors[f4*3 + 1], CubeVectors[f4*3 + 2] );
}
void OctahedronRenderer::initContext(GLContextData& contextData) const
	{
	/* Create context data item: */
	DataItem* dataItem=new DataItem;
	contextData.addDataItem(this,dataItem);
	
	/* Create model display list: */
	glNewList(dataItem->displayListId,GL_COMPILE);
	
	/* Render octahedron: */
	static const int faceVertexIndices[8][3]={{2,0,4},{1,2,4},{3,1,4},{0,3,4},
	                                          {0,2,5},{2,1,5},{1,3,5},{3,0,5}};
	glBegin(GL_TRIANGLES);
	for(int face=0;face<8;++face)
		{
		glNormal(Octahedron::renderNormals[face]);
		for(int i=0;i<3;++i)
			glVertex(Octahedron::renderVertices[faceVertexIndices[face][i]]);
		}
	glEnd();
	
	/* Finish model display list: */
	glEndList();
	}
Пример #13
0
void GlyphGadget::draw(GLContextData& contextData) const
	{
	/* Draw the margin around the glyph: */
	switch(glyphType)
		{
		case NONE:
			glBegin(GL_QUADS);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[2]);
			glEnd();
			break;
		
		case SQUARE:
		case LOW_BAR:
			glBegin(GL_QUAD_STRIP);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[5]);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[0]);
			glEnd();
			break;
		
		case DIAMOND:
			glBegin(GL_TRIANGLE_FAN);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[2]);
			glEnd();
			glBegin(GL_TRIANGLE_FAN);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[5]);
			glVertex(glyphVertices[1]);
			glEnd();
			glBegin(GL_TRIANGLES);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[5]);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[6]);
			glEnd();
			break;
		
		case CROSS:
			glBegin(GL_TRIANGLE_FAN);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[15]);
			glVertex(glyphVertices[13]);
			glVertex(glyphVertices[2]);
			glEnd();
			glBegin(GL_TRIANGLE_FAN);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[12]);
			glVertex(glyphVertices[10]);
			glVertex(glyphVertices[9]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[1]);
			glEnd();
			glBegin(GL_TRIANGLES);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[5]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[9]);
			glVertex(glyphVertices[8]);
			glVertex(glyphVertices[10]);
			glVertex(glyphVertices[12]);
			glVertex(glyphVertices[11]);
			glVertex(glyphVertices[12]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[13]);
			glVertex(glyphVertices[13]);
			glVertex(glyphVertices[15]);
			glVertex(glyphVertices[14]);
			glEnd();
			break;
		
		case SIMPLE_ARROW_LEFT:
		case SIMPLE_ARROW_DOWN:
		case SIMPLE_ARROW_RIGHT:
		case SIMPLE_ARROW_UP:
			glBegin(GL_TRIANGLE_FAN);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[5]);
			glEnd();
			glBegin(GL_TRIANGLES);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[5]);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[6]);
			glEnd();
			glBegin(GL_QUADS);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[5]);
			glEnd();
			break;
		
		case FANCY_ARROW_LEFT:
		case FANCY_ARROW_DOWN:
		case FANCY_ARROW_RIGHT:
		case FANCY_ARROW_UP:
			glBegin(GL_TRIANGLE_FAN);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[4]);
			glVertex(glyphVertices[10]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[0]);
			glVertex(glyphVertices[5]);
			glEnd();
			glBegin(GL_TRIANGLE_FAN);
			glVertex(glyphVertices[1]);
			glVertex(glyphVertices[8]);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[6]);
			glVertex(glyphVertices[5]);
			glVertex(glyphVertices[0]);
			glEnd();
			glBegin(GL_TRIANGLE_FAN);
			glVertex(glyphVertices[3]);
			glVertex(glyphVertices[2]);
			glVertex(glyphVertices[10]);
			glVertex(glyphVertices[9]);
			glVertex(glyphVertices[8]);
			glVertex(glyphVertices[1]);
			glEnd();
			break;
		}
	
	/* Draw the glyph bevel: */
	glBegin(GL_QUADS);
	glColor(glyphColor);
	for(int i=0;i<numNormals;++i)
		{
		glNormal(glyphNormals[i]);
		int i1=(i+1)%numNormals;
		glVertex(glyphVertices[4+i]);
		glVertex(glyphVertices[4+i1]);
		glVertex(glyphVertices[innerStart+i1]);
		glVertex(glyphVertices[innerStart+i]);
		}
	glEnd();
	
	/* Draw the glyph face: */
	switch(glyphType)
		{
		case NONE:
			break;
		
		case SQUARE:
		case DIAMOND:
		case LOW_BAR:
			glBegin(GL_QUADS);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[8]);
			glVertex(glyphVertices[9]);
			glVertex(glyphVertices[10]);
			glVertex(glyphVertices[11]);
			glEnd();
			break;
		
		case CROSS:
			glBegin(GL_QUADS);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[16]);
			glVertex(glyphVertices[17]);
			glVertex(glyphVertices[26]);
			glVertex(glyphVertices[27]);
			glVertex(glyphVertices[17]);
			glVertex(glyphVertices[18]);
			glVertex(glyphVertices[19]);
			glVertex(glyphVertices[20]);
			glVertex(glyphVertices[20]);
			glVertex(glyphVertices[21]);
			glVertex(glyphVertices[22]);
			glVertex(glyphVertices[23]);
			glVertex(glyphVertices[23]);
			glVertex(glyphVertices[24]);
			glVertex(glyphVertices[25]);
			glVertex(glyphVertices[26]);
			glVertex(glyphVertices[17]);
			glVertex(glyphVertices[20]);
			glVertex(glyphVertices[23]);
			glVertex(glyphVertices[26]);
			glEnd();
			break;
		
		case SIMPLE_ARROW_LEFT:
		case SIMPLE_ARROW_DOWN:
		case SIMPLE_ARROW_RIGHT:
		case SIMPLE_ARROW_UP:
			glBegin(GL_TRIANGLES);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex(glyphVertices[7]);
			glVertex(glyphVertices[8]);
			glVertex(glyphVertices[9]);
			glEnd();
			break;
		
		case FANCY_ARROW_LEFT:
		case FANCY_ARROW_DOWN:
		case FANCY_ARROW_RIGHT:
		case FANCY_ARROW_UP:
			glBegin(GL_TRIANGLE_FAN);
			glNormal3f(0.0f,0.0f,1.0f);
			for(int i=11;i<18;++i)
				glVertex(glyphVertices[i]);
			glEnd();
			break;
		}
	}
Пример #14
0
void logo()
{
	glResetMatrixStack();
	glMatrixMode(GL_PROJECTION);
	gluPerspective(20, 256.0 / 192.0, 0.1, 40);

	gluLookAt(	0.0, .55, 0.0 ,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 0.0, -1.0);		//up
				


	glLight(0, RGB15(31,31,31), 0,	floattov10(1.0)-1, 0);
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	
	glMaterialf(GL_AMBIENT, RGB15(8,8,8));
	glMaterialf(GL_DIFFUSE, RGB15(31,31,31));
	glMaterialf(GL_SPECULAR, RGB15(31,31,31));
	glMaterialf(GL_EMISSION, RGB15(8,8,8));
	glMaterialShinyness();
	glPolyFmt( POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 );
		
		
	glGenTextures(1, &logotex);
	glBindTexture(0, logotex);
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD , (u8*)billkuker_bmp_bin);
	glBindTexture(0, logotex);

	glBegin(GL_QUAD);
		glNormal(NORMAL_PACK(0,inttov10(1),0));

		glTexCoord1i(TEXTURE_PACK(0,0));
		glVertex3v16(floattov16(-0.5), floattov16(-0.5), floattov16(0.5) );
		
		glTexCoord1i(TEXTURE_PACK(inttot16(256), inttot16(0)));
		glVertex3v16(floattov16(0.5), floattov16(-0.5), floattov16(0.5) );

		glTexCoord1i(TEXTURE_PACK(inttot16(256),inttot16(256)));
		glVertex3v16(floattov16(0.5), floattov16(-0.5), floattov16(-0.5) );
		
		glTexCoord1i(TEXTURE_PACK(0, inttot16(256)));
		glVertex3v16(floattov16(-0.5),	floattov16(-0.5), floattov16(-0.5) );
	glEnd();
	
	glFlush(0);
	
	playGenericSound(down_raw, down_raw_size);
	playGenericSound(up_raw, up_raw_size);
	
	swiWaitForVBlank();
	
	iprintf("Press any button");
	
	while( !keysHeld() )
		scanKeys();
		
	glResetTextures();
	iprintf("\x1b[2J");
}
Пример #15
0
int main() {	
	
	int textureID;

	float rotateX = 0.0;
	float rotateY = 0.0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	// initialize gl
	glInit();
	
	//enable textures
	glEnable(GL_TEXTURE_2D);
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	//this should work the same as the normal gl call
	glViewport(0,0,255,191);
	
	vramSetBankA(VRAM_A_TEXTURE);

	glGenTextures(1, &textureID);
	glBindTexture(0, textureID);
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin);
	
	
	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 40);
	
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up	
	
	while(1) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();

		//move it away from the camera
		glTranslate3f32(0, 0, floattof32(-1));
				
		glRotateX(rotateX);
		glRotateY(rotateY);
		
		

		glMaterialf(GL_AMBIENT, RGB15(16,16,16));
		glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
		glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
		glMaterialf(GL_EMISSION, RGB15(16,16,16));

		//ds uses a table for shinyness..this generates a half-ass one
		glMaterialShinyness();

		//not a real gl function and will likely change
		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK);

		scanKeys();
		
		u16 keys = keysHeld();
		
		if((keys & KEY_UP)) rotateX += 3;
		if((keys & KEY_DOWN)) rotateX -= 3;
		if((keys & KEY_LEFT)) rotateY += 3;
		if((keys & KEY_RIGHT)) rotateY -= 3;
		
		glBindTexture(0, textureID);

		//draw the obj
		glBegin(GL_QUAD);
			glNormal(NORMAL_PACK(0,inttov10(-1),0));

			GFX_TEX_COORD = (TEXTURE_PACK(0, inttot16(128)));
			glVertex3v16(floattov16(-0.5),	floattov16(-0.5), 0 );
	
			GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128),inttot16(128)));
			glVertex3v16(floattov16(0.5),	floattov16(-0.5), 0 );
	
			GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128), 0));
			glVertex3v16(floattov16(0.5),	floattov16(0.5), 0 );

			GFX_TEX_COORD = (TEXTURE_PACK(0,0));
			glVertex3v16(floattov16(-0.5),	floattov16(0.5), 0 );
		
		glEnd();
		
		glPopMatrix(1);
			
		glFlush(0);

		swiWaitForVBlank();
	}

	return 0;
}//end main 
Пример #16
0
int renderModel(struct MODEL * model)
{
	int v_one, v_two, v_thr;
	int c_one, c_two, c_thr;
	//int n_one, n_two, n_thr;
	int t_one, t_two, t_thr;
	v16 v_x, v_y, v_z;
	t16 u_m, v_m;
	char r, g, b;
	//v16 n_x, n_y, n_z;
	
	int objectC = 0;
	int triangleC = 0;
	
	while(objectC < model->header.objectCount)
	{
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		
		unsigned char mat = model->faces.object[objectC].materialID;
		unsigned char X = model->materials.material[mat].X;
		unsigned char Y = model->materials.material[mat].Y;
		unsigned char TX = model->materials.material[mat].TX;
		unsigned char TY = model->materials.material[mat].TY;
		unsigned char A = model->materials.material[mat].alpha;
		unsigned char C = model->materials.material[mat].culling;
		
		glPolyFmt(POLY_ALPHA(A) | C);
		
		if(TX != 0 || TY != 0)
		{
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glTranslatef(model->materials.material[mat].scrollX, model->materials.material[mat].scrollY, 0);
			model->materials.material[mat].scrollX += TX;
			model->materials.material[mat].scrollY += TY;
		}
		
		glBindTexture(GL_TEXTURE_2D, model->textures[mat]);
		
		while(triangleC < model->faces.object[objectC].triangleCount)
		{
			v_one = model->faces.object[objectC].triangles[triangleC].triangle[0].v;
			v_two = model->faces.object[objectC].triangles[triangleC].triangle[1].v;
			v_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].v;
			c_one = model->faces.object[objectC].triangles[triangleC].triangle[0].c;
			c_two = model->faces.object[objectC].triangles[triangleC].triangle[1].c;
			c_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].c;
			/*n_one = model->faces.object[objectC].triangles[triangleC].triangle[0].n;
			n_two = model->faces.object[objectC].triangles[triangleC].triangle[1].n;
			n_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].n;*/
			t_one = model->faces.object[objectC].triangles[triangleC].triangle[0].t;
			t_two = model->faces.object[objectC].triangles[triangleC].triangle[1].t;
			t_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].t;
			
			glBegin(GL_TRIANGLES);
			glNormal(NORMAL_PACK( 0, 0, 1<<10));
						
			v_x = model->vertices.vertex[v_one].x;
			v_y = model->vertices.vertex[v_one].y;
			v_z = model->vertices.vertex[v_one].z;
			r = model->colors.color[c_one].r;
			g = model->colors.color[c_one].g;
			b = model->colors.color[c_one].b;
			/*n_x = model->normals.normal[n_one].x;
			n_y = model->normals.normal[n_one].y;
			n_z = model->normals.normal[n_one].z;
			glNormal3f(n_x, n_y, n_z);*/
			u_m = model->coordinates.coordinate[t_one].u;
			v_m = model->coordinates.coordinate[t_one].v;
			glColor3b(r,g,b);
			glTexCoord2t16(u_m * X,v_m * Y);
			glVertex3v16(v_x, v_y, v_z);
			
			v_x = model->vertices.vertex[v_two].x;
			v_y = model->vertices.vertex[v_two].y;
			v_z = model->vertices.vertex[v_two].z;
			r = model->colors.color[c_two].r;
			g = model->colors.color[c_two].g;
			b = model->colors.color[c_two].b;
			/*n_x = model->normals.normal[n_two].x;
			n_y = model->normals.normal[n_two].y;
			n_z = model->normals.normal[n_two].z;
			glNormal3f(n_x, n_y, n_z);*/
			u_m = model->coordinates.coordinate[t_two].u;
			v_m = model->coordinates.coordinate[t_two].v;
			glColor3b(r,g,b);
			glTexCoord2t16(u_m * X,v_m * Y);
			glVertex3v16(v_x, v_y, v_z);
			
			v_x = model->vertices.vertex[v_thr].x;
			v_y = model->vertices.vertex[v_thr].y;
			v_z = model->vertices.vertex[v_thr].z;
			r = model->colors.color[c_thr].r;
			g = model->colors.color[c_thr].g;
			b = model->colors.color[c_thr].b;
			/*n_x = model->normals.normal[n_thr].x;
			n_y = model->normals.normal[n_thr].y;
			n_z = model->normals.normal[n_thr].z;
			glNormal3f(n_x, n_y, n_z);*/
			u_m = model->coordinates.coordinate[t_thr].u;
			v_m = model->coordinates.coordinate[t_thr].v;
			glColor3b(r,g,b);
			glTexCoord2t16(u_m * X,v_m * Y);
			glVertex3v16(v_x, v_y, v_z);
			
			glEnd();
			
			triangleC++;
		}
		
		glPopMatrix(1);
		
		triangleC = 0;
		objectC++;
	}
	
	return 1;
}
Пример #17
0
void IndexedFaceSetNode::glRenderAction(VRMLRenderState& renderState) const
	{
	/* Retrieve the data item from the context: */
	DataItem* dataItem=renderState.contextData.retrieveDataItem<DataItem>(this);
	
	const TextureCoordinateNode* texCoordNode=dynamic_cast<const TextureCoordinateNode*>(texCoord.getPointer());
	const ColorNode* colorNode=dynamic_cast<const ColorNode*>(color.getPointer());
	const NormalNode* normalNode=dynamic_cast<const NormalNode*>(normal.getPointer());
	const CoordinateNode* coordNode=dynamic_cast<const CoordinateNode*>(coord.getPointer());
	
	/* Set up OpenGL: */
	if(ccw)
		glFrontFace(GL_CCW);
	else
		glFrontFace(GL_CW);
	if(solid)
		{
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
		glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);
		}
	else
		{
		glDisable(GL_CULL_FACE);
		glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
		}
	
	if(dataItem->vertexBufferObjectId!=0&&dataItem->indexBufferObjectId!=0)
		{
		/* Determine which parts of the vertex array to enable: */
		int vertexPartsMask=0;
		if(texCoordNode!=0)
			vertexPartsMask|=GLVertexArrayParts::TexCoord;
		if(colorNode!=0)
			vertexPartsMask|=GLVertexArrayParts::Color;
		if(normalNode!=0)
			vertexPartsMask|=GLVertexArrayParts::Normal;
		vertexPartsMask|=GLVertexArrayParts::Position;
		
		/* Draw the indexed triangle set: */
		GLVertexArrayParts::enable(vertexPartsMask);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB,dataItem->vertexBufferObjectId);
		glVertexPointer(vertexPartsMask,static_cast<const Vertex*>(0));
		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,dataItem->indexBufferObjectId);
		glDrawElements(GL_TRIANGLES,dataItem->numTriangles*3,GL_UNSIGNED_INT,static_cast<const GLuint*>(0));
		glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
		GLVertexArrayParts::disable(vertexPartsMask);
		}
	else
		{
		/* Process all faces: */
		std::vector<int>::const_iterator texCoordIt=texCoordIndices.empty()?coordIndices.begin():texCoordIndices.begin();
		std::vector<int>::const_iterator colorIt=colorIndices.empty()?coordIndices.begin():colorIndices.begin();
		int colorCounter=0;
		std::vector<int>::const_iterator normalIt=normalIndices.empty()?coordIndices.begin():normalIndices.begin();
		int normalCounter=0;
		std::vector<int>::const_iterator coordIt=coordIndices.begin();
		while(coordIt!=coordIndices.end())
			{
			glBegin(GL_POLYGON);
			while(*coordIt>=0)
				{
				if(texCoordNode!=0)
					glTexCoord(texCoordNode->getPoint(*texCoordIt));
				if(colorNode!=0)
					{
					if(!colorPerVertex&&colorIndices.empty())
						glColor(colorNode->getColor(colorCounter));
					else
						glColor(colorNode->getColor(*colorIt));
					}
				if(normalNode!=0)
					{
					if(!normalPerVertex&&normalIndices.empty())
						glNormal(normalNode->getVector(normalCounter));
					else
						glNormal(normalNode->getVector(*normalIt));
					}
				glVertex(coordNode->getPoint(*coordIt));
				++texCoordIt;
				if(colorPerVertex)
					++colorIt;
				if(normalPerVertex)
					++normalIt;
				++coordIt;
				}
			glEnd();
			
			++texCoordIt;
			if(!colorPerVertex&&colorIndices.empty())
				++colorCounter;
			else
				++colorIt;
			if(!normalPerVertex&&normalIndices.empty())
				++normalCounter;
			else
				++normalIt;
			++coordIt;
			}
		}
	
	/* Reset OpenGL state: */
	if(!ccw)
		glFrontFace(GL_CCW);
	if(!solid)
		{
		glEnable(GL_CULL_FACE);
		glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);
		}
	}
Пример #18
0
static void drawModel(v16 v[][3], int n[], v16 t[][2], int faces[][3][3], unsigned int nfaces )
{

    if (drawMode == 0)
    {
        glBegin(GL_TRIANGLES);
        for (unsigned int i=0; i < nfaces; i++) {

            glNormal(n[faces[i][0][2]]);
            glVertex3v16v(v[faces[i][0][0]]);

            glNormal(n[faces[i][1][2]]);
            glVertex3v16v(v[faces[i][1][0]]);

            glNormal(n[faces[i][2][2]]);
            glVertex3v16v(v[faces[i][2][0]]);
        }
        glEnd();
    }

    if (drawMode == 1)
    {
        glBegin(GL_TRIANGLES);
        for (unsigned int i=0; i < nfaces; i++) {

            //1
            glNormal(n[faces[i][0][2]]);
            glVertex3v16v(v[faces[i][0][0]]);
            //2
            glNormal(n[faces[i][1][2]]);
            glVertex3v16v(v[faces[i][1][0]]);
            //2
            glNormal(n[faces[i][1][2]]);
            glVertex3v16v(v[faces[i][1][0]]);
            
            //1
            glNormal(n[faces[i][0][2]]);
            glVertex3v16v(v[faces[i][0][0]]);
            //3
            glNormal(n[faces[i][2][2]]);
            glVertex3v16v(v[faces[i][2][0]]);
            //3
            glNormal(n[faces[i][2][2]]);
            glVertex3v16v(v[faces[i][2][0]]);
            
            //3
            glNormal(n[faces[i][2][2]]);
            glVertex3v16v(v[faces[i][2][0]]);
            //2
            glNormal(n[faces[i][1][2]]);
            glVertex3v16v(v[faces[i][1][0]]);
            //2
            glNormal(n[faces[i][1][2]]);
            glVertex3v16v(v[faces[i][1][0]]);
            
        }
        glEnd();
    }

}
Пример #19
0
void CylinderPrimitive::initContext(GLContextData& contextData) const
	{
	/* Create a data item and store it in the context: */
	DataItem* dataItem=new DataItem;
	contextData.addDataItem(this,dataItem);
	
	/* Create a coordinate system for the cylinder: */
	Vector cx=Geometry::normal(axis);
	cx.normalize();
	Vector cy=Geometry::cross(axis,cx);
	cy.normalize();
	Vector cz=axis*(length/Scalar(2));
	
	/* Create the cylinder rendering display lists: */
	glNewList(dataItem->displayListId,GL_COMPILE);
	
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_CULL_FACE);
	glBegin(GL_QUAD_STRIP);
	glNormal(1.0,0.0,0.0);
	glVertex(center+cx*radius+cz);
	glVertex(center+cx*radius-cz);
	for(int x=1;x<72;++x)
		{
		Scalar angle=Math::rad(Scalar(x)*Scalar(360/72));
		Vector d=cx*Math::cos(angle)+cy*Math::sin(angle);
		glNormal(d);
		d*=radius;
		glVertex(center+d+cz);
		glVertex(center+d-cz);
		}
	glNormal(1.0,0.0,0.0);
	glVertex(center+cx*radius+cz);
	glVertex(center+cx*radius-cz);
	glEnd();
	
	glEndList();
	
	glNewList(dataItem->displayListId+1,GL_COMPILE);
	
	glBlendFunc(GL_ONE,GL_ONE);
	glLineWidth(1.0f);
	glBegin(GL_LINES);
	for(int x=0;x<numX;++x)
		{
		Scalar angle=Math::rad(Scalar(x)*Scalar(360)/Scalar(numX));
		Vector d=cx*Math::cos(angle)+cy*Math::sin(angle);
		d*=radius;
		glVertex(center+d+cz);
		glVertex(center+d-cz);
		}
	glEnd();
	for(int y=0;y<=numY;++y)
		{
		Point center2=center+axis*((Scalar(y)/Scalar(numY)-Scalar(0.5))*length);
		glBegin(GL_LINE_LOOP);
		for(int x=0;x<72;++x)
			{
			Scalar angle=Math::rad(Scalar(x)*Scalar(360/72));
			Vector d=cx*Math::cos(angle)+cy*Math::sin(angle);
			d*=radius;
			glVertex(center2+d);
			}
		glEnd();
		}
	
	glEndList();
	}