Example #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);
        }
Example #2
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();
        }
Example #3
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);
            }
        }
Example #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();
 }
Example #5
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();
        }
Example #6
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)); });
        }
Example #7
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();
        }
Example #8
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();
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
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);
 }
Example #12
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);
            }
        }
Example #13
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;
        }