Beispiel #1
0
        protected override void RenderModel()
        {
            if (VBO.FastRenderPass)
            {
                return;
            }
            GameClass.NumOfObjects++;

            GL.Disable(EnableCap.DepthTest);
            GL.DepthMask(false); // ei kirjoiteta z-bufferiin
            GLExt.SetLighting(false);

            GLExt.PushMatrix();
            GLExt.ModelViewMatrix.Row3.X = GLExt.ModelViewMatrix.Row3.Y = GLExt.ModelViewMatrix.Row3.Z = 0;
            GLExt.Scale(10, 10, 10);
            for (int q = 0; q < 6; q++)
            {
                OgreMesh m = skyboxSides[q];
                m.Material.SetMaterial();
                m.Vbo.Render();
            }
            GLExt.PopMatrix();

            GLExt.SetLighting(true);
            GL.DepthMask(true);
            GL.Enable(EnableCap.DepthTest);
        }
Beispiel #2
0
        /// <summary>
        /// renderoi yhden billboardin.
        /// </summary>
        public void RenderBillboard(float x, float y, float z, float zrot, float size, bool blend)
        {
            billBoard.Bind(0);
            GL.Disable(EnableCap.CullFace);

            if (blend)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            }

            GLExt.PushMatrix();
            {
                GLExt.Translate(x, y, z);
                size *= 0.1f;
                GLExt.Scale(size, size, size);
                GLExt.RotateZ(zrot);
                Matrix4 matrix = Matrix4.Identity;
                matrix.Row3           = GLExt.ModelViewMatrix.Row3;
                GLExt.ModelViewMatrix = matrix;

                GLExt.SetLighting(false);
                billBoard.Vbo.Render();
                GLExt.SetLighting(true);
            }
            GLExt.PopMatrix();

            if (blend)
            {
                GL.Disable(EnableCap.Blend);
            }
        }
Beispiel #3
0
        /// <summary>
        /// laskee joka objektin paikan ja ottaa sen talteen joko Matrix tai WMatrix taulukkoon
        /// </summary>
        /// <param name="getWMatrix"></param>
        public void CalcPositions(bool getWMatrix)
        {
            GLExt.PushMatrix();
            foreach (Node o in Childs)
            {
                if (o == this)
                {
                    continue;
                }
                GLExt.PushMatrix();

                if (getWMatrix)
                {
                    o.Translate(o);
                    o.WorldMatrix = GLExt.ModelViewMatrix;
                }
                else
                {
                    o.Translate(null);
                    o.Matrix = GLExt.ModelViewMatrix;
                }

                if (o.Childs.Count > 0)
                {
                    o.CalcPositions(getWMatrix);
                }

                GLExt.PopMatrix();
            }
            GLExt.PopMatrix();
        }
Beispiel #4
0
 public void Draw(int x, int y, float z, float rotate, float sx, float sy, bool blend)
 {
     if (Vbo == null)
     {
         CreateVBO(false);
     }
     Bind(0);
     GLExt.PushMatrix();
     {
         GLExt.Translate(x, y, z);
         GLExt.RotateZ(rotate);
         GLExt.Scale(sx, sy, 1);
         if (blend)
         {
             GL.Enable(EnableCap.Blend);
             GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
             Vbo.Render();
             GL.Disable(EnableCap.Blend);
         }
         else
         {
             Vbo.Render();
         }
     }
     GLExt.PopMatrix();
 }
Beispiel #5
0
        /// <summary>
        /// lasketaan objektien paikka ja lisätään näkyvät objektit listoihin, sitten renderoidaan näkyvät.
        /// </summary>
        public virtual void Render()
        {
            Frustum.CalculateFrustum();

            visibleObjects.Clear();
            transparentObjects.Clear();

            GLExt.PushMatrix();

            // lasketaan kaikkien objektien paikat valmiiksi.
            // näkyvät objektit asetetaan visible ja transparent listoihin
            CalculatePositions();

            // renderointi
            foreach (Renderable o in visibleObjects)
            {
                o.RenderModel();
            }
            foreach (SortedList_Model o in transparentObjects)
            {
                Model m = o.model;
                m.RenderModel();
            }
            Texture.UnBind(Settings.COLOR_TEXUNIT);
            GLExt.PopMatrix();
        }
