int Application3::Render()
{
	GzCamera	camera;
	GzToken		nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer	valueListTriangle[3]; 	/* vertex attribute pointers */
	GzToken		nameListColor[3];		/* color type names */
	GzPointer	valueListColor[3];	/* color type rgb pointers */
	GzColor		color;
	GzCoord		vertexList[3];	/* vertex position coordinates */
	GzCoord		normalList[3];	/* vertex normals */
	GzTextureIndex  	uvList[3];		/* vertex texture map indices */
	char		dummy[256];
	int			i, j;
	int			xRes, yRes, dispClass;	/* display parameters */
	int			status;

	status = 0;

	status |= GzInitDisplay(m_pDisplay);

	/*
	* Tokens associated with triangle vertex values
	*/
	nameListTriangle[0] = GZ_POSITION;

	// I/O File open
	FILE *infile;
	if ((infile = fopen(INFILE3, "r")) == NULL)
	{
		AfxMessageBox("The input file was not opened\n");
		return GZ_FAILURE;
	}

	FILE *outfile;
	if ((outfile = fopen(OUTFILE3, "wb")) == NULL)
	{
		AfxMessageBox("The output file was not opened\n");
		return GZ_FAILURE;
	}

	/*
	* Walk through the list of triangles, set color
	* and render each triangle
	*/
	i = 0;
	while (fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
		fscanf(infile, "%f %f %f %f %f %f %f %f",
			&(vertexList[0][0]), &(vertexList[0][1]),
			&(vertexList[0][2]),
			&(normalList[0][0]), &(normalList[0][1]),
			&(normalList[0][2]),
			&(uvList[0][0]), &(uvList[0][1]));
		fscanf(infile, "%f %f %f %f %f %f %f %f",
			&(vertexList[1][0]), &(vertexList[1][1]),
			&(vertexList[1][2]),
			&(normalList[1][0]), &(normalList[1][1]),
			&(normalList[1][2]),
			&(uvList[1][0]), &(uvList[1][1]));
		fscanf(infile, "%f %f %f %f %f %f %f %f",
			&(vertexList[2][0]), &(vertexList[2][1]),
			&(vertexList[2][2]),
			&(normalList[2][0]), &(normalList[2][1]),
			&(normalList[2][2]),
			&(uvList[2][0]), &(uvList[2][1]));

		/*
		* Set up shading attributes for each triangle
		*/
		shade(normalList[0], color);/* shade based on the norm of vert0 */
		valueListColor[0] = (GzPointer)color;
		nameListColor[0] = GZ_RGB_COLOR;
		GzPutAttribute(m_pRender, 1, nameListColor, valueListColor);

		/*
		* Set the value pointers to the first vertex of the
		* triangle, then feed it to the renderer
		*/
		valueListTriangle[0] = (GzPointer)vertexList;
		GzPutTriangle(m_pRender, 1, nameListTriangle, valueListTriangle);
	}

	GzFlushDisplay2File(outfile, m_pDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pDisplay);	// write out or update display to frame buffer

	/*
	 * Close file
	 */

	if (fclose(infile))
		AfxMessageBox("The input file was not closed\n");

	if (fclose(outfile))
		AfxMessageBox("The output file was not closed\n");

	if (status)
		return(GZ_FAILURE);
	else
		return(GZ_SUCCESS);
}
Example #2
0
void CCS580HWView::OnAnimation()
{
	// TODO: Add your command handler code here

	GzCamera	camera;
	GzToken		nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer	valueListTriangle[3]; 	/* vertex attribute pointers */
	GzToken		nameListColor[3];		/* color type names */
	GzPointer	valueListColor[3];	/* color type rgb pointers */
	GzColor		color;
	GzCoord		vertexList[3];	/* vertex position coordinates */
	GzCoord		normalList[3];	/* vertex normals */
	GzTextureIndex  	uvList[3];		/* vertex texture map indices */
	char		dummy[256];
	int			i, j;
	int			xRes, yRes, dispClass;	/* display parameters */
	int			status;

	
	nameListTriangle[0] = GZ_POSITION;

	/*
	* Walk through the list of triangles, set color
	* and render each triangle
	*/
	FILE *outfile;
	FILE *infile;
	for (; m_pApplication->m_pRender->anilevelnow <= m_pApplication->m_pRender->anilevel; m_pApplication->m_pRender->anilevelnow++){
		GzInitDisplay(m_pApplication->m_pDisplay);
		if ((infile = fopen("pot4.asc", "r")) == NULL)
		{
			AfxMessageBox(_T("The input file was not opened\n"));
		}
		//_cprintf("%s#%d\n", "CS580HWView", m_pApplication->m_pRender->anilevelnow);
		if ((outfile = fopen(("animation/output" + std::to_string(m_pApplication->m_pRender->anilevelnow) + ".ppm").c_str(), "wb")) == NULL)
		{
			AfxMessageBox(_T("The output file was not opened\n"));
		}
		while (fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
			fscanf(infile, "%f %f %f %f %f %f %f %f",
				&(vertexList[0][0]), &(vertexList[0][1]),
				&(vertexList[0][2]),
				&(normalList[0][0]), &(normalList[0][1]),
				&(normalList[0][2]),
				&(uvList[0][0]), &(uvList[0][1]));
			fscanf(infile, "%f %f %f %f %f %f %f %f",
				&(vertexList[1][0]), &(vertexList[1][1]),
				&(vertexList[1][2]),
				&(normalList[1][0]), &(normalList[1][1]),
				&(normalList[1][2]),
				&(uvList[1][0]), &(uvList[1][1]));
			fscanf(infile, "%f %f %f %f %f %f %f %f",
				&(vertexList[2][0]), &(vertexList[2][1]),
				&(vertexList[2][2]),
				&(normalList[2][0]), &(normalList[2][1]),
				&(normalList[2][2]),
				&(uvList[2][0]), &(uvList[2][1]));


			//		GzPutAttribute(m_pRender, 1, nameListColor, valueListColor);
			shadeForAnimation(normalList[0], color);/* shade based on the norm of vert0 */
			valueListColor[0] = (GzPointer)color;
			nameListColor[0] = GZ_RGB_COLOR;
			GzPutAttribute(m_pApplication->m_pRender, 1, nameListColor, valueListColor);
			/*
			* Set the value pointers to the first vertex of the
			* triangle, then feed it to the renderer
			*/
			valueListTriangle[0] = (GzPointer)vertexList;
			AnimationPutTriangle(m_pApplication->m_pRender, 1, nameListTriangle, valueListTriangle);
		}
		//_cprintf("%s\n", "write to file");
		GzFlushDisplay2File(outfile, m_pApplication->m_pDisplay); 	/* write out or update display to file*/
		if (fclose(outfile))
			AfxMessageBox(_T("The output file was not closed\n")); 
		if (fclose(infile))
			AfxMessageBox(_T("The input file was not closed\n"));
	}
	AfxMessageBox(_T("YAY! It's done! please check the animation folder! :)\n"));
		
}
int Application5::Render() 
{
	GzToken		nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer	valueListTriangle[3]; 	/* vertex attribute pointers */
	GzCoord		vertexList[3];	/* vertex position coordinates */ 
	GzCoord		normalList[3];	/* vertex normals */ 
	GzTextureIndex  	uvList[3];		/* vertex texture map indices */ 
	char		dummy[256]; 
	int			status; 


	/* Initialize Display */
	for (int i = 0; i < AAKERNEL_SIZE; i++)
	{
		status |= GzInitDisplay(m_pDisplay[i]); 
	}
	/* 
	* Tokens associated with triangle vertex values 
	*/ 
	nameListTriangle[0] = GZ_POSITION; 
	nameListTriangle[1] = GZ_NORMAL; 
	nameListTriangle[2] = GZ_TEXTURE_INDEX;  

	// I/O File open
	FILE *infile;
	if( (infile  = fopen( INFILE , "r" )) == NULL )
	{
         AfxMessageBox( "The input file was not opened\n" );
		 return GZ_FAILURE;
	}

	FILE *outfile;
	if( (outfile  = fopen( OUTFILE , "wb" )) == NULL )
	{
         AfxMessageBox( "The output file was not opened\n" );
		 return GZ_FAILURE;
	}

	/* 
	* Walk through the list of triangles, set color 
	* and render each triangle 
	*/ 
	while( fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[0][0]), &(vertexList[0][1]),  
		&(vertexList[0][2]), 
		&(normalList[0][0]), &(normalList[0][1]), 	
		&(normalList[0][2]), 
		&(uvList[0][0]), &(uvList[0][1]) ); 
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[1][0]), &(vertexList[1][1]), 	
		&(vertexList[1][2]), 
		&(normalList[1][0]), &(normalList[1][1]), 	
		&(normalList[1][2]), 
		&(uvList[1][0]), &(uvList[1][1]) ); 
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[2][0]), &(vertexList[2][1]), 	
		&(vertexList[2][2]), 
		&(normalList[2][0]), &(normalList[2][1]), 	
		&(normalList[2][2]), 
		&(uvList[2][0]), &(uvList[2][1]) ); 

	    /* 
	     * Set the value pointers to the first vertex of the 	
	     * triangle, then feed it to the renderer 
	     * NOTE: this sequence matches the nameList token sequence
	     */ 
	     valueListTriangle[0] = (GzPointer)vertexList; 
		 valueListTriangle[1] = (GzPointer)normalList; 
		 valueListTriangle[2] = (GzPointer)uvList; 
		 for (int i = 0; i < AAKERNEL_SIZE; i++)
		 {
			 GzPutTriangle(m_pRender[i], 3, nameListTriangle, valueListTriangle);
		 } 
	} 
	combine2One();
	GzFlushDisplay2File(outfile, m_finalDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_finalDisplay);	// write out or update display to frame buffer

	/* 
	 * Close file
	 */ 

	if( fclose( infile ) )
      AfxMessageBox( "The input file was not closed\n" );

	if( fclose( outfile ) )
      AfxMessageBox( "The output file was not closed\n" );
 
	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}
