Пример #1
0
        //public static void ShowNormals()
        //{
        //    Shaders.UseShader(0);
        //    Shaders.CurrentTransformation = testobj1.Transformation;
        //    Shaders.UseShader(BasicShader);
        //    GL.Begin(PrimitiveType.Lines);
        //    foreach (Content.Vertex t1 in testobj1.Vertexlist)
        //    {
        //        GL.Color3(Color.White);
        //        GL.Vertex3(t1.Position);
        //        GL.Color3(Color.Red);
        //        GL.Vertex3(t1.Position + (t1.Normal*10));
        //    }
        //    GL.End();
        //    Shaders.CurrentTransformation = Matrix4.Identity;
        //    Shaders.UseShader(0);
        //}

        public static void Render()
        {
            error = GL.GetError();
            if (error != ErrorCode.NoError)
            {
                throw new Exception(error.ToString());
            }
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Color3(Color.Blue);
            //  GL.DepthMask(false);
            //  skybox.Draw(PolygonMode.Fill,SkyboxShader);
            //  GL.DepthMask(true);

            testobj1.Draw();
            Shaders.CurrentTransformation = Matrix4.Identity;

            Shaders.UseShader(BasicShader);
            GL.Begin(PrimitiveType.Lines);
            GL.Color3(Color.Yellow);
            GL.Vertex3(0, 0, -20);
            GL.Vertex3(0, 0, 0);
            GL.Color3(Color.Blue);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(0, 0, +20);
            GL.Color3(Color.Red);
            GL.Vertex3(-20, 0, 0);
            GL.Vertex3(0, 0, 0);
            GL.Color3(Color.Orange);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(+20, 0, 0);
            GL.Color3(Color.Green);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(0, +20, 0);
            GL.Color3(Color.Purple);
            GL.Vertex3(0, -20, 0);
            GL.Vertex3(0, 0, 0);
            foreach (Lighting.Light light in Lighting.LightList)
            {
                GL.Color3(Color.Green);
                GL.Vertex3(light.Position);
                GL.Color3(Color.White);
                GL.Vertex3(light.Direction);
            }
            GL.End();
            //// ShowNormals();
            gamewindow.SwapBuffers();
            frames++;
        }
Пример #2
0
        public static void Load()
        {
            gamewindow.VSync       = VSyncMode.On;
            gamewindow.WindowState = WindowState.Maximized;
            gamewindow.Location    = new Point((Screen.PrimaryScreen.WorkingArea.Width - gamewindow.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - gamewindow.Height) / 2);
            UntexturedShader       = Shaders.LoadShaders(Shaders.VUnTextured, Shaders.FUnTextured);
            BasicShader            = Shaders.LoadShaders(Shaders.Vbasic, Shaders.Fbasic);
            TexturedShader         = Shaders.LoadShaders(Shaders.VTextured, Shaders.FTextured);
            SkyboxShader           = Shaders.LoadShaders(Shaders.VSkybox, Shaders.FSkybox);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.Enable(EnableCap.DepthClamp);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            //GL.Enable(EnableCap.FramebufferSrgb);
            gamewindow.CursorVisible = false;
            GL.ClearColor(Color.CornflowerBlue);

            testobj1 = Content.Object.LoadObj(@"C:\Users\alexf\Google Drive\Computer\Desktop\ModelFile\test1\test1.ccf", true);
            // testobj1.ShaderProgram = TexturedShader;
            // testobj1.Transformation = Matrix4.CreateRotationX(5) *Matrix4.CreateScale(.0005f) *Matrix4.CreateTranslation(0.05f,-0.5f,0);
            testobj1.Transformation = Matrix4.CreateScale(.0005f);
            //skybox = Content.Mesh.LoadObj(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1\cubemap.obj", false);
            // skybox.ShaderProgram = SkyboxShader;
            List <string> skyboxfaces = new List <string>();

            skyboxfaces.Add(Directory.GetFiles(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1").Where(x => x.Contains("RT.jpg")).First());
            skyboxfaces.Add(Directory.GetFiles(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1").Where(x => x.Contains("LF.jpg")).First());
            skyboxfaces.Add(Directory.GetFiles(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1").Where(x => x.Contains("UP.jpg")).First());
            skyboxfaces.Add(Directory.GetFiles(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1").Where(x => x.Contains("DN.jpg")).First());
            skyboxfaces.Add(Directory.GetFiles(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1").Where(x => x.Contains("BK.jpg")).First());
            skyboxfaces.Add(Directory.GetFiles(@"C:\Users\alexf\Google Drive\Computer\Desktop\skybox1").Where(x => x.Contains("FR.jpg")).First());
            //Content.SkyboxTexture = Content.LoadCubeMap(skyboxfaces.ToArray());


            Lighting.Light l1 = new Lighting.Light(new Vector3(0f, 1f, -1f), new Vector3(0f, 0.5f, .5f), new Vector4(1f, 1f, 1f, 1f), new Vector3(0, 0, 0), 0, 200, .01f);
            Lighting.LightList.Add(l1);
        }
Пример #3
0
 public void DrawModel(Instance c1, Matrix4 Transformation)
 {
     //  Shaders.CurrentTransformation = (c1 as Subcomponent).matrix * Transformation;
     if (c1.component.model != null)
     {
         Shaders.UseShader(c1.component.model.ShaderProgram, c1.component.model);
         GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
         if (c1.component.model.DiffuseTexture != -1)
         {
             GL.ActiveTexture(TextureUnit.Texture0);
             GL.BindTexture(TextureTarget.Texture2D, c1.component.model.DiffuseTexture);
         }
         if (c1.component.model.SpecularTexture != -1)
         {
             GL.ActiveTexture(TextureUnit.Texture1);
             GL.BindTexture(TextureTarget.Texture2D, c1.component.model.SpecularTexture);
         }
         if (c1.component.model.NormalTexture != -1)
         {
             GL.ActiveTexture(TextureUnit.Texture2);
             GL.BindTexture(TextureTarget.Texture2D, c1.component.model.NormalTexture);
         }
         GL.BindVertexArray(c1.component.model.VertexArrayObjectID);
         Program.error = GL.GetError();
         if (Program.error != ErrorCode.NoError)
         {
             throw new Exception(Program.error.ToString());
         }
         GL.DrawElements(PrimitiveType.Triangles, c1.component.model.IndexBuffer.Count(), DrawElementsType.UnsignedInt, 0);
         Shaders.UseShader(0);
     }
     foreach (Instance c2 in c1.component.Children)
     {
         DrawModel(c2, Shaders.CurrentTransformation);
     }
 }