Beispiel #6
0
        // partikkeliengine kutsuu tätä, asetettu räjähdykseen (halutaan muuttaa sen väriä)
        void RenderParticleCallback(Particle p)
        {
            // nyt voi tehdä joka partikkelille mitä haluaa, esim asettaa alphan lifeksi.
            float tc = p.life / 2;

            GLExt.Color4(1f, tc, tc, tc);
        }
Beispiel #7
0
        public override void Render()
        {
            ang += 1;
            GL.Clear(ClearFlags);

            back.DrawFullScreen(0, 0);

            GLExt.Color4(0.5f, 0.5f, 0.5f, 0.5f);
            // images at random z (0.0 - 1.0)
            for (int q = 0; q < 100; q++)
            {
                back.Draw(x[q], y[q], z[q], 0, 0.2f, 0.2f, false); // no blending
            }
            GLExt.Color4(1, 1, 1, 1);


            GLExt.Color4(1, 1, 1, (float)Math.Abs(Math.Sin(ang * 0.01f)));
            back.Draw(10, 10, 0, 1, 1, false);                     // no blending
            back.Draw(Settings.Width / 2 + 10, 10, 0, 1, 1, true); // blending
            GLExt.Color4(1, 1, 1, 1);

            // must invert mouse y
            img.Draw(Mouse.X, Settings.Height - Mouse.Y,
                     mouseZ,
                     ang, 1, 1, true);

            font.Write("2D-test.", 0, 0);
            font.Write("\nUse mouse wheel to move mouse pointer at Z-axis.\n\nPress ESC\nto start the next test.", 10, 20);

            //Console.WriteLine("> " + Mouse.X + "  " + Mouse.Y);

            base.Render();
        }
Beispiel #8
0
 /// <summary>
 /// käytä fps kamerassa
 /// </summary>
 public void SetFPSCamera()
 {
     GLExt.LoadIdentity();
     GLExt.RotateX(-Rotation.X);
     GLExt.RotateY(-Rotation.Y);
     GLExt.RotateZ(-Rotation.Z);
     GLExt.Translate(-Position.X, -Position.Y, -Position.Z);
 }
Beispiel #9
0
        /// <summary>
        /// aseta texturematriisit shadowmapping shaderia varten
        /// </summary>
        static void SetTextureMatrix()
        {
            Matrix4 projMatrix = GLExt.ProjectionMatrix, modelMatrix = GLExt.ModelViewMatrix;

            GLExt.MatrixMode(MatrixMode.Texture);
            GLExt.LoadIdentity();
            GLExt.Translate(0.5f, 0.5f, 0.5f); // remap from [-1,1]^2 to [0,1]^2
            GLExt.Scale(0.5f, 0.5f, 0.5f);
            GLExt.MultMatrix(ref projMatrix);
            GLExt.MultMatrix(ref modelMatrix);
            GLExt.MatrixMode(MatrixMode.Modelview);
        }
Beispiel #10
0
        public override void Render()
        {
            GL.Clear(ClearFlags);

            GLExt.Color4((float)Mouse.X / Settings.Width,
                         (float)Mouse.Y / Settings.Height,
                         1, 1);
            back.DrawFullScreen(0, 0);
            GLExt.Color4(1, 1, 1, 1);

            base.Render();
        }
Beispiel #11
0
        public static void Set2D(int width, int height)
        {
            is3D            = false;
            Settings.Width  = width;
            Settings.Height = height;

            GLExt.SetProjectionMatrix(Matrix4.CreateOrthographicOffCenter(0, width, 0, height, -1, 1));
            GLExt.LoadIdentity();
            GL.Viewport(0, 0, width, height);
            GL.Disable(EnableCap.CullFace);
            GLExt.SetLighting(false);
        }
