Esempio n. 1
0
        protected void setMaterialState(SSMainShaderProgram mainShader)
        {
            GL.Enable(EnableCap.ColorMaterial); // turn off per-vertex color
            GL.Color4(this.MainColor);

            // setup the base color values...
            GL.Material(MaterialFace.Front, MaterialParameter.Ambient, AmbientMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, DiffuseMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Specular, SpecularMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Emission, EmissionMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Shininess, ShininessMatColor);

            if (textureMaterial != null)
            {
                if (mainShader != null)
                {
                    mainShader.SetupTextures(textureMaterial);
                }
                else
                {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.Enable(EnableCap.Texture2D);
                    if (textureMaterial.ambientTex != null || textureMaterial.diffuseTex != null)
                    {
                        // fall back onto the diffuse texture in the absence of ambient
                        SSTexture tex = textureMaterial.ambientTex ?? textureMaterial.diffuseTex;
                        GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
                    }
                    else
                    {
                        GL.BindTexture(TextureTarget.Texture2D, 0);
                    }
                }
            }
        }
Esempio n. 2
0
 public SSObjectGDISurface()
 {
     textureSurface              = new SSTexture();
     this.renderState.lighted    = false;
     this.renderState.depthTest  = false;
     this.renderState.depthWrite = false;
 }
Esempio n. 3
0
        public static SSTextureMaterial FromBlenderMtl(string basePath, SSWavefrontMTLInfo mtl)
        {
            SSTexture diffuse = null, specular = null, ambient = null, bumpMap = null;

            if (mtl.diffuseTextureResourceName != null && mtl.diffuseTextureResourceName.Length > 0)
            {
                string path = Path.Combine(basePath, mtl.diffuseTextureResourceName);
                diffuse = SSAssetManager.GetInstance <SSTextureWithAlpha> (path);
            }
            if (mtl.specularTextureResourceName != null && mtl.specularTextureResourceName.Length > 0)
            {
                string path = Path.Combine(basePath, mtl.specularTextureResourceName);
                specular = SSAssetManager.GetInstance <SSTextureWithAlpha> (path);
            }
            if (mtl.ambientTextureResourceName != null && mtl.ambientTextureResourceName.Length > 0)
            {
                string path = Path.Combine(basePath, mtl.ambientTextureResourceName);
                ambient = SSAssetManager.GetInstance <SSTextureWithAlpha> (path);
            }
            if (mtl.bumpTextureResourceName != null && mtl.bumpTextureResourceName.Length > 0)
            {
                string path = Path.Combine(basePath, mtl.bumpTextureResourceName);
                bumpMap = SSAssetManager.GetInstance <SSTextureWithAlpha> (path);
            }

            return(new SSTextureMaterial(diffuse, specular, ambient, bumpMap));
        }
Esempio n. 4
0
        public virtual void renderMesh(SSRenderConfig renderConfig)
        {
            if (!renderConfig.drawingShadowMap && textureMaterial != null)
            {
                if (renderConfig.ActiveDrawShader != null)
                {
                    renderConfig.ActiveDrawShader.SetupTextures(textureMaterial);
                }
                else
                {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.Enable(EnableCap.Texture2D);
                    if (textureMaterial.ambientTex != null || textureMaterial.diffuseTex != null)
                    {
                        // fall back onto the diffuse texture in the absence of ambient
                        SSTexture tex = textureMaterial.ambientTex ?? textureMaterial.diffuseTex;
                        GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
                    }
                    else
                    {
                        GL.BindTexture(TextureTarget.Texture2D, 0);
                    }
                }
            }

            if (alphaBlendingEnabled)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            }
        }
Esempio n. 5
0
        public SSMesh_SphereICO(int divisions, SSMainShaderProgram shaderPgm, SSTexture texture)
        {
            this.shaderPgm = shaderPgm;
            this.texture   = texture;

            this._Create(divisions);
        }
