コード例 #1
0
ファイル: Billboard.cs プロジェクト: Keilerr/csat
        /// <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);
            }
        }
コード例 #2
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();
 }
コード例 #3
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);
 }
コード例 #4
0
ファイル: ShadowMapping.cs プロジェクト: Keilerr/csat
        /// <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);
        }
コード例 #5
0
ファイル: ShadowMapping.cs プロジェクト: Keilerr/csat
        /// <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();
        }
コード例 #6
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);
        }
コード例 #7
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();
        }
コード例 #8
0
ファイル: BitmapFont.cs プロジェクト: Keilerr/csat
 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);
 }
コード例 #9
0
ファイル: Particles.cs プロジェクト: Keilerr/csat
        /// <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;
        }