Beispiel #12
0
        /// <summary>
        /// renderoi worldin valosta päin (pelkän depthin)
        /// </summary>
        public static void SetupShadows(Renderable world, int lightNo, bool withParticles)
        {
            if (UseShadowMapping == false)
            {
                return;
            }

            if (Light.Lights.Count == 0)
            {
                Log.WriteLine("SetupShadows requires at least one light source!", false);
                return;
            }
            GL.Disable(EnableCap.Blend);
            GL.ColorMask(false, false, false, false);
            GL.Disable(EnableCap.CullFace);
            GL.PolygonOffset(1, 1);
            GL.Enable(EnableCap.PolygonOffsetFill);

            fbo.BindDepth();
            fbo.BindFBO();
            fbo.Clear();

            // kuvakulma valosta päin
            GLExt.LoadMatrix(ref Light.Lights[lightNo].OrigOrientationMatrix);
            GLExt.Translate(-Light.Lights[lightNo].Position.X, -Light.Lights[lightNo].Position.Y, -Light.Lights[lightNo].Position.Z);

            SetTextureMatrix();
            Frustum.CalculateFrustum();

            VBO.FastRenderPass = true;
            depthShader.UseProgram();
            world.Render();
            if (withParticles)
            {
                depthShaderAlphaTest.UseProgram();
                Particles.Render();
                GLSLShader.UnBindShader();
            }
            VBO.FastRenderPass = false;
            fbo.UnBindFBO();

            GL.Disable(EnableCap.PolygonOffsetFill);
            GL.Enable(EnableCap.CullFace);
            GL.ColorMask(true, true, true, true);

            GLExt.LoadIdentity();
            GameClass.NumOfObjects = 0;

            ShadowMapping.UnBindLightMask();
        }
Beispiel #13
0
        protected void CalculatePositions()
        {
            CalcPositions(false);

            GLExt.PushMatrix();
            GLExt.LoadIdentity();
            CalcPositions(true);
            GLExt.PopMatrix();

            MakeLists();

            // järjestä läpinäkyvät listassa olevat objektit etäisyyden mukaan, kauimmaiset ekaks
            transparentObjects.Sort(delegate(SortedList_Model z1, SortedList_Model z2) { return(z2.Len.CompareTo(z1.Len)); });
        }
Beispiel #14
0
        public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode)
        {
            if (numOfIndices > 0)
            {
                Dispose();
            }
            int size;

            vertexFlags  = mode;
            numOfIndices = indices.Length;
            Vertex.Size  = BlittableValueType.StrideOf(vertices);

            GL.GenBuffers(1, out vertexID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * BlittableValueType.StrideOf(vertices) != size)
            {
                Log.Error("DataToVBO: Vertex data not uploaded correctly");
            }

            GL.GenBuffers(1, out indexID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (indices.Length * sizeof(short) != size)
            {
                throw new ApplicationException("DataToVBO: Element data not uploaded correctly");
            }

            Shader = GLSLShader.Load();

            if (Shader != null)
            {
                if (Settings.UseGL3)
                {
                    GL.GenVertexArrays(1, out vaoID);
                    GL.BindVertexArray(vaoID);
                }
                GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
                Shader.SetAttributes();
                if (Settings.UseGL3)
                {
                    GL.BindVertexArray(0);
                }
            }

            GLExt.CheckGLError("DataToVBO");
        }
Beispiel #15
0
        public static void Set3D(int width, int height, float near, float far)
        {
            is3D            = true;
            Settings.Width  = width;
            Settings.Height = height;
            Near            = near;
            Far             = far;

            GLExt.SetProjectionMatrix(Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(Fov),
                                                                           (float)width / (float)height, near, far));
            GLExt.LoadIdentity();
            GL.Viewport(0, 0, width, height);
            GL.Enable(EnableCap.CullFace);
            GLExt.SetLighting(true);
        }
Beispiel #16
0
        void Translate(Node node)
        {
            Node obj = node;

            if (node == null)
            {
                obj = this;
            }

            GLExt.Translate(obj.Position.X, obj.Position.Y, obj.Position.Z);
            GLExt.RotateZ(Rotation.Z);
            GLExt.RotateY(Rotation.Y);
            GLExt.RotateX(Rotation.X);
            GLExt.MultMatrix(ref OrigOrientationMatrix);
            GLExt.Scale(obj.Scale.X, obj.Scale.Y, obj.Scale.Z);
        }
