Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        public override void Render(World world, Faces faces, RenderSettings settings)
        {
            base.Render(world, faces, settings);

            GL.glDisable(GL.GL_BLEND);
            GL.glEnable(GL.GL_COLOR_MATERIAL);
            if (settings.Textures)
            {
                GL.glEnable(GL.GL_TEXTURE_2D);
            }
            else
            {
                GL.glDisable(GL.GL_TEXTURE_2D);
            }
            if (settings.ZBuffer)
            {
                GL.glEnable(GL.GL_DEPTH_TEST);
            }
            else
            {
                GL.glDisable(GL.GL_DEPTH_TEST);
            }

            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, (settings.Wireframe) ? GL.GL_LINE : GL.GL_FILL);
            GL.glColor(Color.White);

            foreach (Face face in faces)
            {
                int vertexCount = face.Points.Count;
                Vector3DCollection worldCoords   = face.Points;
                Vector3DCollection textureCoords = null;

                bool texture = (settings.Textures && face.IsTexture);
                if (settings.Textures)
                {
                    if (texture)
                    {
                        GL.glEnable(GL.GL_TEXTURE_2D);
                        GL.glBindTexture(GL.Texture.Texture2D, face.Texture.OpenGLHandle);
                        textureCoords = face.TextureCoords;
                    }
                    else
                    {
                        GL.glDisable(GL.GL_TEXTURE_2D);
                    }
                }

                if (settings.FaceColors)
                {
                    GL.glColor(face.Color);
                }

                GL.glBegin(GL.Primative.Polygon);

                for (int index = 0; index < vertexCount; index++)
                {
                    if (texture)
                    {
                        RenderUtils.glTexture(textureCoords[index]);
                    }
                    RenderUtils.glVertex(worldCoords[index]);
                }

                GL.glEnd();
            }
        }
Ejemplo n.º 4
0
        public override void Render(World world, Faces faces, RenderSettings settings)
        {
            base.Render(world, faces, settings);

            GL.glDisable(GL.GL_BLEND);
            GL.glEnable(GL.GL_COLOR_MATERIAL);
            if (settings.Textures)
            {
                GL.glEnable(GL.GL_TEXTURE_2D);
            }
            else
            {
                GL.glDisable(GL.GL_TEXTURE_2D);
            }

            if (settings.ZBuffer)
            {
                GL.glEnable(GL.GL_DEPTH_TEST);
            }
            else
            {
                GL.glDisable(GL.GL_DEPTH_TEST);
            }

            GL.glPolygonMode(GL.GL_FRONT_AND_BACK, (settings.Wireframe) ? GL.GL_LINE : GL.GL_FILL);

            Color    clr   = Color.White;
            Vector3D light = world.Light;

            foreach (Face face in faces)
            {
                int vertexCount = face.Points.Count;
                Vector3DCollection worldCoords   = face.Points;
                Vector3DCollection textureCoords = null;
                Vector3D           normal        = face.Normal;

                if (settings.FaceColors)
                {
                    clr = face.Color;
                }

                bool texture = (settings.Textures && face.IsTexture);
                if (settings.Textures)
                {
                    if (texture)
                    {
                        GL.glEnable(GL.GL_TEXTURE_2D);
                        GL.glBindTexture(GL.Texture.Texture2D, face.Texture.OpenGLHandle);
                        textureCoords = face.TextureCoords;
                    }
                    else
                    {
                        GL.glDisable(GL.GL_TEXTURE_2D);
                    }
                }

                GL.glBegin(GL.Primative.Polygon);

                bool vertexNormals = face.IsVertexNormals;

                for (int index = 0; index < vertexCount; index++)
                {
                    Vector3D worldCoord = worldCoords[index];
                    if (vertexNormals)
                    {
                        normal = face.VertexNormals[index];
                    }

                    RenderUtils.glColor_PhongIllumination(clr, worldCoord, normal, light, Color.White, light, 30);
                    if (texture)
                    {
                        RenderUtils.glTexture(textureCoords[index]);
                    }
                    RenderUtils.glVertex(worldCoord);
                }

                GL.glEnd();
            }
        }