public void Render(ICamera camera, Vector3d lightPosition) { _simpleMaterial.Bind(); _simpleMaterial.ProjectionMatrix.Set(camera.ComputeProjectionMatrix().ToMatrix4()); _simpleMaterial.ViewMatrix.Set(camera.ComputeCameraMatrix().ToMatrix4()); _simpleMaterial.Color.Set(new Vector4(0f, 1f, 0f, 1f)); _simpleMaterial.ModelMatrix.Set(Matrix4.CreateTranslation((Vector3)lightPosition)); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.Disable(EnableCap.CullFace); _renderable.VertexArrayObject.Bind(); GL.DrawElements(BeginMode.Triangles, _renderable.Faces * 3, DrawElementsType.UnsignedInt, 0); _renderable.VertexArrayObject.Unbind(); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Enable(EnableCap.CullFace); _simpleMaterial.Unbind(); }
public void Update(double elapsedTime, EntityManager entityManager) { GL.ClearColor(Color4.White); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.DepthTest); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.CullFace); GL.FrontFace(FrontFaceDirection.Cw); _simpleMaterial.Bind(); var light = entityManager.GetEntitiesWithComponent <PositionalLightComponent>().Single(); var positionalLightComponent = entityManager.GetComponent <PositionalLightComponent>(light); _simpleMaterial.LightPosition.Set((Vector3)positionalLightComponent.Position); _simpleMaterial.ProjectionMatrix.Set(_camera.ComputeProjectionMatrix().ToMatrix4()); _simpleMaterial.ViewMatrix.Set(_camera.ComputeCameraMatrix().ToMatrix4()); foreach (var entity in entityManager.GetEntitiesWithComponent <StaticMesh>()) { var component = entityManager.GetComponent <StaticMesh>(entity); //if(!component.IsVisible) //continue; //component.IsVisible = false; var resources = EnsureResources(component); resources.VertexArrayObject.Bind(); _simpleMaterial.ModelMatrix.Set(component.ModelMatrix); _simpleMaterial.Color.Set(component.Color); //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); //GL.Disable(EnableCap.CullFace); GL.DrawElements(BeginMode.Triangles, component.Mesh.Faces.Length * 3, DrawElementsType.UnsignedInt, 0); //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); //GL.Enable(EnableCap.CullFace); resources.VertexArrayObject.Unbind(); } _simpleMaterial.Unbind(); _normalDebugProgram.Bind(); _normalDebugProgram.ProjectionMatrix.Set(_camera.ComputeProjectionMatrix().ToMatrix4()); _normalDebugProgram.ViewMatrix.Set(_camera.ComputeCameraMatrix().ToMatrix4()); foreach (var entity in entityManager.GetEntitiesWithComponent <NormalComponent>()) { var component = entityManager.GetComponent <StaticMesh>(entity); var resources = EnsureResources(component); resources.VertexArrayObject.Bind(); _normalDebugProgram.ModelMatrix.Set(component.ModelMatrix); GL.DrawElements(BeginMode.Triangles, component.Mesh.Faces.Length * 3, DrawElementsType.UnsignedInt, 0); resources.VertexArrayObject.Unbind(); } _normalDebugProgram.Unbind(); }