Example #4
0
int Application1::Render() 
{
	int		i, j; 
	int		xRes, yRes, dispClass;	/* display parameters */ 
	int		status; 
 	 
	status = 0; 
 
	/* 
	 * initialize the display and the renderer 
	 */ 

	m_nWidth = 512;		// frame buffer and display width
	m_nHeight = 512;    // frame buffer and display height

	status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);

	status |= GzNewDisplay(&m_pDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight); 
 
	status |= GzGetDisplayParams(m_pDisplay, &xRes, &yRes, &dispClass); 

	status |= GzInitDisplay(m_pDisplay);  /* init for new frame */
 
	if (status) exit(GZ_FAILURE); 
 
	// I/O File open

	FILE *infile;
	if( (infile = fopen( INFILE1 , "r" )) == NULL )
	{
         AfxMessageBox( "The input file was not opened\n" );
		 return GZ_FAILURE;
	}

	FILE *outfile;
	if( (outfile = fopen( OUTFILE1 , "wb" )) == NULL )
	{
         AfxMessageBox( "The output file was not opened\n" );
		 return GZ_FAILURE;
	}
	
	int	ulx, uly, lrx, lry, r, g, b;
	while( fscanf(infile, "%d %d %d %d %d %d %d", 
			&ulx, &uly, &lrx, &lry, &r, &g, &b) == 7) { 
		for (j = uly; j <= lry; j++) {
		  for (i = ulx; i <= lrx; i++) {
		    GzPutDisplay(m_pDisplay, i, j, r, g, b, 1, 0);
		  }
		}
	} 
	
	GzFlushDisplay2File(outfile, m_pDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pDisplay);	// write out or update display to frame buffer
 
	/* 
	 * Clean up and exit 
	 */ 

	if( fclose( infile ) )
      AfxMessageBox( "The input file was not closed\n" );

	if( fclose( outfile ) )
      AfxMessageBox( "The output file was not closed\n" );

	status |= GzFreeDisplay(m_pDisplay); 
 
	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 

}
int Application2::Render() 
{
	GzToken		nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer	valueListTriangle[3]; 		/* vertex attribute pointers */
	GzToken         nameListColor[3];       /* color type names */
	GzPointer       valueListColor[3];      /* color type rgb pointers */
	GzColor		color; 
	GzCoord		vertexList[3];	/* vertex position coordinates */ 
	GzCoord		normalList[3];	/* vertex normals */ 
	GzTextureIndex	uvList[3];		/* vertex texture map indices */ 
	char		dummy[256]; 
	int		i; 
	int		xRes, yRes, dispClass;	/* display parameters */ 
	int		status; 
 
	status = 0; 

	/* 
	 * initialize the display and the renderer 
	 */ 

	m_nWidth = 256;		// frame buffer and display width
	m_nHeight = 256;    // frame buffer and display height

	status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);
	status |= GzNewDisplay(&m_pDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight); 
 
	status |= GzGetDisplayParams(m_pDisplay, &xRes, &yRes, &dispClass); 
	 
	status |= GzInitDisplay(m_pDisplay); 
 
	status |= GzNewRender(&m_pRender, GZ_Z_BUFFER_RENDER, m_pDisplay); 

	status |= GzBeginRender(m_pRender); 

	if (status) exit(GZ_FAILURE); 

	/* 
	 * Tokens associated with triangle vertex values 
	 */ 
	nameListTriangle[0] = GZ_POSITION; /* define vert coordinates only */

	// I/O File open
	FILE *infile;
	if( (infile  = fopen( INFILE2 , "r" )) == NULL )
	{
         AfxMessageBox( "The input file was not opened\n" );
		 return GZ_FAILURE;
	}

	FILE *outfile;
	if( (outfile  = fopen( OUTFILE2 , "wb" )) == NULL )
	{
         AfxMessageBox( "The output file was not opened\n" );
		 return GZ_FAILURE;
	}

	/* 
	* Walk through the list of triangles, set color 
	* and pass vert info to render/scan convert each triangle 
	*/ 
	i = 0; 

	while( fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[0][0]), &(vertexList[0][1]),  
		&(vertexList[0][2]), 
		&(normalList[0][0]), &(normalList[0][1]), 	
		&(normalList[0][2]), 
		&(uvList[0][0]), &(uvList[0][1]) ); 
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[1][0]), &(vertexList[1][1]), 	
		&(vertexList[1][2]), 
		&(normalList[1][0]), &(normalList[1][1]), 	
		&(normalList[1][2]), 
		&(uvList[1][0]), &(uvList[1][1]) ); 
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[2][0]), &(vertexList[2][1]), 	
		&(vertexList[2][2]), 
		&(normalList[2][0]), &(normalList[2][1]), 	
		&(normalList[2][2]), 
		&(uvList[2][0]), &(uvList[2][1]) ); 

	    /* 
	    * Set up shading attributes for each triangle 
	    */ 
	    shade2(normalList[0], color);/* shade based on the norm of vert0 */
	    valueListColor[0] = (GzPointer)color; 
	    nameListColor[0] = GZ_RGB_COLOR; 
	    GzPutAttribute(m_pRender, 1, nameListColor, valueListColor); 
 
	    /* 
	     * Set the value pointers to the first vertex of the 	
	     * triangle, then feed it to the renderer 
	     */ 
	     valueListTriangle[0] = (GzPointer)vertexList; 


	     GzPutTriangle(m_pRender, 1, nameListTriangle, valueListTriangle);
	} 

	GzFlushDisplay2File(outfile, m_pDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pDisplay);	// write out or update display to frame buffer
 
	/* 
	 * Clean up and exit 
	 */ 

	if( fclose( infile ) )
      AfxMessageBox( "The input file was not closed\n" );

	if( fclose( outfile ) )
      AfxMessageBox( "The output file was not closed\n" );

	status |= GzFreeRender(m_pRender); 
	status |= GzFreeDisplay(m_pDisplay); 
 
	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
} 
int Application4::Render() 
{
	GzToken		nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer	valueListTriangle[3]; 	/* vertex attribute pointers */
	GzCoord		vertexList[3], tempVertexList[3];	/* vertex position coordinates */ 
	GzCoord		normalList[3], tempNormalList[3];	/* vertex normals */ 
	GzTextureIndex  	uvList[3], tempUVList[3];		/* vertex texture map indices */ 
	char		dummy[256]; 
	int			status; 
	int			index = 0, x = 0, y = 0, disp_i = 0;
	int		    xRes, yRes, dispClass;
	int i = 0, j = 0;

// ****************************************************************************************
//								START	HW6 CHANGE
// ****************************************************************************************
	/* Initialize Display */
	for(index = 0; index < AAKERNEL_SIZE; index++){
		status |= GzInitDisplay(m_pDisplay[index]); 
	}
// ****************************************************************************************
//								END		HW6 CHANGE
// ****************************************************************************************	
	/* 
	* Tokens associated with triangle vertex values 
	*/ 
	nameListTriangle[0] = GZ_POSITION; 
	nameListTriangle[1] = GZ_NORMAL; 
	nameListTriangle[2] = GZ_TEXTURE_INDEX;  

	// I/O File open
	FILE *infile;
	if( (infile  = fopen( INFILE , "r" )) == NULL )
	{
         AfxMessageBox( "The input file was not opened\n" );
		 return GZ_FAILURE;
	}

	FILE *outfile;
	if( (outfile  = fopen( OUTFILE , "wb" )) == NULL )
	{
         AfxMessageBox( "The output file was not opened\n" );
		 return GZ_FAILURE;
	}

	/* 
	* Walk through the list of triangles, set color 
	* and render each triangle 
	*/ 
	while( fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[0][0]), &(vertexList[0][1]),  
		&(vertexList[0][2]), 
		&(normalList[0][0]), &(normalList[0][1]), 	
		&(normalList[0][2]), 
		&(uvList[0][0]), &(uvList[0][1]) ); 
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[1][0]), &(vertexList[1][1]), 	
		&(vertexList[1][2]), 
		&(normalList[1][0]), &(normalList[1][1]), 	
		&(normalList[1][2]), 
		&(uvList[1][0]), &(uvList[1][1]) ); 
	    fscanf(infile, "%f %f %f %f %f %f %f %f", 
		&(vertexList[2][0]), &(vertexList[2][1]), 	
		&(vertexList[2][2]), 
		&(normalList[2][0]), &(normalList[2][1]), 	
		&(normalList[2][2]), 
		&(uvList[2][0]), &(uvList[2][1]) ); 

		for(i = 0; i < 3; i++)
			for(j = 0; j < 3; j++)
				tempVertexList[i][j] = vertexList[i][j];

		for(i = 0; i < 3; i++)
			for(j = 0; j < 3; j++)
				tempNormalList[i][j] = normalList[i][j];

		for(i = 0; i < 3; i++)
			for(j = 0; j < 2; j++)
				tempUVList[i][j] = uvList[i][j];


	    /* 
	     * Set the value pointers to the first vertex of the 	
	     * triangle, then feed it to the renderer 
	     * NOTE: this sequence matches the nameList token sequence
	     */ 