Beispiel #17
0
        /// <summary>
        /// renderoidaan näkyvät objektit listoista jotka Render() metodi on luonut.
        /// </summary>
        public void RenderAgain()
        {
            GLExt.PushMatrix();

            // renderointi
            foreach (Renderable o in visibleObjects)
            {
                o.RenderModel();
            }
            foreach (SortedList_Model o in transparentObjects)
            {
                Model m = o.model;
                m.RenderModel();
            }
            Texture.UnBind(Settings.COLOR_TEXUNIT);
            GLExt.PopMatrix();
        }
Beispiel #18
0
        public void DrawFullScreen(int x, int y)
        {
            float sx = (float)Settings.Width / (float)RealWidth;
            float sy = (float)Settings.Height / (float)RealHeight;

            if (Vbo == null)
            {
                CreateVBO(false);
            }
            Bind(0);
            GLExt.PushMatrix();
            {
                GLExt.Translate(sx * x, Settings.Height + sy * (y - RealHeight), 0);
                GLExt.Scale(sx, sy, 1);
                Vbo.Render();
            }
            GLExt.PopMatrix();
        }
Beispiel #19
0
        public void RenderMesh()
        {
            if (Vbo == null)
            {
                return;
            }

            if (DoubleSided)
            {
                GL.Disable(EnableCap.CullFace);
            }
            if (VBO.FastRenderPass)
            {
                if (CastShadow)
                {
                    Vbo.Render();
                }
            }
            else
            {
                Material.SetMaterial();
                if (WorldMatrix != null)
                {
                    GLExt.MatrixMode(MatrixMode.Texture);
                    GLExt.PushMatrix();
                    GLExt.MultMatrix(ref WorldMatrix);
                    GLExt.MatrixMode(MatrixMode.Modelview);
                }

                Vbo.Render();

                if (WorldMatrix != null)
                {
                    GLExt.MatrixMode(MatrixMode.Texture);
                    GLExt.PopMatrix();
                    GLExt.MatrixMode(MatrixMode.Modelview);
                }
            }
            if (DoubleSided)
            {
                GL.Enable(EnableCap.CullFace);
            }
        }
Beispiel #20
0
        // debug
        public void RenderSkeleton()
        {
            if (Settings.UseGL3 == false)
            {
                GLSLShader.UnBindShader();

                GL.Disable(EnableCap.Texture2D);
                GL.Disable(EnableCap.DepthTest);
                GLExt.PushMatrix();
                {
                    GL.Translate(Position.X, Position.Y, Position.Z);
                    GL.Rotate(Rotation.X, 1, 0, 0);
                    GL.Rotate(Rotation.Y, 0, 1, 0);
                    GL.Rotate(Rotation.Z, 0, 0, 1);
                    GL.Rotate(-90, 1, 0, 0);
                    GL.Scale(Scale.X, Scale.Y, Scale.Z);
                    GL.PointSize(5);
                    GLExt.Color4(1, 0, 0, 1);
                    GL.Begin(BeginMode.Points);
                    for (int q = 0; q < numJoints; q++)
                    {
                        GL.Vertex3(skeleton[q].pos);
                    }
                    GL.End();
                    GL.PointSize(1);
                    GLExt.Color4(0, 1, 0, 1);
                    GL.Begin(BeginMode.Lines);
                    for (int q = 0; q < numJoints; q++)
                    {
                        if (skeleton[q].parent != -1)
                        {
                            GL.Vertex3(skeleton[skeleton[q].parent].pos);
                            GL.Vertex3(skeleton[q].pos);
                        }
                    }
                    GL.End();
                }
                GLExt.PopMatrix();
                GL.Enable(EnableCap.DepthTest);
                GL.Enable(EnableCap.Texture2D);
                GLExt.Color4(1, 1, 1, 1);
            }
        }
