Exemple #1
0
static void BuildLists(void)
{

    lists[CUBE] = glGenLists(1);
    BuildCube();
    lists[SQUARE] = glGenLists(1);
    BuildSquare();
    lists[PUSHPOP] = glGenLists(1);
    BuildPushPopTest();
}
Exemple #2
0
void BuildLists(void)
{

    cube = glGenLists(1);
    BuildCube();

    cage = glGenLists(2);
    BuildCage();

    cylinder = glGenLists(3);
    BuildCylinder(60);

    torus = glGenLists(4);
    BuildTorus(0.65, 20, .85, 65);

    genericObject = torus;
}
Exemple #3
0
//--------------------------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------------------------
SkyBox::SkyBox( float fSize )
{
	//we might want to use a sphere for the sky, I keep this code just in case.
	//BuildSphere(fSize, 100, 100 );
	BuildCube( fSize );
}
Exemple #4
0
static void BuildLists(void)
{

    cube = glGenLists(1);
    BuildCube();
}
Exemple #5
0
void BuildGeometry (unsigned int surface, unsigned int colorScheme, unsigned int subdivisions, unsigned int xyRatio,
					GLuint * polyList, GLuint * lineList, GLuint * pointList)
{
	long i,j, index;
	long maxI = subdivisions * xyRatio, maxJ = subdivisions;
	double u, v, delta=0.001;
	recVec p1,p2;
	recVec *vertexPos = NULL,*vertexNormal = NULL;
	recColor *vertexColor = NULL;
	recTexCoord *vertexTexCoord = NULL;

	// set valid surface and color scheme
	surface %= kSurfaces;
	colorScheme %= kColorSchemes;

	// delete existing list
	if (*polyList)
		glDeleteLists (*polyList, 1);
	if (*lineList)
		glDeleteLists (*lineList, 1);
	if (*pointList)
		glDeleteLists (*pointList, 1);
	*polyList = *lineList = *pointList = 0;
	
	if (surface == kCube) // build the standard color cube (disregard color, subdivisions, and xyRatio)
		BuildCube (polyList, lineList, pointList, colorScheme);
	else {
		// build buffers
		vertexPos = (recVec*) malloc ((maxI) * (maxJ) * sizeof (recVec));
		if (vertexNormal)
			free (vertexNormal);
		vertexNormal = (recVec*) malloc ((maxI) * (maxJ) * sizeof (recVec));
		if (vertexColor)
			free (vertexColor);
		vertexColor = (recColor*) malloc ((maxI) * (maxJ) * sizeof (recColor));
		if (vertexTexCoord)
			free (vertexTexCoord);
		vertexTexCoord = (recTexCoord*) malloc ((maxI) * (maxJ) * sizeof (recTexCoord));
		if (!vertexPos || !vertexNormal || !vertexColor || !vertexTexCoord)
			return;
			
		// build surface
		for (i = 0; i < maxI; i++) {
			for (j = 0; j < maxJ; j++) {
				index = i * maxJ + j;
				u  = -PI + (i % maxI) * TWOPI / maxI;
				v  = -PI + (j % maxJ) * TWOPI / maxJ;
				vertexPos[index] = Eval(u,v, surface);
				p1 = Eval(u + delta, v, surface);
				p2 = Eval(u, v + delta, surface);
				vertexNormal[index] = CalcNormal(vertexPos[index],p1,p2);
				vertexColor[index] = getColor(u, -PI, PI, colorScheme);
				vertexTexCoord[index].s = (float) i * 5.0f / (float) maxI;
				vertexTexCoord[index].t = (float) j * 1.0f/ (float) maxJ;
			}
		}
		
		*polyList = glGenLists (1);
		glNewList(*polyList, GL_COMPILE);
			for (i=0; i< maxI; i++) {
				glBegin(GL_TRIANGLE_STRIP);
				for (j = 0; j <= maxJ; j++) {
					index = (i % maxI) * maxJ + (j % maxJ);
					glColor3fv (&vertexColor[index].r);
					glNormal3fv (&vertexNormal[index].x);
					glTexCoord2fv (&vertexTexCoord[index].s);
					glVertex3fv (&vertexPos[index].x);
		
					index = ((i + 1) % maxI) * maxJ + (j % maxJ);
					glColor3fv (&vertexColor[index].r);
					glNormal3fv (&vertexNormal[index].x);
					glTexCoord2fv (&vertexTexCoord[index].s);
					glVertex3fv (&vertexPos[index].x);
//					index = ((i - 1) % maxI) * maxJ + (j % maxJ);
				}
				glEnd ();
			}
		glEndList ();
	
		*lineList = glGenLists (1);
		glNewList(*lineList, GL_COMPILE);
			for (i=0; i< maxI; i++) {
				glBegin(GL_LINE_STRIP);
				for (j = 0; j < maxJ; j++) {
					index = i * maxJ + j;
					glColor3fv (&vertexColor[index].r);
					glVertex3fv (&vertexPos[index].x);
				}
				index = i * maxJ + 0;
				glColor3fv (&vertexColor[index].r);
				glVertex3fv (&vertexPos[index].x);
				glEnd ();
			}
			for (j=0; j< maxJ; j++) {
				glBegin(GL_LINE_STRIP);
				for (i = 0; i < maxI; i++) {
					index = i * maxJ + j;
					glColor3fv (&vertexColor[index].r);
					glVertex3fv (&vertexPos[index].x);
				}
				index = 0 + j;
				glColor3fv (&vertexColor[index].r);
				glVertex3fv (&vertexPos[index].x);
				glEnd ();
			}
		glEndList ();
	
		*pointList = glGenLists (1);
		glNewList(*pointList, GL_COMPILE);
			glBegin(GL_POINTS);
			for (i=0; i< maxI; i++) {
				for (j = 0; j < maxJ; j++) {
					index = i * maxJ + j;
					glColor3fv (&vertexColor[index].r);
					glVertex3fv (&vertexPos[index].x);
				}
			}
			glEnd ();
		glEndList ();
		free (vertexPos);
		free (vertexNormal);
		free (vertexColor);
	}
}