Esempio n. 6
0
        protected void setMaterialState()
        {
            GL.Enable(EnableCap.ColorMaterial); // turn off per-vertex color
            GL.Color4(this.MainColor);

            // setup the base color values...
            var colorMat = this.colorMaterial ?? _defaultColorMat;

            SSColorMaterial.applyColorMaterial(colorMat);

            if (textureMaterial != null)
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.Enable(EnableCap.Texture2D);
                if (textureMaterial.ambientTex != null || textureMaterial.diffuseTex != null)
                {
                    // fall back onto the diffuse texture in the absence of ambient
                    SSTexture tex = textureMaterial.diffuseTex ?? textureMaterial.ambientTex;
                    GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, 0);
                }
            }
        }
Esempio n. 7
0
        public void UpdateTexture()
        {
            if (!Dirty)
            {
                return;
            }
            Dirty = false;

            // using this method to software GDI+ render to a bitmap, and then copy to texture
            // http://florianblock.blogspot.com/2008/06/copying-dynamically-created-bitmap-to.html

            Bitmap bitmap = this.RepaintGDI(out gdiSize);

            if (bitmap != null)
            {
                textureSize = bitmap.Size;

                // download bits into a texture...
                textureSurface.loadFromBitmap(bitmap, hasAlpha: base.alphaBlendingEnabled, mipmap: false);
            }
            else
            {
                if (textureSurface != null)
                {
                    textureSurface.DeleteTexture();
                    textureSurface = null;
                }
            }
        }
Esempio n. 8
0
 public SSObjectGDISurface()
 {
     textureSurface = new SSTexture();
     this.renderState.lighted = false;
     this.renderState.depthTest = false;
     this.renderState.depthWrite = false;
 }
Esempio n. 9
0
        public SSTextureMaterial(SSTexture diffuse = null, SSTexture specular = null, 
							      SSTexture ambient = null, SSTexture bumpMap = null)
        {
            diffuseTex = diffuse;
            specularTex = specular;
            ambientTex = ambient;
            bumpMapTex = bumpMap;
        }
Esempio n. 10
0
 public SSTextureMaterial(SSTexture diffuse = null, SSTexture specular = null,
                          SSTexture ambient = null, SSTexture bumpMap  = null)
 {
     diffuseTex  = diffuse;
     specularTex = specular;
     ambientTex  = ambient;
     bumpMapTex  = bumpMap;
 }
Esempio n. 11
0
 public SSObject2DSurface_AGG()
 {
     textureSurface = new SSTexture();
     this.renderState.alphaBlendingOn = true;
     this.renderState.alphaTest = true;
     this.renderState.lighted = false;
     this.renderState.depthTest = false;
     this.renderState.depthWrite = false;
 }
Esempio n. 12
0
 public SSObject2DSurface_AGG()
 {
     textureSurface = new SSTexture();
     this.renderState.alphaBlendingOn = true;
     this.renderState.alphaTest       = true;
     this.renderState.lighted         = false;
     this.renderState.depthTest       = false;
     this.renderState.depthWrite      = false;
     this.renderState.frustumCulling  = false;
 }
 /// <summary>
 /// Binds our texture-images to GL texture-units
 /// http://adriangame.blogspot.com/2010/05/glsl-multitexture-checklist.html
 /// these texture-unit assignments are hard-coded in the shader setup
 /// Disables textures that were passed as null (defaults)
 /// </summary>
 public void SetupTextures(
     SSTexture diffuseTex = null, SSTexture specTex    = null,
     SSTexture ambientTex = null, SSTexture bumpMapTex = null)
 {
     // these texture-unit assignments are hard-coded in the shader setup
     GL.ActiveTexture(TextureUnit.Texture0);
     if (diffuseTex != null)
     {
         GL.BindTexture(TextureTarget.Texture2D, diffuseTex.TextureID);
         uniDiffTexEnabled = true;
     }
     else
     {
         GL.BindTexture(TextureTarget.Texture2D, 0);
         uniDiffTexEnabled = false;
     }
     GL.ActiveTexture(TextureUnit.Texture1);
     if (specTex != null)
     {
         GL.BindTexture(TextureTarget.Texture2D, specTex.TextureID);
         uniSpecTexEnabled = true;
     }
     else
     {
         GL.BindTexture(TextureTarget.Texture2D, 0);
         uniSpecTexEnabled = false;
     }
     GL.ActiveTexture(TextureUnit.Texture2);
     if (ambientTex != null || diffuseTex != null)
     {
         // fall back onto the diffuse texture in the absence of ambient
         SSTexture tex = ambientTex != null ? ambientTex : diffuseTex;
         GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
         uniAmbTexEnabled = true;
     }
     else
     {
         GL.BindTexture(TextureTarget.Texture2D, 0);
         uniAmbTexEnabled = false;
     }
     GL.ActiveTexture(TextureUnit.Texture3);
     if (bumpMapTex != null)
     {
         GL.BindTexture(TextureTarget.Texture2D, bumpMapTex.TextureID);
         uniBumpTexEnabled = true;
     }
     else
     {
         GL.BindTexture(TextureTarget.Texture2D, 0);
         uniBumpTexEnabled = false;
     }
 }
