示例#1
0
        void RenderableWater_WriteNextFrameEvent(Vector3 camerapos)
        {
            double           xmultiplier = scale.x / numsectors;
            double           ymultiplier = scale.y / numsectors;
            GraphicsHelperGl g           = new GraphicsHelperGl();

            g.SetMaterialColor(new double[] { 0, 0.2, 0.8, 0.6 });
            g.EnableBlendSrcAlpha();
            g.EnableModulate();
            g.DisableTexture2d();          // note to self: could add texture??? (or vertex fragment)
            Gl.glDisable(Gl.GL_CULL_FACE); // water has two sides?
            g.Normal(new Vector3(0, 0, 1));
            for (int x = 0; x < numsectors; x++)
            {
                Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
                for (int y = 0; y <= numsectors; y++)
                {
                    Vector3 posoffset = new Vector3(x * xmultiplier, y * ymultiplier, 0);
                    Vector3 vertexpos = pos + posoffset;
                    //Console.WriteLine(vertexpos);
                    g.Vertex(vertexpos);
                    vertexpos.x += xmultiplier;
                    //Console.WriteLine(vertexpos);
                    g.Vertex(vertexpos);
                }
                Gl.glEnd();
            }
            Gl.glEnable(Gl.GL_CULL_FACE);
            Gl.glDisable(Gl.GL_BLEND);
            g.SetMaterialColor(new double[] { 1, 1, 1, 1 });
        }