// ****************************************************************************************
//								START		HW6 CHANGE
// ****************************************************************************************
		for(index = 0; index < AAKERNEL_SIZE; index++)
		{				 
			for(i = 0; i < 3; i++)
				for(j = 0; j < 3; j++)
					vertexList[i][j] = tempVertexList[i][j];

			for(i = 0; i < 3; i++)
				for(j = 0; j < 3; j++)
					 normalList[i][j] = tempNormalList[i][j];

			for(i = 0; i < 3; i++)
				for(j = 0; j < 2; j++)
					 uvList[i][j] = tempUVList[i][j];

			valueListTriangle[0] = (GzPointer)vertexList; 
			valueListTriangle[1] = (GzPointer)normalList; 
			valueListTriangle[2] = (GzPointer)uvList; 

			GzPutTriangle(m_pRender[index], 3, nameListTriangle, valueListTriangle); 
		}
// ****************************************************************************************
//								END			HW6 CHANGE
// ****************************************************************************************
	} 

// ****************************************************************************************
//								START	HW6 CHANGE
// ****************************************************************************************
	
	// Create The final display for rendering it into the framebuffer
	status |= GzNewDisplay(&m_pFinalDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);
	status |= GzGetDisplayParams(m_pFinalDisplay, &xRes, &yRes, &dispClass);  
	status |= GzInitDisplay(m_pFinalDisplay); 
	
	GzColor finalColor;
	for(y = 0; y <= RESOLUTIONY; y++){
		for(x = 0; x <= RESOLUTIONX; x++){
			disp_i = (x+(y*256));
			finalColor[RED]=0;
			finalColor[GREEN]=0;
			finalColor[BLUE]=0;
			for(index = 0; index < AAKERNEL_SIZE; index++){
			 
				finalColor[RED] += ((float)m_pRender[index]->display->fbuf[disp_i].red * AAFilter[index][2]);
				finalColor[GREEN] += ((float)m_pRender[index]->display->fbuf[disp_i].green * AAFilter[index][2]);
				finalColor[BLUE] += ((float)m_pRender[index]->display->fbuf[disp_i].blue * AAFilter[index][2]);
			
			}
			m_pFinalDisplay->fbuf[disp_i].red = (short)finalColor[RED];
			m_pFinalDisplay->fbuf[disp_i].green = (short)finalColor[GREEN];
			m_pFinalDisplay->fbuf[disp_i].blue = (short)finalColor[BLUE];
		}
	}