Esempio n. 14
0
        public static SSTextureMaterial FromBlenderMtl(SSAssetManager.Context ctx, SSWavefrontMTLInfo mtl)
        {
            SSTexture diffuse = null, specular = null, ambient = null, bumpMap = null;

            if (mtl.diffuseTextureResourceName != null && mtl.diffuseTextureResourceName.Length > 0)
            {
                diffuse = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.diffuseTextureResourceName);
            }
            if (mtl.specularTextureResourceName != null && mtl.specularTextureResourceName.Length > 0)
            {
                specular = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.specularTextureResourceName);
            }
            if (mtl.ambientTextureResourceName != null && mtl.ambientTextureResourceName.Length > 0)
            {
                ambient = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.ambientTextureResourceName);
            }
            if (mtl.bumpTextureResourceName != null && mtl.bumpTextureResourceName.Length > 0)
            {
                bumpMap = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.bumpTextureResourceName);
            }

            return(new SSTextureMaterial(diffuse, specular, ambient, bumpMap));
        }
Esempio n. 15
0
 public SSObject2DSurface_AGG()
 {
     textureSurface = new SSTexture();
 }
Esempio n. 16
0
 public SSObjectGDISurface()
 {
     textureSurface = new SSTexture();
 }
Esempio n. 17
0
        /// <summary>
        /// Binds our texture-images to GL texture-units 
        /// http://adriangame.blogspot.com/2010/05/glsl-multitexture-checklist.html
        /// these texture-unit assignments are hard-coded in the shader setup
        /// Disables textures that were passed as null (defaults)
        /// </summary>
        public void SetupTextures(
			SSTexture diffuseTex = null, SSTexture specTex = null, 
			SSTexture ambientTex = null, SSTexture bumpMapTex = null)
        {
            // these texture-unit assignments are hard-coded in the shader setup
            GL.ActiveTexture(TextureUnit.Texture0);
            if (diffuseTex != null) {
                GL.BindTexture(TextureTarget.Texture2D, diffuseTex.TextureID);
                uniDiffTexEnabled = true;
            } else {
                GL.BindTexture(TextureTarget.Texture2D, 0);
                uniDiffTexEnabled = false;
            }
            GL.ActiveTexture(TextureUnit.Texture1);
            if (specTex != null) {
                GL.BindTexture(TextureTarget.Texture2D, specTex.TextureID);
                uniSpecTexEnabled = true;
            } else {
                GL.BindTexture(TextureTarget.Texture2D, 0);
                uniSpecTexEnabled = false;
            }
            GL.ActiveTexture(TextureUnit.Texture2);
            if (ambientTex != null || diffuseTex != null) {
                // fall back onto the diffuse texture in the absence of ambient
                SSTexture tex = ambientTex != null ? ambientTex : diffuseTex;
                GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
                uniAmbTexEnabled = true;
            } else {
                GL.BindTexture(TextureTarget.Texture2D, 0);
                uniAmbTexEnabled = false;
            }
            GL.ActiveTexture(TextureUnit.Texture3);
            if (bumpMapTex != null) {
                GL.BindTexture(TextureTarget.Texture2D, bumpMapTex.TextureID);
                uniBumpTexEnabled = true;
            } else {
                GL.BindTexture(TextureTarget.Texture2D, 0);
                uniBumpTexEnabled = false;
            }
        }
 public SSMesh_SphereICO(int divisions, SSTexture texture)
     : base(BufferUsageHint.StaticDraw, BufferUsageHint.StaticDraw)
 {
     this.textureMaterial = new SSTextureMaterial(texture);
     this._Create(divisions);
 }
