Beispiel #1
0
 public void Render(List <JWaterTile> waterTiles, JCamera camera, JLight light)
 {
     PrepareRender(camera, light);
     foreach (JWaterTile tile in waterTiles)
     {
         Matrix4 modelMatrix = JMathUtils.createTransformationMatrix(new Vector3(tile.X, tile.Height, tile.Z), 0, 0, 0, JWaterTile.TILE_SIZE);
         WaterShader.LoadModelMatrix(modelMatrix);
         GL.DrawArrays(PrimitiveType.Triangles, 0, WaterQuad.vertexCount);
     }
     Unbind();
 }
        public void Render(JLight light, JCamera camera, Vector4 clippingPlane)
        {
            prepare();

            Shader.start();
            Shader.LoadClippingPlane(clippingPlane);
            Shader.LoadSkyColor(skyRed, skyGreen, skyBlue);
            Shader.LoadLight(light);
            Shader.LoadViewMatrix(camera);
            Renderer.render(Entities);
            Shader.stop();

            TerrainShader.start();
            TerrainShader.LoadClippingPlane(clippingPlane);
            TerrainShader.LoadSkyColor(skyRed, skyGreen, skyBlue);
            TerrainShader.LoadLight(light);
            TerrainShader.LoadViewMatrix(camera);
            TerrainRenderer.Render(terrains);
            TerrainShader.stop();

            Entities.Clear();
            terrains.Clear();
        }
Beispiel #3
0
        private void PrepareRender(JCamera camera, JLight light)
        {
            WaterShader.start();
            WaterShader.LoadViewMatrix(camera);

            distortionVariance += DISTORTION_SPEED * JGameWindow.FrameTimeSeconds();
            distortionVariance %= 1.0f;
            WaterShader.LoadDistortionVariance(distortionVariance);
            WaterShader.LoadLight(light);

            GL.BindVertexArray(WaterQuad.vaoID);
            GL.EnableVertexAttribArray(0);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, FrameBuffer.ReflectionTexture);
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, FrameBuffer.RefractionTexture);
            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2D, WaterTile.ColorTexture.TextureID);
            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2D, dudvMap);
            GL.ActiveTexture(TextureUnit.Texture4);
            GL.BindTexture(TextureTarget.Texture2D, normalMap);
        }
 public void RenderScene(List <JBoundedEntity> entities, List <JEntity> staticEntities, JPerlinTerrain terrain, JLight light, JCamera camera, Vector4 clippingPlane)
 {
     processTerrain(terrain);
     foreach (JBoundedEntity entity in entities)
     {
         ProcessEntity(entity);
         ProcessEntity(entity.BoundingSphere.SphereEntity);
     }
     foreach (JEntity entity in staticEntities)
     {
         ProcessEntity(entity);
     }
     Render(light, camera, clippingPlane);
 }
        /// <summary>
        /// GraphicsMode used for anitaliasing.
        /// </summary>
        public JGameWindow() : base(WIDTH, HEIGHT, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), "JModelViewer", GameWindowFlags.Default, DisplayDevice.Default, 3, 0, GraphicsContextFlags.ForwardCompatible)
        {
            PlayerTexturePath = JFileUtils.GetPathToResFile("Cowboy\\CowboyTexture.png");
            PlayerModelPath   = JFileUtils.GetPathToResFile("Cowboy\\Cowboy.obj");

            Version  version        = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            DateTime buildDate      = new DateTime(2000, 1, 1).AddDays(version.Build).AddSeconds(version.Revision * 2);
            string   displayVersion = $"{version} ({buildDate})";

            Console.WriteLine("JGameEngine v." + displayVersion);

            Console.WriteLine("OpenGL version: " + GL.GetString(StringName.Version));

            Loader          = new JLoader();
            PlayerModelData = JObjFileLoader.LoadObj(PlayerModelPath);

            Console.WriteLine("Using .obj file: " + PlayerModelPath);
            PlayerModel = Loader.LoadToVAO(PlayerModelData.Vertices, PlayerModelData.TextureCoords, PlayerModelData.Normals, PlayerModelData.Indices);

            Console.WriteLine("Using .png texture file: " + PlayerTexturePath + "...");
            JModelTexture texture = new JModelTexture(Loader.loadTexture(PlayerTexturePath));

            TexturedModel = new JTexturedModel(PlayerModel, texture);
            Light         = new JLight(new Vector3(0, 0, 0), new Vector3(1, 1, 1));

            JTerrainTexture textureWaterDeep       = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\WaterDeep.png")));
            JTerrainTexture textureWaterShallow    = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\WaterShallow.png")));
            JTerrainTexture textureSand            = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\Sand.png")));
            JTerrainTexture textureGrassNatural    = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\GrassNatural.png")));
            JTerrainTexture textureGrassLush       = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\GrassLush.png")));
            JTerrainTexture textureMountainNatural = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\MountainNatural.png")));
            JTerrainTexture textureMountainRocky   = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\MountainRocky.png")));
            JTerrainTexture textureSnow            = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\Snow.png")));

            JTerrainTexturePack texturePack = new JTerrainTexturePack();

            texturePack.AddTerrainTexture(textureWaterDeep, 0.1f);
            texturePack.AddTerrainTexture(textureWaterShallow, 0.15f);
            texturePack.AddTerrainTexture(textureSand, 0.18f);
            texturePack.AddTerrainTexture(textureGrassNatural, 0.35f);
            texturePack.AddTerrainTexture(textureGrassLush, 0.45f);
            texturePack.AddTerrainTexture(textureMountainNatural, 0.6f);
            texturePack.AddTerrainTexture(textureMountainRocky, 0.7f);
            texturePack.AddTerrainTexture(textureSnow, 0.8f);

            MasterRenderer = new JMasterRenderer(texturePack);

            WaterBuffer = new JWaterFrameBuffer(this);
            WaterShader = new JWaterShader();
            waterTiles  = new List <JWaterTile>();
            WaterTile   = new JWaterTile(400, -400, 8, textureWaterShallow);
            waterTiles.Add(WaterTile);
            waterRenderer = new JWaterRenderer(Loader, WaterShader, MasterRenderer.projectionMatrix, WaterBuffer, WaterTile);

            terrain = new JPerlinTerrain(0, -1, Loader, texturePack);

            Entity     = new JBoundedEntity(TexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.1f, Loader);
            Entity2    = new JBoundedEntity(TexturedModel, new Vector3(100, 0, -50), new Vector3(0, 0, 1), 0.1f, Loader);
            EntityList = new List <JBoundedEntity>();
            EntityList.Add(Entity);
            EntityList.Add(Entity2);

            // Generate Trees
            JEntityGenerator entityGenerator = new JEntityGenerator(Loader, terrain, WaterTile);

            StaticEntities = entityGenerator.GenerateTrees();

            Camera = new JCameraFree();

            picker = new JMousePicker(Camera, MasterRenderer.projectionMatrix, terrain, this);

            LastFrameTime = GetCurrentTime();
        }
Beispiel #6
0
 public void LoadLight(JLight light)
 {
     base.LoadVector(location_lightColor, light.Color);
     base.LoadVector(location_lightPosition, light.Position);
 }