Beispiel #21
0
 public void Write(string str, float x, float y)
 {
     texture.Bind(0);
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     GLExt.PushMatrix();
     {
         curX = x;
         curY = y;
         GLExt.Translate(x, (float)Settings.Height - y, 0);
         float xp = 0;
         for (int q = 0, ch; q < str.Length; q++)
         {
             // etsi kirjain
             for (ch = 0; ch < chars.Length; ch++)
             {
                 if (str[q] == chars[ch])
                 {
                     break;
                 }
             }
             if (str[q] == '\n')
             {
                 curY -= charHeight * Size;
                 GLExt.Translate(-xp, -charHeight * Size, 0);
                 xp = 0;
                 continue;
             }
             float w  = uv[ch].w;
             float wm = w * Size;
             xp += wm;
             DrawChar(ch);
             GLExt.Translate(wm, 0, 0);
         }
     }
     GLExt.PopMatrix();
     GL.Disable(EnableCap.Blend);
 }
Beispiel #22
0
        void CreateShaders(string shaderFileName, string shaderStr)
        {
            int    statusCode;
            string info;

            string flags = "";

            if (shaderFileName.Contains(":")) // jos flagit (esim :TEXTURE)
            {
                int start = shaderFileName.IndexOf(':');
                flags = shaderFileName.Substring(start, shaderFileName.Length - start);
            }

            // jos shader jo ladattu, käytetään sitä
            if (shaders.ContainsKey(shaderFileName))
            {
                ProgramID      = shaders[shaderFileName].ProgramID;
                vertexObject   = shaders[shaderFileName].vertexObject;
                fragmentObject = shaders[shaderFileName].fragmentObject;
                return;
            }

            Log.WriteLine("Shader: " + shaderFileName);
            shaders.Add(shaderFileName, this);
            if (shaderStr.Contains("[SETUP]") == false)
            {
                shaderStr = "[SETUP]\n" + shaderStr;
            }
            int    s   = shaderStr.IndexOf("[SETUP]") + 8;
            int    v   = shaderStr.IndexOf("[VERTEX]") + 9;
            int    f   = shaderStr.IndexOf("[FRAGMENT]") + 11;
            string set = shaderStr.Substring(s, v - s - 9);
            string vs  = shaderStr.Substring(v, f - v - 11);
            string fs  = shaderStr.Substring(f, shaderStr.Length - f);

            // käy flagsit läpi, #define flags
            string[] flag = flags.Split(':');
            for (int q = 0; q < flag.Length; q++)
            {
                if (flag[q].Length > 0)
                {
                    set += "\n#define " + flag[q];
                }
            }

            // käy [SETUP] blokki läpi, aseta oikeat definet
            string[] setup = set.Split('\n');
            for (int q = 0; q < setup.Length; q++)
            {
                if (setup[q].StartsWith("//"))
                {
                    continue; // skippaa kommentit
                }
                else if (setup[q].StartsWith("#define"))
                {
                    vs = setup[q] + "\n" + vs;
                    fs = setup[q] + "\n" + fs;
                }
            }

            // konvaa gl2:n glsl koodit gl3:sen glsl:ksi
            if (Settings.UseGL3)
            {
                string gl3 = @"#version 130
                            precision highp float;
                            ";
                vs = gl3 + vs;
                vs = vs.Replace("attribute ", "in ");
                vs = vs.Replace("varying ", "out ");

                fs = gl3 + "out vec4 glFragColor;\n" + fs;
                fs = fs.Replace("gl_FragColor", "glFragColor");
                fs = fs.Replace("varying ", "in ");
                fs = fs.Replace("texture2D", "texture");
                fs = fs.Replace("shadow2DProj", "textureProj");
            }

#if DEBUG
#if SHOWSHADERS
            System.Console.WriteLine("----VS------");
            string[] lines = vs.Split('\n');
            for (int q = 0; q < lines.Length; q++)
            {
                System.Console.WriteLine("" + (q + 1) + ": " + lines[q]);
            }

            System.Console.WriteLine("----FS------");
            lines = fs.Split('\n');
            for (int q = 0; q < lines.Length; q++)
            {
                System.Console.WriteLine("" + (q + 1) + ": " + lines[q]);
            }

            System.Console.Write("\n");
#endif
#endif
            vertexObject   = GL.CreateShader(ShaderType.VertexShader);
            fragmentObject = GL.CreateShader(ShaderType.FragmentShader);

            // Compile vertex shader
            GL.ShaderSource(vertexObject, vs);
            GL.CompileShader(vertexObject);
            GL.GetShaderInfoLog(vertexObject, out info);
            GL.GetShader(vertexObject, ShaderParameter.CompileStatus, out statusCode);
            if (statusCode != 1)
            {
                Log.Error(shaderFileName + ":\n" + info);
            }
            else
            {
                Log.WriteLine(info);
            }

            if (info.IndexOf('.') > 0)
            {
                Log.WriteLine(info.Substring(0, info.IndexOf('.')));
            }

            // Compile fragment shader
            GL.ShaderSource(fragmentObject, fs);
            GL.CompileShader(fragmentObject);
            GL.GetShaderInfoLog(fragmentObject, out info);
            GL.GetShader(fragmentObject, ShaderParameter.CompileStatus, out statusCode);
            if (statusCode != 1)
            {
                Log.Error(shaderFileName + ":\n" + info);
            }
            else
            {
                Log.WriteLine(info);
            }

            if (info.IndexOf('.') > 0)
            {
                Log.WriteLine(info.Substring(0, info.IndexOf('.')));
            }

            ProgramID = GL.CreateProgram();
            GL.AttachShader(ProgramID, fragmentObject);
            GL.AttachShader(ProgramID, vertexObject);
            GL.LinkProgram(ProgramID);
            Log.WriteLine(GL.GetProgramInfoLog(ProgramID));
            if (GL.GetProgramInfoLog(ProgramID).Contains("error"))
            {
                Log.Error("GLSL compiling error.");
            }

            GLExt.CheckGLError("GLSL");
        }
