public override void Render(World world, Faces faces, RenderSettings settings) { base.Render(world, faces, settings); Vector3D viewerOrigin = world.Camera.Translation; Vector3D viewerUp = world.Camera.UpAxis; Vector3D lightOrigin = world.Camera.Translation - world.Camera.RightAxis * world.Camera.ViewportWidth * 50; Vector3D lightUp = world.Camera.UpAxis; GL.glPolygonMode(GL.GL_FRONT_AND_BACK, (settings.Wireframe) ? GL.GL_LINE : GL.GL_FILL); GL.glDisable(GL.GL_BLEND); //GL.glBlendFunc( GL.BlendSrc.SrcAlpha, GL.BlendDest.OneMinusSrcAlpha ); GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glEnable(GL.GL_TEXTURE_2D); if (!settings.FaceColors) { GL.glColor(Color.White); } if (settings.ZBuffer) { GL.glEnable(GL.GL_DEPTH_TEST); } else { GL.glDisable(GL.GL_DEPTH_TEST); } Vector3D lightSource = world.Camera.Translation; Color clr = Color.White; //float r = 1, g = 1, b = 1; foreach (Face face in faces) { int faceVerticies = face.Points.Count; Vector3DCollection faceWorldCoords = face.Points; Vector3DCollection faceTextureCoords = face.TextureCoords; Vector3D normal = face.Normal; // blend in reflection component GL.glBindTexture(GL.Texture.Texture2D, (uint)_textureReflection.OpenGLHandle); GL.glBegin(GL.Primative.Polygon); if (settings.FaceColors) { clr = face.Color; } bool bVertexNormals = face.IsVertexNormals; for (int index = 0; index < faceVerticies; index++) { Vector3D worldCoord = faceWorldCoords[index]; if (bVertexNormals) { normal = face.VertexNormals[index]; } RenderUtils.glColor_GouraudIllumination(clr, worldCoord, normal, lightSource); RenderUtils.glTexture_AsinMapping(worldCoord, normal, viewerOrigin, viewerUp); RenderUtils.glVertex(worldCoord); } GL.glEnd(); /*GL.glBegin( GL.Primative.Lines ); * * if( bVertexNormals ) { * for( int index = 0; index < faceVerticies; index ++ ) { * Vector3D worldCoord = faceWorldCoords[ index ]; * normal = face.VertexNormals[ index ]; * * RenderUtils.glColor( normal.ToColor() ); * RenderUtils.glVertex( worldCoord ); * RenderUtils.glVertex( worldCoord + normal * 30 ); * } * } * else { * RenderUtils.glColor( Color.Yellow ); * RenderUtils.glVertex( face.MidPoint ); * RenderUtils.glVertex( face.MidPoint + normal * 30 ); * } * * GL.glEnd();*/ GL.glErrorCheck(); } }
public override void Render(World world, Faces faces, RenderSettings settings) { base.Render(world, faces, settings); Vector3D viewerOrigin = world.Camera.Translation; Vector3D viewerUp = world.Camera.UpAxis; Vector3D lightOrigin = world.Camera.Translation; // - world.Camera.RightAxis * world.Camera.ViewportWidth * 50; Vector3D lightUp = world.Camera.UpAxis; GL.glPolygonMode(GL.GL_FRONT_AND_BACK, (settings.Wireframe) ? GL.GL_LINE : GL.GL_FILL); GL.glDisable(GL.GL_TEXTURE_2D); Color clr = Color.White; foreach (Face face in faces) { int faceVerticies = face.Points.Count; Vector3DCollection worldCoords = face.Points; Vector3DCollection textureCoords = null; Vector3D normal = face.Normal; // draw base texture if (settings.ZBuffer) { GL.glEnable(GL.GL_DEPTH_TEST); } GL.glDisable(GL.GL_BLEND); GL.glEnable(GL.GL_COLOR_MATERIAL); if (settings.FaceColors) { clr = face.Color; } bool vertexNormals = face.IsVertexNormals; bool texture = settings.Textures && face.IsTexture; // draw base texture if (texture) { GL.glEnable(GL.GL_TEXTURE_2D); GL.glBindTexture(GL.Texture.Texture2D, (uint)face.Texture.OpenGLHandle); textureCoords = face.TextureCoords; } else { GL.glDisable(GL.GL_TEXTURE_2D); } GL.glBegin(GL.Primative.Polygon); for (int index = 0; index < faceVerticies; index++) { if (vertexNormals) { normal = face.VertexNormals[index]; } RenderUtils.glColor_GouraudIllumination(clr, worldCoords[index], normal, lightOrigin); if (texture) { RenderUtils.glTexture(textureCoords[index]); } RenderUtils.glVertex(worldCoords[index]); } GL.glEnd(); /*// blend in diffuse component * * GL.glEnable( GL.GL_BLEND ); * GL.glBlendFunc( GL.GL_ZERO, GL.GL_SRC_COLOR ); * GL.glColor( Color.White ); * GL.glEnable( GL.GL_TEXTURE_2D ); * GL.glBindTexture( GL.Texture.Texture2D, (uint) _diffuseMapHandle ); * GL.glBegin( GL.Primative.Polygon ); * * if( RenderUtils.IsFacing( face.MidPoint, face.Normal, lightOrigin ) ) { * for( int index = 0; index < faceVerticies; index ++ ) { * Vector3D worldCoord = faceWorldCoords[ index ]; * * if( vertexNormals ) { * normal = face.VertexNormals[ index ]; * } * * RenderUtils.glTexture_AsinMapping( worldCoord, normal, lightOrigin, lightUp ); * RenderUtils.glVertex( worldCoord ); * } * } * else { * for( int index = 0; index < faceVerticies; index ++ ) { * Vector3D worldCoord = faceWorldCoords[ index ]; * * if( vertexNormals ) { * normal = face.VertexNormals[ index ]; * } * * RenderUtils.glTexture( new Vector3D( 0, 0, 0 ) ); * RenderUtils.glVertex( worldCoord ); * } * } * GL.glEnd(); */ // determine if no light is hitting face if (RenderUtils.IsFacing(face.MidPoint, face.Normal, lightOrigin, viewerOrigin)) { // blend in specular component GL.glEnable(GL.GL_BLEND); GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); GL.glEnable(GL.GL_TEXTURE_2D); GL.glBindTexture(GL.Texture.Texture2D, (uint)_specularMapHandle); GL.glColor(Color.White); GL.glBegin(GL.Primative.Polygon); for (int index = 0; index < faceVerticies; index++) { Vector3D worldCoord = worldCoords[index]; if (vertexNormals) { normal = face.VertexNormals[index]; } RenderUtils.glTexture_PhongMapping(worldCoord, normal, lightOrigin, viewerOrigin, viewerUp); RenderUtils.glVertex(worldCoord); } GL.glEnd(); } } GL.glDisable(GL.GL_BLEND); }
public override void Render(World world, Faces faces, RenderSettings settings) { base.Render(world, faces, settings); //Faces visibleFaces = BSPTreeVizOperator.GetVisibleFaces( world.Camera.Translation, world.BSPTreeRoot ); //world.PolygonCount += faces.Count; GL.glPolygonMode(GL.GL_FRONT_AND_BACK, (settings.Wireframe) ? GL.GL_LINE : GL.GL_FILL); GL.glDisable(GL.GL_BLEND); GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glErrorCheck(); if (settings.Textures) { GL.glEnable(GL.GL_TEXTURE_2D); } else { GL.glDisable(GL.GL_TEXTURE_2D); } GL.glErrorCheck(); if (settings.ZBuffer) { GL.glEnable(GL.GL_DEPTH_TEST); } else { GL.glDisable(GL.GL_DEPTH_TEST); } GL.glErrorCheck(); Vector3D ptCamera = world.Camera.ForwardAxis; Vector3D lightSource = world.Light; Color clr = Color.White; //float r = 1, g = 1, b = 1; foreach (Face face in faces) { bool texture = (settings.Textures && face.IsTexture); if (texture) { if (face.IsTexture) { GL.glBindTexture(GL.Texture.Texture2D, face.Texture.OpenGLHandle); } } GL.glBegin(GL.Primative.Polygon); if (settings.FaceColors) { clr = face.Color; } RenderUtils.glColor_GouraudIllumination(clr, face.MidPoint, face.Normal, lightSource); //GL.glColor3f( r * lightIntensity, g * lightIntensity, b * lightIntensity ); int count = face.Points.Count; for (int i = 0; i < count; i++) { if (texture) { RenderUtils.glTexture(face.TextureCoords[i]); } RenderUtils.glVertex(face.Points[i]); } GL.glEnd(); } GL.glErrorCheck(); }