private SceneObjectGeometry CreateSphere(string material) { SceneObjectGeometry sphereGeometry = new SceneObjectGeometry("Sphere"); sphereGeometry.ObjectState.DefineState(new CullFaceState(FrontFaceDirection.Ccw, CullFaceMode.Back)); sphereGeometry.ObjectState.DefineState(new TransformState()); sphereGeometry.LocalModelView = Matrix4x4f.Translated(0.0f, 4.0f, 0.0f); sphereGeometry.VertexArray = VertexArrays.CreateSphere(4.0f, 32, 32); ArrayBuffer <Vertex2f> texCoordBuffer = new ArrayBuffer <Vertex2f>(); texCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(texCoordBuffer, VertexArraySemantic.TexCoord); ArrayBuffer <Vertex3f> tanCoordBuffer = new ArrayBuffer <Vertex3f>(); tanCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(tanCoordBuffer, VertexArraySemantic.Tangent); ArrayBuffer <Vertex3f> bitanCoordBuffer = new ArrayBuffer <Vertex3f>(); bitanCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(bitanCoordBuffer, VertexArraySemantic.Bitangent); sphereGeometry.VertexArray.GenerateTexCoords(new VertexArrayTexGen.Sphere()); sphereGeometry.VertexArray.GenerateTangents(); sphereGeometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment"); SetSphereMaterial(sphereGeometry, material); return(sphereGeometry); }
private void GlSurface_ContextCreated(object sender, GLSurfaceViewEventArgs e) { // Wrap GL context with GraphicsContext _Context = new GraphicsContext(e.DeviceContext, e.RenderContext); _CubeScene = new SceneGraph(SceneGraphFlags.None); _CubeScene.SceneRoot = new SceneObjectGeometry(); _CubeScene.SceneRoot.ObjectState.DefineState(new DepthTestState(DepthFunction.Less)); _CubeScene.CurrentView = new SceneObjectCamera(); _CubeScene.SceneRoot.Link(_CubeScene.CurrentView); SceneObjectGeometry geometry = new SceneObjectGeometry(); geometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard"); geometry.AddGeometry(VertexArrays.CreateSphere(3.0f, 8, 8)); _CubeScene.SceneRoot.Link(geometry); _CubeScene.Create(_Context); Gl.ClearColor(1.0f, 0.1f, 0.1f, 1.0f); }