Beispiel #23
0
 /// <summary>
 /// käytä esim jos kamera on pathissa
 /// </summary>
 public void SetCameraMatrix()
 {
     GLExt.LoadMatrix(ref OrigOrientationMatrix);
 }
Beispiel #24
0
        public void RenderMesh()
        {
            if (DoubleSided)
            {
                GL.Disable(EnableCap.CullFace);
            }

            if (VBO.FastRenderPass == false)
            {
                Material.SetMaterial();
                GLExt.MatrixMode(MatrixMode.Texture);
                GL.ActiveTexture(TextureUnit.Texture0 + Settings.SHADOW_TEXUNIT);
                GLExt.PushMatrix();
                if (WorldMatrix != null)
                {
                    GLExt.MultMatrix(ref WorldMatrix);
                }
                GLExt.RotateX(-90);
                GLExt.MatrixMode(MatrixMode.Modelview);
            }

            if (VBO.FastRenderPass == false || CastShadow == true)
            {
                GLExt.RotateX(-90);

                for (int i = 0; i < model.Length; i++)
                {
                    if (model[i].vbo == null)
                    {
                        continue;
                    }

                    if (VBO.FastRenderPass == false)
                    {
                        model[i].texture.Bind(0);
                    }

                    // lasketaanko uusi asento (jos ei olla laskettu jo shadowpassis)
                    if (animCalculated == false)
                    {
                        // Interpolate skeletons between two frames
                        InterpolateSkeletons(ref curAnim.skelFrames, curAnim.curFrame, curAnim.nextFrame, curAnim.numJoints, curAnim.lastTime * curAnim.frameRate);
                        PrepareMesh();
                        animCalculated = true;
                    }
                    model[i].vbo.Render();
                }

                if (VBO.FastRenderPass == false)
                {
                    GLExt.MatrixMode(MatrixMode.Texture);
                    GL.ActiveTexture(TextureUnit.Texture0 + Settings.SHADOW_TEXUNIT);
                    GLExt.PopMatrix();
                    GLExt.MatrixMode(MatrixMode.Modelview);
                    animCalculated = false;
                }
            }
            if (DoubleSided)
            {
                GL.Enable(EnableCap.CullFace);
            }
        }
Beispiel #25
0
 protected override void RenderModel()
 {
     GLExt.LoadMatrix(ref Matrix);
     RenderMesh();
 }