示例#2
0
 void RenderableWater_WriteNextFrameEvent(Vector3 camerapos)
 {
     double xmultiplier = scale.x / numsectors;
     double ymultiplier = scale.y / numsectors;
     GraphicsHelperGl g = new GraphicsHelperGl();
     g.SetMaterialColor(new double[] { 0, 0.2, 0.8, 0.6 });
     g.EnableBlendSrcAlpha();
     g.EnableModulate();
     g.DisableTexture2d(); // note to self: could add texture??? (or vertex fragment)
     Gl.glDisable( Gl.GL_CULL_FACE ); // water has two sides?
     g.Normal(new Vector3(0, 0, 1));
     for (int x = 0; x < numsectors; x++)
     {
         Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
         for (int y = 0; y <= numsectors; y++)
         {
             Vector3 posoffset = new Vector3( x * xmultiplier, y * ymultiplier, 0 );
             Vector3 vertexpos = pos + posoffset;
             //Console.WriteLine(vertexpos);
             g.Vertex(vertexpos);
             vertexpos.x += xmultiplier;
             //Console.WriteLine(vertexpos);
             g.Vertex(vertexpos);
         }
         Gl.glEnd();
     }
     Gl.glEnable( Gl.GL_CULL_FACE );
     Gl.glDisable( Gl.GL_BLEND );
     g.SetMaterialColor(new double[] { 1, 1, 1, 1 });
 }
        // renders to 0,0,0 ; size will be (mapwidth + 1) * xscale by (mapheight + 1) * yscale
        public void Render(Vector3 camerapos)
        {
            //ExportAsSingleTexture.GetInstance().Export("");

            Gl.glPushMatrix();
            FrustrumCulling culling = FrustrumCulling.GetInstance();
            //IGraphicsHelper g = GraphicsHelperFactory.GetInstance();
            GraphicsHelperGl g = new GraphicsHelperGl();

            int iSectorsDrawn = 0;
            int iChunkDrawsSkippedNoTextureSection = 0;

            int numxchunks = width / chunksize;
            int numychunks = height / chunksize;

            double chunkboundingradius = chunksize * xscale * 1.414 / 2;
            //Console.WriteLine("chunkboundingradius: " + chunkboundingradius);

            g.SetMaterialColor(new Color(1.0, 1.0, 1.0));

            Gl.glDepthFunc(Gl.GL_LEQUAL);
            g.EnableBlendSrcAlpha();

            foreach( RendererPass rendererpass in rendererpasses )
            {
                rendererpass.Apply();
                for (int chunkx = 0; chunkx < numxchunks - 1; chunkx++)
                {
                    for (int chunky = 0; chunky < numychunks - 1; chunky++)
                    {
                        if (chunkusestexturestage[rendererpass.texturestages[0].maptexturestage.maptexturestagemodel][chunkx, chunky])
                        {
                            //if (iSectorsDrawn == 0)
                            //{
                            int chunkmapposx = chunkx * chunksize;
                            int chunkmapposy = chunky * chunksize;
                            int chunkdisplayposx = chunkmapposx * xscale;
                            int chunkdisplayposy = chunkmapposy * yscale;
                            Vector3 chunkmappos = new Vector3(chunkmapposx, chunkmapposy, heightmap[chunkmapposx, chunkmapposy]);
                            Vector3 chunkdisplaypos = new Vector3(chunkdisplayposx, chunkdisplayposy, heightmap[chunkmapposx, chunkmapposy]);
                            Vector3 chunkcentredisplaypos = chunkdisplaypos +
                                new Vector3(chunksize * xscale / 2, chunksize * yscale / 2, 0);
                            if (culling.IsInsideFrustum(chunkcentredisplaypos, chunkboundingradius))
                            //if (true)
                            {
                                iSectorsDrawn++;

                                // check how far away sector is
                                // if nearby we render it in detail
                                // otherwise just render a few points from it
                                double distancesquared = Vector3.DistanceSquared(chunkcentredisplaypos, camerapos);
                                //if ( distancesquared > detaildistance * detaildistance)
                                int stepsize = 16;
                                if (distancesquared < loddistances[0] * loddistances[0])
                                {
                                    stepsize = 1;
                                }
                                else if (distancesquared < loddistances[1] * loddistances[2])
                                {
                                    stepsize = 2;
                                }
                                else if (distancesquared < loddistances[3] * loddistances[3])
                                {
                                    stepsize = 4;
                                }
                                else if (distancesquared < loddistances[4] * loddistances[4])
                                {
                                    stepsize = 8;
                                }
                                else if (distancesquared < loddistances[5] * loddistances[5])
                                {
                                   stepsize = 16;
                                }

                                RenderChunk(chunkx, chunky, stepsize);
                            }
                        }
                        else
                        {
                            iChunkDrawsSkippedNoTextureSection++;
                        }
                        // System.Environment.Exit(1);
                    }
                }
                //Gl.glTranslated(0, 0, 500);
            }
            //System.Environment.Exit(0);
            // Console.WriteLine("chunk renders: " + iSectorsDrawn + " maptextureculls: " + iChunkDrawsSkippedNoTextureSection);
            for (int i = maxtexels - 1; i >= 0; i--)
            {
                g.ActiveTexture(i);
                g.SetTextureScale(1 );
                g.DisableTexture2d();
            }
            Gl.glDepthFunc(Gl.GL_LESS);
            Gl.glDisable(Gl.GL_BLEND);
            g.EnableModulate();
            Gl.glPopMatrix();
        }
        // renders to 0,0,0 ; size will be (mapwidth + 1) * xscale by (mapheight + 1) * yscale
        public void Render(Vector3 camerapos)
        {
            //ExportAsSingleTexture.GetInstance().Export("");

            Gl.glPushMatrix();
            FrustrumCulling culling = FrustrumCulling.GetInstance();
            //IGraphicsHelper g = GraphicsHelperFactory.GetInstance();
            GraphicsHelperGl g = new GraphicsHelperGl();

            int iSectorsDrawn = 0;
            int iChunkDrawsSkippedNoTextureSection = 0;

            int numxchunks = width / chunksize;
            int numychunks = height / chunksize;

            double chunkboundingradius = chunksize * xscale * 1.414 / 2;

            //Console.WriteLine("chunkboundingradius: " + chunkboundingradius);

            g.SetMaterialColor(new Color(1.0, 1.0, 1.0));

            Gl.glDepthFunc(Gl.GL_LEQUAL);
            g.EnableBlendSrcAlpha();

            foreach (RendererPass rendererpass in rendererpasses)
            {
                rendererpass.Apply();
                for (int chunkx = 0; chunkx < numxchunks - 1; chunkx++)
                {
                    for (int chunky = 0; chunky < numychunks - 1; chunky++)
                    {
                        if (chunkusestexturestage[rendererpass.texturestages[0].maptexturestage.maptexturestagemodel][chunkx, chunky])
                        {
                            //if (iSectorsDrawn == 0)
                            //{
                            int     chunkmapposx          = chunkx * chunksize;
                            int     chunkmapposy          = chunky * chunksize;
                            int     chunkdisplayposx      = chunkmapposx * xscale;
                            int     chunkdisplayposy      = chunkmapposy * yscale;
                            Vector3 chunkmappos           = new Vector3(chunkmapposx, chunkmapposy, heightmap[chunkmapposx, chunkmapposy]);
                            Vector3 chunkdisplaypos       = new Vector3(chunkdisplayposx, chunkdisplayposy, heightmap[chunkmapposx, chunkmapposy]);
                            Vector3 chunkcentredisplaypos = chunkdisplaypos +
                                                            new Vector3(chunksize * xscale / 2, chunksize * yscale / 2, 0);
                            if (culling.IsInsideFrustum(chunkcentredisplaypos, chunkboundingradius))
                            //if (true)
                            {
                                iSectorsDrawn++;

                                // check how far away sector is
                                // if nearby we render it in detail
                                // otherwise just render a few points from it
                                double distancesquared = Vector3.DistanceSquared(chunkcentredisplaypos, camerapos);
                                //if ( distancesquared > detaildistance * detaildistance)
                                int stepsize = 16;
                                if (distancesquared < loddistances[0] * loddistances[0])
                                {
                                    stepsize = 1;
                                }
                                else if (distancesquared < loddistances[1] * loddistances[2])
                                {
                                    stepsize = 2;
                                }
                                else if (distancesquared < loddistances[3] * loddistances[3])
                                {
                                    stepsize = 4;
                                }
                                else if (distancesquared < loddistances[4] * loddistances[4])
                                {
                                    stepsize = 8;
                                }
                                else if (distancesquared < loddistances[5] * loddistances[5])
                                {
                                    stepsize = 16;
                                }

                                RenderChunk(chunkx, chunky, stepsize);
                            }
                        }
                        else
                        {
                            iChunkDrawsSkippedNoTextureSection++;
                        }
                        // System.Environment.Exit(1);
                    }
                }
                //Gl.glTranslated(0, 0, 500);
            }
            //System.Environment.Exit(0);
            // Console.WriteLine("chunk renders: " + iSectorsDrawn + " maptextureculls: " + iChunkDrawsSkippedNoTextureSection);
            for (int i = maxtexels - 1; i >= 0; i--)
            {
                g.ActiveTexture(i);
                g.SetTextureScale(1);
                g.DisableTexture2d();
            }
            Gl.glDepthFunc(Gl.GL_LESS);
            Gl.glDisable(Gl.GL_BLEND);
            g.EnableModulate();
            Gl.glPopMatrix();
        }