Exemple #1
0
        public static void BillboardBegin(Texture tex, float x, float y, float z, float size)
        {
            GL.PushAttrib(AttribMask.ColorBufferBit | AttribMask.EnableBit | AttribMask.PolygonBit);

            int i, j;
            size *= 0.01f;

            GL.Enable(EnableCap.Texture2D);
            tex.Bind();

            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.Lighting);

            GL.PushMatrix();
            GL.Translate(x, y, z);

            GL.GetFloat(GetPName.ModelviewMatrix, Util.ModelMatrix);

            for (i = 0; i < 3; i++)
            {
                for (j = 0; j < 3; j++)
                {
                    if (i == j) Util.ModelMatrix[i * 4 + j] = 1;
                    else Util.ModelMatrix[i * 4 + j] = 0;
                }
            }
            GL.LoadMatrix(Util.ModelMatrix);
            GL.Scale(size, size, size);
        }
Exemple #2
0
        /// <summary>
        /// lataa skybox.
        /// </summary>
        /// <param name="skyName">skyboxin nimi, eli esim plainsky_  jos tiedostot on plainsky_front.jpg, plainsky_back.jpg jne</param>
        /// <param name="ext">tiedoston pääte, eli jpg, png, dds, ..</param>
        /// <param name="scale"></param>
        public void LoadSkybox(string skyName, string ext, float scale)
        {
            Texture.LoadTextures = false; // älä lataa objektin textureita automaattisesti
            sky = new ObjModel("skybox", "skybox.obj", scale, scale, scale); // lataa skybox
            Texture.LoadTextures = true; // seuraava saa ladatakin..
            sky.Boundings = null;

            string[] side = { "bottom", "left", "back", "right", "top", "front" };

            for (int q = 0; q < 6; q++)
            {
                sky.Meshes()[q].Boundings = null;

                string fileName = skyName + side[q] + "." + ext;
                Texture newSkyTex = new Texture();

                TextureLoaders.TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge;
                TextureLoaders.TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge;

                newSkyTex = Texture.Load(fileName);

                // etsi sivun materiaali
                Material matInf = sky.GetMaterial(sky.Meshes()[q].MaterialName);

                if (matInf != null)
                {
                    // korvaa vanhat texturet
                    matInf.DiffuseTex = newSkyTex;
                }
            }
            TextureLoaders.TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat;
            TextureLoaders.TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat;
        }
Exemple #3
0
        /// <summary>Load resources here.</summary>
        protected override void OnLoad(EventArgs e)
        {
            GL.ClearColor(System.Drawing.Color.Blue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.CullFace);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.Normalize);
            GL.Enable(EnableCap.ColorMaterial);

            Light.Enable();
            Light light=new Light("light");
            light.Position = new Vector3(20, 50, 0);
            light.Ambient = new Vector3(0.8f, 0.8f, 0.8f);
            Light.Add(light, 0);

            light = new Light("light2");
            light.Position = new Vector3(-40, 50, 50);
            light.Ambient = new Vector3(0.8f, 0.8f, 0.8f);
            Light.Add(light, 1);

            obj = new ObjModel("scene", "skene.obj", 20, 20, 20);
            skybox.LoadSkybox("sky/sky2_", "jpg", 100);
            tex = Texture.Load("1.png");

            cam.Position.Y = 10;

            Util.Set3DMode();
        }