Beispiel #26
0
        /// <summary>
        /// renderoi partikkelit, sorttaa läpinäkyvät.
        /// </summary>
        public static new void Render()
        {
            GLExt.Color4(1f, 1, 1, 1f);
            GLExt.PushMatrix();
            GLExt.SetLighting(false);

            List <SortedList_Particles> slist = new List <SortedList_Particles>();

            GL.Disable(EnableCap.CullFace);

            int c = 0;

            // järjestetään taulukko kauimmaisesta lähimpään. pitää rendata siinä järjestyksessä.
            // vain läpikuultavat pitää järjestää. täysin näkyvät renderoidaan samantien.
            for (int q = 0; q < ParticleGroups.Count; q++)
            {
                Particles curpar = ParticleGroups[q];
                if (curpar.particles.Count <= 0)
                {
                    continue;
                }
                if (VBO.FastRenderPass == true)
                {
                    if (curpar.CastShadow == false)
                    {
                        continue;
                    }
                }

                curpar.particles[0].partTex.Bind(0);

                GLExt.PushMatrix();
                GLExt.MultMatrix(ref curpar.WorldMatrix);

                for (int w = 0; w < curpar.NumOfParticles; w++)
                {
                    Particle p = curpar.particles[w];
                    GLExt.PushMatrix();
                    GLExt.Translate(p.pos.X, p.pos.Y, p.pos.Z);
                    Matrix4 matrix = Matrix4.Identity;
                    matrix.Row3           = GLExt.ModelViewMatrix.Row3;
                    GLExt.ModelViewMatrix = matrix;

                    Vector3 v = curpar.WorldMatrix.Row3.Xyz + curpar.Position + p.pos;
                    if (Frustum.SphereInFrustum(v.X, v.Y, v.Z, 10) != 0)
                    {
                        if (VBO.FastRenderPass == true) // renderoi partikkeli depthbufferiin (varjostusta varten)
                        {
                            GLExt.Scale(p.size, p.size, p.size);
                            GLExt.RotateZ(p.zrot);
                            p.partTex.RenderBillboard();
                        }
                        else
                        {
                            c++;
                            if (p.isTransparent == true) // listaan renderoitavaks myöhemmin
                            {
                                float len = (Camera.cam.Position - matrix.Row3.Xyz).LengthSquared;
                                slist.Add(new SortedList_Particles(len, p, matrix));
                            }
                            else // rendataan se nyt, ei lisätä sortattavaks
                            {
                                GLExt.Scale(p.size, p.size, p.size);
                                GLExt.RotateZ(p.zrot);
                                GLExt.Color4(p.color.X, p.color.Y, p.color.Z, p.color.W);;
                                if (p.callBack != null)
                                {
                                    p.callBack(p);
                                }
                                p.partTex.RenderBillboard();
                            }
                        }
                    }
                    GLExt.PopMatrix();
                }
                GLExt.PopMatrix();
            }

            if (VBO.FastRenderPass == false)
            {
                slist.Sort(delegate(SortedList_Particles z1, SortedList_Particles z2) { return(z2.Len.CompareTo(z1.Len)); });
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);

                // rendataan läpikuultavat
                GL.DepthMask(false); // ei kirjoiteta zbufferiin
                for (int q = 0; q < slist.Count; q++)
                {
                    Particle p = slist[q].Part;
                    if (VBO.FastRenderPass == false)
                    {
                        p.partTex.Bind(0);
                        GLExt.Color4(p.color.X, p.color.Y, p.color.Z, p.color.W);
                        if (p.callBack != null)
                        {
                            p.callBack(p);
                        }
                    }
                    GLExt.LoadMatrix(ref slist[q].Matrix);
                    GLExt.Scale(p.size, p.size, p.size);
                    GLExt.RotateZ(p.zrot);
                    p.partTex.RenderBillboard();
                }
                GL.DepthMask(true);
                GL.Disable(EnableCap.Blend);
            }
            GLExt.PopMatrix();

            GL.Enable(EnableCap.CullFace);
            GLExt.Color4(1, 1, 1, 1);
            GLExt.SetLighting(true);
            GameClass.NumOfObjects += c;
        }