Ejemplo n.º 1
0
 private void UnloadImageAsset(ImageAssetData asset)
 {
     if (asset.IsLoaded)
     {
         GL.DeleteTexture(asset.OpenGLHandle);
     }
 }
Ejemplo n.º 2
0
        private void LoadImageAsset(ImageAssetData asset)
        {
            if (asset.IsLoaded)
            {
                return;
            }

            int textureHandle = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, textureHandle);

            var width  = 0;
            var height = 0;

            byte[] imageData    = null;
            var    currentIndex = 0;

            using (var stream = Utils.OpenEmbeddedResource(asset.AssetName)){
                using (var img = SixLabors.ImageSharp.Image.Load(stream)) {
                    imageData = new byte[img.Width * img.Height * 4];
                    width     = img.Width;
                    height    = img.Height;
                    for (int y = 0; y < img.Height; y++)
                    {
                        for (int x = 0; x < img.Width; x++)
                        {
                            var pixelValue = img[x, y];
                            imageData[currentIndex++] = pixelValue.B;
                            imageData[currentIndex++] = pixelValue.G;
                            imageData[currentIndex++] = pixelValue.R;
                            imageData[currentIndex++] = pixelValue.A;
                        }
                    }
                }
            }

            GL.TexImage2D(
                TextureTarget.Texture2D,
                0,
                PixelInternalFormat.Rgba,
                width,
                height,
                0,
                PixelFormat.Bgra,
                PixelType.UnsignedByte,
                imageData);

            GL.TexParameter(
                TextureTarget.Texture2D,
                TextureParameterName.TextureMinFilter,
                (int)TextureMinFilter.Nearest);
            GL.TexParameter(
                TextureTarget.Texture2D,
                TextureParameterName.TextureMagFilter,
                (int)TextureMinFilter.Nearest);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            asset.OpenGLHandle = textureHandle;
            asset.IsLoaded     = true;
        }
Ejemplo n.º 3
0
        private void RenderWithBlinn(
            MeshAssetData mesh,
            ImageAssetData colorTexture,
            ImageAssetData normalTexture,
            Matrix4 modelMatrix)
        {
            var modelViewProjection =
                modelMatrix *
                this.gameData.CameraData.Transformation *
                this.gameData.CameraData.PerspectiveProjection;

            var shader = this.gameData.BlinnShader;

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, colorTexture.OpenGLHandle);
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, normalTexture.OpenGLHandle);

            GL.BindVertexArray(mesh.VertexArrayObjectHandle);

            GL.UseProgram(shader.BasicShader.ProgramHandle);
            GL.UniformMatrix4(
                shader.BasicShader.ModelviewProjectionMatrixLocation,
                false,
                ref modelViewProjection);

            GL.UniformMatrix4(shader.ModelMatrixLocation, false, ref modelMatrix);
            GL.Uniform1(shader.ColorTextureLocation, 0);
            GL.Uniform1(shader.NormalTextureLocation, 1);
            GL.Uniform1(shader.MaterialShininessLocation, 2.0f);
            GL.Uniform3(shader.LightDirectionLocation, this.gameData.AmbientLightDirection);

            GL.Uniform4(shader.LightAmbientColorLocation, new Vector4(0.6f, 0.6f, 0.6f, 0));
            GL.Uniform4(shader.LightDiffuseColorLocation, new Vector4(0.8f, 0.8f, 0.8f, 0));
            GL.Uniform4(shader.LightSpecularColorLocation, new Vector4(0.0f, 0.0f, 0.0f, 0));
            GL.Uniform4(shader.CameraPositionLocation, new Vector4(this.gameData.CameraData.Eye, 1));

            GL.DrawElements(
                PrimitiveType.Triangles,
                mesh.IndicesCount,
                DrawElementsType.UnsignedInt,
                IntPtr.Zero);

            GL.BindVertexArray(0);
            GL.ActiveTexture(TextureUnit.Texture0);
        }
Ejemplo n.º 4
0
        private ImageAssetData GetSatteliteTexture(SatelliteSimData satellite)
        {
            ImageAssetData texture = null;

            switch (this.gameData.ColorCodeMode)
            {
            case ColorCodeMode.NONE:
                texture = this.gameData.SatelliteTextureDefault;
                break;

            case ColorCodeMode.USERS:
                switch (satellite.Users)
                {
                case SatelliteUsers.CIVIL:
                    texture = this.gameData.SatelliteTextures[1];
                    break;

                case SatelliteUsers.MILITARY:
                    texture = this.gameData.SatelliteTextures[2];
                    break;

                case SatelliteUsers.COMMERCIAL:
                    texture = this.gameData.SatelliteTextures[3];
                    break;

                case SatelliteUsers.GOVERNMENT:
                    texture = this.gameData.SatelliteTextures[4];
                    break;

                case SatelliteUsers.MIXED:
                    texture = this.gameData.SatelliteTextures[5];
                    break;
                }

                break;

            case ColorCodeMode.ORBITTYPE:

                switch (satellite.ClassOfOrbit)
                {
                case OrbitType.LEO:
                    texture = this.gameData.SatelliteTextures[1];
                    break;

                case OrbitType.MEO:
                    texture = this.gameData.SatelliteTextures[2];
                    break;

                case OrbitType.GEO:
                    texture = this.gameData.SatelliteTextures[3];
                    break;

                case OrbitType.ELLIPTICAL:
                    texture = this.gameData.SatelliteTextures[4];
                    break;
                }
                break;
            }

            if (satellite.IsSelected)
            {
                texture = this.gameData.SatelliteTextureSelected;
            }

            return(texture);
        }