Exemple #4
0
        public static Texture Load(string fileName, bool useTexDir)
        {
            Texture temptex;
            // jos texture on jo ladattu, ei ladata uudelleen
            textures.TryGetValue(fileName, out temptex);
            if (temptex != null)
            {
                temptex.textureCount++; // monta muuta käyttöä samalla texturella
                return temptex;
            }

            Texture t = new Texture();

            t.textureName = fileName;
            Log.WriteDebugLine("Texture: " + t.textureName);

            if (useTexDir) fileName = Settings.TextureDir + fileName;

            try
            {
                if (fileName.Contains(".dds")) // jos dds texture
                {
                    TextureLoaders.ImageDDS.LoadFromDisk(fileName, out t.textureID, out t.target);
                }
                else
                {
                    TextureLoaders.ImageGDI.LoadFromDisk(fileName, out t.textureID, out t.target);
                }
            }
            catch (Exception e)
            {
                Log.WriteDebugLine(e.ToString());
                throw new Exception(e.ToString());
            }

            float[] pwidth = new float[1];
            float[] pheight = new float[1];
            GL.BindTexture(t.target, t.textureID);
            GL.GetTexLevelParameter(t.target, 0, GetTextureParameter.TextureWidth, pwidth);
            GL.GetTexLevelParameter(t.target, 0, GetTextureParameter.TextureHeight, pheight);
            t.width = (int)pwidth[0];
            t.height = (int)pheight[0];

            textures.Add(t.textureName, t);

            return t;
        }
Exemple #5
0
        public override void Dispose()
        {
            Log.WriteDebugLine("Disposed: " + Name);

            if (texture != null) texture.Dispose();
            if (vbo != null) vbo.Dispose();

            texture = null;
            vbo = null;
        }
Exemple #6
0
        /// <summary>
        /// lataa kuva.
        /// </summary>
        /// <param name="fileName"></param>
        public void Load(string fileName)
        {
            texture = Texture.Load(fileName);

            int[] ind = new int[] { 0, 1, 3, 1, 2, 3 };

            int w = texture.Width / 2;
            int h = texture.Height / 2;

            Vector3[] vs = new Vector3[]
            {
                new Vector3(-w, -h,0),
                new Vector3(-w, h,0),
                new Vector3(w, h,0),
                new Vector3(w, -h,0)
            };

            Vector2[] uv = new Vector2[]
            {
                new Vector2(1,0),
                new Vector2(1,1),
                new Vector2(0,1),
                new Vector2(0,0)
            };

            Vector3[] norm = new Vector3[]
            {
                new Vector3(0, 0, 1),
                new Vector3(0, 0, 1),
                new Vector3(0, 0, 1),
                new Vector3(0, 0, 1)
            };

            vbo = new VBO();
            vbo.DataToVBO(vs, ind, norm, uv);

            // scale
            Front.X = 1;
            Front.Y = 1;
        }
Exemple #7
0
        /// <summary>
        /// lataa kupu.
        /// </summary>
        /// <param name="skyName">texturen nimi</param>
        /// <param name="scale"></param>
        public void LoadSkydome(string skyName, float scale)
        {
            Texture.LoadTextures = false; // älä lataa objektin textureita automaattisesti
            sky = new ObjModel("skydome", "skydome.obj", scale, scale, scale); // lataa kupu
            Texture.LoadTextures = true; // seuraava saa ladatakin..
            sky.Boundings = null;
            sky.Meshes()[0].Boundings = null;

            Texture newSkyTex = new Texture();
            newSkyTex = Texture.Load(skyName);

            // etsi materiaali
            Material matInf = sky.GetMaterial(sky.Meshes()[0].MaterialName);

            if (matInf != null)
            {
                // korvaa vanha texture
                matInf.DiffuseTex = newSkyTex;
            }
        }
Exemple #8
0
        public void Load(string fileName)
        {
            try
            {
                // lataa fonttitexture
                fontTex = Texture.Load(fileName);

                // lataa bitmap ja etsi kirjainten uv koordinaatit

                Bitmap CurrentBitmap = null;

                CurrentBitmap = new Bitmap(Settings.TextureDir + fileName);
                if (CurrentBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb || CurrentBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                {
                    BitmapData Data = CurrentBitmap.LockBits(new Rectangle(0, 0, CurrentBitmap.Width, CurrentBitmap.Height), ImageLockMode.ReadOnly, CurrentBitmap.PixelFormat);

                    SearchUV(ref Data, (CurrentBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb) ? 3 : 4);

                    CurrentBitmap.UnlockBits(Data);
                }
                else throw new Exception("Font: wrong pixel format.");
            }
            catch (Exception e)
            {
                throw new ArgumentException("Font: error loading file " + fileName + ".\n" + e);
            }
            CreateDL();
        }