/*	
	// update the renderers with the sample weights
	for(index = 0; index < 1; index++){
		for(y = 0; y <= RESOLUTIONY; y++){
			for(x = 0; x <= RESOLUTIONX; x++){
				disp_i = (x+(y*256));
				m_pRender[index]->display->fbuf[disp_i].red *= AAFilter[index][2];
				m_pRender[index]->display->fbuf[disp_i].green *= AAFilter[index][2];
				m_pRender[index]->display->fbuf[disp_i].blue *= AAFilter[index][2];
			}
		}
	}

	// Compute the final pixel colors to render in the framebuffer
	for(index = 0; index < 1; index++){
		for(y = 0; y <= RESOLUTIONY; y++){
			for(x = 0; x <= RESOLUTIONX; x++){
				disp_i = (x+(y*256));
				m_pFinalDisplay->fbuf[disp_i].red += m_pRender[index]->display->fbuf[disp_i].red;
				m_pFinalDisplay->fbuf[disp_i].green += m_pRender[index]->display->fbuf[disp_i].green;
				m_pFinalDisplay->fbuf[disp_i].blue += m_pRender[index]->display->fbuf[disp_i].blue;
			}
		}
	}
*/
// ****************************************************************************************
//								END		HW6 CHANGE
// ****************************************************************************************

	
	GzFlushDisplay2File(outfile, m_pFinalDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pFinalDisplay);	// write out or update display to frame buffer

	/* 
	 * Close file
	 */ 

	if( fclose( infile ) )
      AfxMessageBox( "The input file was not closed\n" );

	if( fclose( outfile ) )
      AfxMessageBox( "The output file was not closed\n" );
 
	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}
