static int render_teapot_refraction(GzRender* in_renderer) { //setup shader and teapot material in_renderer->v_shader = GouraudVertexShader; in_renderer->p_shader = GouraudAlphaPixelShader; //use the same material for ambient, diffuse and specular GzColor material_color = {0.7f, 0.3f, 0.1f}; for(int i=0; i<3; i++) { in_renderer->Ka[i] = material_color[i]; in_renderer->Kd[i] = material_color[i]; in_renderer->Ks[i] = material_color[i]; } in_renderer->spec = 32; //setup transform GzMatrix m; GzScaleMat(teapot_scale, m); GzPushMatrix(in_renderer, m); GzCoord pos = {teapot_position[0], teapot_position[1]/1.33f, teapot_position[2]}; GzTrxMat(pos, m); GzPushMatrix(in_renderer, m); GzTrxMat(teapot_rotation, m); GzPushMatrix(in_renderer, m); GzPutCamera(renderer, &default_camera); GzBeginRender(in_renderer); GzToken nameListTriangle[4]; /* vertex attribute names */ GzPointer valueListTriangle[4]; /* vertex attribute pointers */ nameListTriangle[0] = GZ_POSITION; nameListTriangle[1] = GZ_NORMAL; nameListTriangle[2] = GZ_TEXTURE_INDEX; nameListTriangle[3] = GZ_RGB_COLOR; const Model::TriangleVector& triangles = teapot_model.GetData(); for(Model::TriangleVector::const_iterator it = triangles.begin(); it != triangles.end(); it++) { valueListTriangle[0] = (GzPointer)(*it)->vertices; valueListTriangle[1] = (GzPointer)(*it)->normals; valueListTriangle[2] = (GzPointer)(*it)->uvs; GzPutTriangle(in_renderer, 3, nameListTriangle, valueListTriangle); } return GZ_SUCCESS; }
static int render_water_plane(GzRender* in_renderer) { //setup shader and teapot material in_renderer->v_shader = PhongVertexShader; in_renderer->p_shader = PhongPixelShader; //use the same material for ambient, diffuse and specular GzColor material_color = {0.04f, 0.4f, 0.6f}; for(int i=0; i<3; i++) { in_renderer->Ka[i] = material_color[i]; in_renderer->Kd[i] = material_color[i]; in_renderer->Ks[i] = material_color[i]; } in_renderer->spec = 32; GzPutCamera(renderer, &default_camera); //setup transform GzCoord scale = {3.0f, 1.0f, 1.5f}; GzMatrix m; GzScaleMat(scale,m); GzPushMatrix(in_renderer, m); GzBeginRender(in_renderer); GzToken nameListTriangle[4]; /* vertex attribute names */ GzPointer valueListTriangle[4]; /* vertex attribute pointers */ nameListTriangle[0] = GZ_POSITION; nameListTriangle[1] = GZ_NORMAL; nameListTriangle[2] = GZ_TEXTURE_INDEX; nameListTriangle[3] = GZ_RGB_COLOR; const Model::TriangleVector& triangles = water_plane_model.GetData(); for(Model::TriangleVector::const_iterator it = triangles.begin(); it != triangles.end(); it++) { valueListTriangle[0] = (GzPointer)(*it)->vertices; valueListTriangle[1] = (GzPointer)(*it)->normals; valueListTriangle[2] = (GzPointer)(*it)->uvs; GzPutTriangle(in_renderer, 3, nameListTriangle, valueListTriangle); } return GZ_SUCCESS; }
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); }
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); }
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 Project::Render() { GzToken nameListTriangle[2]; /* vertex attribute names */ GzPointer valueListTriangle[2]; /* vertex attribute pointers */ GzCoord vertexList[3]; /* vertex position coordinates */ GzCoord normalList[3]; /* vertex normals */ int status; objParser.getNumOfVertices(); /* Initialize Display */ status |= GzInitDisplay(m_pDisplay); /* * Tokens associated with triangle vertex values */ nameListTriangle[0] = GZ_POSITION; nameListTriangle[1] = GZ_NORMAL; // I/O File open 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 */ for (int i = 0; i < objParser.getNumOfFaces(); ++i) { Face face = objParser.getFace(i + 1); vector<Face::FaceVertex> faceVertices = face.faceVertices; for (int j = 0; j < faceVertices.size(); ++j) { Face::FaceVertex faceVertex = faceVertices[j]; Vertex vertex = objParser.getVertex(faceVertex.v); VertexNormal vertexNormal = objParser.getVertexNormal(faceVertex.vn); vertexList[j][0] = vertex.x; vertexList[j][1] = vertex.y; vertexList[j][2] = vertex.z; normalList[j][0] = vertexNormal.x; normalList[j][1] = vertexNormal.y; normalList[j][2] = vertexNormal.z; } valueListTriangle[0] = (GzPointer)vertexList; valueListTriangle[1] = (GzPointer)normalList; GzPutTriangle(m_pRender, 2, 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 switch(currRenderFunc) { case 1: { CreateDepthMap(m_pDisplay, m_pDepthMap); BlurDepthMap(m_pDepthMap, m_pDepthMapBlurred); CopyToFrameBuffer(m_pFrameBuffer, m_pDepthMapBlurred); break; } case 2: { CreateDepthMap(m_pDisplay, m_pDepthMap); BlurDepthMap(m_pDepthMap, m_pDepthMapBlurred); GetEdgeMap(m_pDepthMapBlurred, m_pEdgeMap, m_pFF1_x, m_pFF1_y, m_pGradient); CopyToFrameBuffer(m_pFrameBuffer, m_pEdgeMap); break; } case 3: { ApplyGaussianBlur(m_pFrameBuffer, m_p3DImageBlurred, m_ifilterLength); CopyToFrameBuffer(m_pFrameBuffer, m_p3DImageBlurred); break; } case 4: { ApplyGaussianBlur(m_pFrameBuffer, m_p3DImageBlurred, m_ifilterLength); MultiplyImageWithTexture(m_p3DImageBlurred, m_pProceduralTexture, m_pTextureImageMult); CopyToFrameBuffer(m_pFrameBuffer, m_pTextureImageMult); break; } case 5: { ApplyGaussianBlur(m_pFrameBuffer, m_p3DImageBlurred, m_ifilterLength); MultiplyImageWithTexture(m_p3DImageBlurred, m_pImageTexture, m_pTextureImageMult); CopyToFrameBuffer(m_pFrameBuffer, m_pTextureImageMult); break; } case 6: { CreateDepthMap(m_pDisplay, m_pDepthMap); BlurDepthMap(m_pDepthMap, m_pDepthMapBlurred); GetEdgeMap(m_pDepthMapBlurred, m_pEdgeMap, m_pFF1_x, m_pFF1_y, m_pGradient); FindForceField(m_pFF1_x, m_pFF1_y, m_pGradient, m_pFF_x, m_pFF_y); unsigned char* output; GzNewFrameBuffer(&output, m_nWidth, m_nHeight); DrawLooseStrokes(m_pEdgeMap, m_pFF_x, m_pFF_y, output); CopyToFrameBuffer(m_pFrameBuffer, output); break; } case 7: { CreateDepthMap(m_pDisplay, m_pDepthMap); BlurDepthMap(m_pDepthMap, m_pDepthMapBlurred); GetEdgeMap(m_pDepthMapBlurred, m_pEdgeMap, m_pFF1_x, m_pFF1_y, m_pGradient); ApplyGaussianBlur(m_pFrameBuffer, m_p3DImageBlurred, m_ifilterLength); if (lastTexture == 1) CopyToFrameBuffer(m_pTexture, m_pImageTexture); else CopyToFrameBuffer(m_pTexture, m_pProceduralTexture); MultiplyImageWithTexture(m_p3DImageBlurred, m_pTexture, m_pTextureImageMult); FindForceField(m_pFF1_x, m_pFF1_y, m_pGradient, m_pFF_x, m_pFF_y); DrawLooseStrokes(m_pEdgeMap, m_pFF_x, m_pFF_y, m_pTextureImageMult); CopyToFrameBuffer(m_pFrameBuffer, m_pTextureImageMult); break; } default: break; } //CreateDepthMap(m_pDisplay, m_pDepthMap); //BlurDepthMap(m_pDepthMap, m_pDepthMapBlurred); //GetEdgeMap(m_pDepthMapBlurred, m_pEdgeMap, m_pFF1_x, m_pFF1_y, m_pGradient); //ApplyGaussianBlur(m_pFrameBuffer, m_p3DImageBlurred, 9); //MultiplyImageWithTexture(m_p3DImageBlurred, m_pPaperTexture, m_pTextureImageMult); // //FindForceField(m_pFF1_x, m_pFF1_y, m_pGradient, m_pFF_x, m_pFF_y); //unsigned char* output; //GzNewFrameBuffer(&output, m_nWidth, m_nHeight); ////DrawLine(line, 1, 230, 200, 210, 0, 0, 0); ////DrawForceField(m_pDepthMap, m_pFF_x, m_pFF_y); //DrawLooseStrokes(m_pEdgeMap, m_pFF_x, m_pFF_y, m_pTextureImageMult); //CopyToFrameBuffer(m_pFrameBuffer, m_pTextureImageMult); /* * Close file */ if( fclose( outfile ) ) AfxMessageBox( "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); }