Esempio n. 19
0
        public static SSTextureMaterial FromMaterialString(string basePath, string materialString)
        {
            string existingPath = null;

            string combined = Path.Combine(basePath, materialString);

            if (SSAssetManager.ResourceExists(combined))
            {
                existingPath = combined;
            }
            else if (SSAssetManager.ResourceExists(materialString))
            {
                existingPath = materialString;
            }
            else
            {
                string[] basePaths  = { "", basePath }; // search in root as well as supplied base path
                var      extensions = new List <string> (SSTexture.commonImageExtensions);
                extensions.Insert(0, ".mtl");           // check mtl first

                foreach (var bp in basePaths)
                {
                    // for each context (current vs root directory)...
                    foreach (string extension in extensions)
                    {
                        // for each extension of interest...
                        string fullPath = Path.Combine(bp, materialString + extension);
                        if (SSAssetManager.ResourceExists(fullPath))
                        {
                            existingPath = fullPath;
                            break;
                        }
                    }
                }
            }

            if (existingPath != null)
            {
                // try loading a material
                try {
                    SSWavefrontMTLInfo[] mtls = SSWavefrontMTLInfo.ReadMTLs(existingPath);
                    if (mtls.Length <= 0)
                    {
                        throw new Exception("No MTLs available in a file");
                    }
                    string baseDir = Path.GetDirectoryName(existingPath);
                    return(SSTextureMaterial.FromBlenderMtl(baseDir, mtls[0]));
                } catch {
                    // try loading an image
                    try {
                        SSTexture diffTex = SSAssetManager.GetInstance <SSTextureWithAlpha> (existingPath);
                        return(new SSTextureMaterial(diffTex));
                    } catch {
                    }
                }
            }

            string errMsg = "could not load texture material: " + materialString;

            System.Console.WriteLine(errMsg);
            throw new Exception(errMsg);
        }
Esempio n. 20
0
 public SSObject2DSurface_AGG()
 {
     textureSurface = new SSTexture();
 }
Esempio n. 21
0
 public SSObjectGDISurface()
 {
     textureSurface = new SSTexture();
 }
Esempio n. 22
0
        public static SSTextureMaterial FromMaterialString(SSAssetManager.Context ctx, string materialString)
        {
            string existingFilename = null;

            SSAssetManager.Context existingCtx = null;

            if (ctx != null && SSAssetManager.ResourceExists(ctx, materialString))
            {
                existingCtx      = ctx;
                existingFilename = materialString;
            }
            else if (SSAssetManager.ResourceExists(SSAssetManager.Context.Root, materialString))
            {
                existingCtx      = SSAssetManager.Context.Root;
                existingFilename = materialString;
            }
            else
            {
                SSAssetManager.Context[] ctxs = { ctx, SSAssetManager.Context.Root };
                var extensions = new List <string> (SSTexture.commonImageExtensions);
                extensions.Insert(0, ".mtl");                  // check mtl first

                foreach (var context in ctxs)
                {
                    // for each context (current vs root directory)...
                    foreach (string extension in extensions)
                    {
                        // for each extension of interest...
                        string filename = materialString + extension;
                        if (SSAssetManager.ResourceExists(context, filename))
                        {
                            existingCtx      = context;
                            existingFilename = filename;
                            break;
                        }
                    }
                }
            }

            if (existingFilename != null)
            {
                // try loading a material
                try {
                    SSWavefrontMTLInfo[] mtls = SSWavefrontMTLInfo.ReadMTLs(existingCtx, existingFilename);
                    if (mtls.Length < 0)
                    {
                        throw new Exception("No MTLs available in a file");
                    }
                    return(SSTextureMaterial.FromBlenderMtl(existingCtx, mtls[0]));
                } catch {
                    // try loading an image
                    try {
                        SSTexture diffTex = SSAssetManager.GetInstance <SSTextureWithAlpha> (existingCtx, existingFilename);
                        return(new SSTextureMaterial(diffTex));
                    } catch {
                    }
                }
            }

            string errMsg = "could not load texture material: " + materialString;

            System.Console.WriteLine(errMsg);
            throw new Exception(errMsg);
        }