int Application5::Render() 
{
	GzToken		nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer	valueListTriangle[3]; 	/* vertex attribute pointers */
	GzCoord		vertexList[3];	/* vertex position coordinates */ 
	GzCoord		normalList[3];	/* vertex normals */ 
	GzTextureIndex  	uvList[3];		/* vertex texture map indices */ 
	char		dummy[256]; 
	int			status; 


	/* Initialize Display */
	/////for (int i = 0; i < AAKERNEL_SIZE; i++) 
	////status |= GzInitDisplay(m_pDisplay); 
	
	/////for (int i = 0; i < AAKERNEL_SIZE; i++) {

		

		/////GzNewDisplay(&AArender->display, GZ_RGBAZ_DISPLAY, m_pRender->display->xres, m_pRender->display->yres);
	/////}
	/* 
	* Tokens associated with triangle vertex values 
	*/ 
	nameListTriangle[0] = GZ_POSITION; 
	nameListTriangle[1] = GZ_NORMAL; 
	nameListTriangle[2] = GZ_TEXTURE_INDEX;  

	// I/O File open
	FILE *infile;
	if( (infile  = fopen( INFILE , "r" )) == NULL )
	{
         AfxMessageBox(_T( "The input file was not opened\n" ));
		 return GZ_FAILURE;
	}

	FILE *outfile;
	if( (outfile  = fopen( OUTFILE , "wb" )) == NULL )
	{
		AfxMessageBox(_T("The output file was not opened\n"));
		 return GZ_FAILURE;
	}

	/* 
	* Walk through the list of triangles, set color 
	* and render each triangle 
	*/ 
	////m_pAADisplays = (GzDisplay **)malloc(6 * sizeof(GzDisplay*));
	////m_pAADisplays = new GzDisplay*[6];
	////m_pAARenders = (GzRender **)malloc(6 * sizeof(GzRender*));
	////m_pAARenders = new GzRender*[6];
	for (int i = 0; i < AAKERNEL_SIZE; i++) {
		/////status |= GzNewRender(&m_pAARenders[i], m_pAADisplays[i]);
		m_pAARenders[i] = new GzRender();
		memcpy(m_pAARenders[i], m_pRender, sizeof(GzRender));
		status |= GzNewDisplay(&m_pAADisplays[i], m_nWidth, m_nHeight);
		status |= GzInitDisplay(m_pAADisplays[i]);
		m_pAARenders[i]->display = m_pAADisplays[i];
		m_pAARenders[i]->Xshift = AAFilter[i][0];
		m_pAARenders[i]->Yshift = AAFilter[i][1];
		m_pAARenders[i]->Weight = AAFilter[i][2];
	}

	while (fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
		fscanf(infile, "%f %f %f %f %f %f %f %f",
			&(vertexList[0][0]), &(vertexList[0][1]),
			&(vertexList[0][2]),
			&(normalList[0][0]), &(normalList[0][1]),
			&(normalList[0][2]),
			&(uvList[0][0]), &(uvList[0][1]));
		fscanf(infile, "%f %f %f %f %f %f %f %f",
			&(vertexList[1][0]), &(vertexList[1][1]),
			&(vertexList[1][2]),
			&(normalList[1][0]), &(normalList[1][1]),
			&(normalList[1][2]),
			&(uvList[1][0]), &(uvList[1][1]));
		fscanf(infile, "%f %f %f %f %f %f %f %f",
			&(vertexList[2][0]), &(vertexList[2][1]),
			&(vertexList[2][2]),
			&(normalList[2][0]), &(normalList[2][1]),
			&(normalList[2][2]),
			&(uvList[2][0]), &(uvList[2][1]));
		/*
		 * Set the value pointers to the first vertex of the
		 * triangle, then feed it to the renderer
		 * NOTE: this sequence matches the nameList token sequence
		 */
		valueListTriangle[0] = (GzPointer)vertexList;
		valueListTriangle[1] = (GzPointer)normalList;
		valueListTriangle[2] = (GzPointer)uvList;
		GzPutTriangle(m_pRender, 3, nameListTriangle, valueListTriangle);
		//#if ANTIALIASING
			for (int i = 0; i < AAKERNEL_SIZE; i++) 				
				GzPutTriangle(m_pAARenders[i], 3, nameListTriangle, valueListTriangle);
		//#endif	
	}

	GzInitDisplay(m_pRender->display);
	for (int y = 0; y < m_pRender->display->yres; y++) {
		for (int x = 0; x < m_pRender->display->xres; x++) {
			
			GzDisplay* display = m_pRender->display;
			int index = ARRAY(x, y);
			
			for (int i = 0; i < AAKERNEL_SIZE; i++) {
				m_pRender->display->fbuf[index].red += m_pAARenders[i]->display->fbuf[index].red	* m_pAARenders[i]->Weight;
				m_pRender->display->fbuf[index].green += m_pAARenders[i]->display->fbuf[index].green * m_pAARenders[i]->Weight;
				m_pRender->display->fbuf[index].blue += m_pAARenders[i]->display->fbuf[index].blue	* m_pAARenders[i]->Weight;
			}
		}
	}
	

	GzFlushDisplay2File(outfile, m_pDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pDisplay);	// write out or update display to frame buffer

	/* 
	 * Close file
	 */ 

	if( fclose( infile ) )
		AfxMessageBox(_T("The input file was not closed\n"));

	if( fclose( outfile ) )
		AfxMessageBox(_T("The output file was not closed\n"));
 
	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}
int Application6::Render()
{
	GzToken			nameListTriangle[3]; 	/* vertex attribute names */
	GzPointer		valueListTriangle[3]; 	/* vertex attribute pointers */
	GzCoord			vertexList[3];	/* vertex position coordinates */ 
	GzCoord			normalList[3];	/* vertex normals */ 
	GzTextureIndex  uvList[3];		/* vertex texture map indices */ 
	char			dummy[256]; 
	int				status; 


	/* Initialize Display */
	for (int i = 0; i < AAKERNEL_SIZE; i++)
	{
		status |= GzInitDisplay(m_pDisplay[i]);
	}
	
	/* 
	* Tokens associated with triangle vertex values 
	*/ 
	nameListTriangle[0] = GZ_POSITION; 
	nameListTriangle[1] = GZ_NORMAL; 
	nameListTriangle[2] = GZ_TEXTURE_INDEX;  

	// I/O File open
	FILE *infile;
	if( (infile  = fopen( INFILE , "r" )) == NULL )
	{
		 AfxMessageBox( "The input file was not opened\n" );
		 return GZ_FAILURE;
	}

	FILE *outfile;
	if( (outfile  = fopen( OUTFILE , "wb" )) == NULL )
	{
		 AfxMessageBox( "The output file was not opened\n" );
		 return GZ_FAILURE;
	}

	///* 
	//* Walk through the list of triangles, set color 
	//* and render each triangle 
	//*/ 
	//while( fscanf(infile, "%s", dummy) == 1) { 	/* read in tri word */
	//	fscanf(infile, "%f %f %f %f %f %f %f %f", 
	//	&(vertexList[0][0]), &(vertexList[0][1]),  
	//	&(vertexList[0][2]), 
	//	&(normalList[0][0]), &(normalList[0][1]), 	
	//	&(normalList[0][2]), 
	//	&(uvList[0][0]), &(uvList[0][1]) ); 
	//	fscanf(infile, "%f %f %f %f %f %f %f %f", 
	//	&(vertexList[1][0]), &(vertexList[1][1]), 	
	//	&(vertexList[1][2]), 
	//	&(normalList[1][0]), &(normalList[1][1]), 	
	//	&(normalList[1][2]), 
	//	&(uvList[1][0]), &(uvList[1][1]) ); 
	//	fscanf(infile, "%f %f %f %f %f %f %f %f", 
	//	&(vertexList[2][0]), &(vertexList[2][1]), 	
	//	&(vertexList[2][2]), 
	//	&(normalList[2][0]), &(normalList[2][1]), 	
	//	&(normalList[2][2]), 
	//	&(uvList[2][0]), &(uvList[2][1]) );

	/* Generate two quads:
		-One to the left of the z axis
		-One to the right of the z axis
		
	*/
	int numPolys = 5;
	float numPolysHalved = float(numPolys) / 2.0f;
	for (float i = -numPolysHalved; i < numPolysHalved; i++){
		for (int j = 0; j < numPolys; j++){
			//First triangle of the quad
			vertexList[0][0] = SIZE * i; vertexList[0][1] = 0; vertexList[0][2] = SIZE * j;
			vertexList[1][0] = SIZE * i; vertexList[1][1] = 0; vertexList[1][2] = SIZE * j + SIZE;
			vertexList[2][0] = SIZE * i + SIZE; vertexList[2][1] = 0; vertexList[2][2] = SIZE * j + SIZE;

			normalList[0][0] = 0; normalList[0][1] = 1; normalList[0][2] = 0;
			normalList[1][0] = 0; normalList[1][1] = 1; normalList[1][2] = 0;
			normalList[2][0] = 0; normalList[2][1] = 1; normalList[2][2] = 0;

			uvList[0][0] = 0; uvList[0][1] = 1;
			uvList[1][0] = 0; uvList[1][1] = 0;
			uvList[2][0] = 1; uvList[2][1] = 0;
			/*
				* Set the value pointers to the first vertex of the
				* triangle, then feed it to the renderer
				* NOTE: this sequence matches the nameList token sequence
				*/
			valueListTriangle[0] = (GzPointer)vertexList;
			valueListTriangle[1] = (GzPointer)normalList;
			valueListTriangle[2] = (GzPointer)uvList;
			for (int k = 0; k < AAKERNEL_SIZE; k++){
				GzPutTriangle(m_pRender[k], 3, nameListTriangle, valueListTriangle);
			}
			//Second triangle of the quad
			vertexList[0][0] = SIZE * i; vertexList[0][1] = 0; vertexList[0][2] = SIZE * j;
			vertexList[1][0] = SIZE * i + SIZE; vertexList[1][1] = 0; vertexList[1][2] = SIZE * j;
			vertexList[2][0] = SIZE * i + SIZE; vertexList[2][1] = 0; vertexList[2][2] = SIZE * j + SIZE;

			normalList[0][0] = 0; normalList[0][1] = 1; normalList[0][2] = 0;
			normalList[1][0] = 0; normalList[1][1] = 1; normalList[1][2] = 0;
			normalList[2][0] = 0; normalList[2][1] = 1; normalList[2][2] = 0;

			uvList[0][0] = 0; uvList[0][1] = 1;
			uvList[1][0] = 1; uvList[1][1] = 1;
			uvList[2][0] = 1; uvList[2][1] = 0;
			/*
			* Set the value pointers to the first vertex of the
			* triangle, then feed it to the renderer
			* NOTE: this sequence matches the nameList token sequence
			*/
			valueListTriangle[0] = (GzPointer)vertexList;
			valueListTriangle[1] = (GzPointer)normalList;
			valueListTriangle[2] = (GzPointer)uvList;
			for (int k = 0; k < AAKERNEL_SIZE; k++){
				GzPutTriangle(m_pRender[k], 3, nameListTriangle, valueListTriangle);
			}
		}
	}

	//Combine the displays
	for (int i = 0; i < AAKERNEL_SIZE; i++){
		if (!m_pDisplay[i]){
			return GZ_FAILURE;
		}
	}
	if (!m_pFinalDisplay){
		return GZ_FAILURE;
	}
	for (int i = 0; i < m_pFinalDisplay->xres; i++){
		for (int j = 0; j < m_pFinalDisplay->yres; j++){
			int index = (i + (j * m_pFinalDisplay->xres));
			m_pFinalDisplay->fbuf[index].red = 0;
			m_pFinalDisplay->fbuf[index].green = 0;
			m_pFinalDisplay->fbuf[index].blue = 0;
			m_pFinalDisplay->fbuf[index].alpha = 0;
			m_pFinalDisplay->fbuf[index].z = 0;
			for (int k = 0; k < AAKERNEL_SIZE; k++){
				m_pFinalDisplay->fbuf[index].red += m_pDisplay[k]->fbuf[index].red * AAFilter[k][WEIGHT];
				m_pFinalDisplay->fbuf[index].green += m_pDisplay[k]->fbuf[index].green * AAFilter[k][WEIGHT];
				m_pFinalDisplay->fbuf[index].blue += m_pDisplay[k]->fbuf[index].blue * AAFilter[k][WEIGHT];
				m_pFinalDisplay->fbuf[index].alpha += m_pDisplay[k]->fbuf[index].alpha * AAFilter[k][WEIGHT];
				m_pFinalDisplay->fbuf[index].z += m_pDisplay[k]->fbuf[index].z * AAFilter[k][WEIGHT];
			}
		}
	}

	GzFlushDisplay2File(outfile, m_pFinalDisplay); 	/* write out or update display to file*/
	GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pFinalDisplay);	// write out or update display to frame buffer

	/* 
	 * Close file
	 */ 

	if( fclose( infile ) )
	  AfxMessageBox( "The input file was not closed\n" );

	if( fclose( outfile ) )
	  AfxMessageBox( "The output file was not closed\n" );
 
	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}