Beispiel #1
0
        private void drawCubeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var cubeVertices = SFShapes.ShapeGenerator.GetCubePositions(Vector3.Zero, 1);
            var cube         = new SFShapes.Mesh3D(cubeVertices);

            DrawShape(cubeVertices.Item1, cube);
        }
Beispiel #2
0
        private void drawSphereToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var sphereVertices = SFShapes.ShapeGenerator.GetSpherePositions(Vector3.Zero, 1, 32);
            var sphere         = new SFShapes.Mesh3D(sphereVertices);

            DrawShape(sphereVertices.Item1, sphere);
        }
Beispiel #3
0
        private void DrawShape(List <Vector3> shapeVertices, SFShapes.Mesh3D shape)
        {
            var textures = new List <TextureRenderInfo>()
            {
                new TextureRenderInfo("uvTestPattern", UvCoord.TexCoord0, TextureSwizzle.Rgb)
            };
            var pos = new SFGenericModel.VertexAttributes.VertexFloatAttribute("position", SFGenericModel.VertexAttributes.ValueCount.Three, VertexAttribPointerType.Float);
            var uv0 = new SFGenericModel.VertexAttributes.VertexFloatAttribute("uv0", SFGenericModel.VertexAttributes.ValueCount.Two, VertexAttribPointerType.Float);

            TextureShaderGenerator.CreateShader(textures, pos, pos, uv0, out string vert, out string frag);

            Shader shader = new Shader();

            shader.LoadShaders(new List <Tuple <string, ShaderType, string> >()
            {
                new Tuple <string, ShaderType, string>(vert, ShaderType.VertexShader, ""),
                new Tuple <string, ShaderType, string>(frag, ShaderType.FragmentShader, ""),
            });
            System.Diagnostics.Debug.WriteLine(shader.GetErrorLog());

            shader.UseProgram();

            shader.SetTexture("uvTestPattern", graphicsResources.uvTestPattern, 0);

            Camera camera = new Camera()
            {
                RenderWidth  = glControl1.Width,
                RenderHeight = glControl1.Height
            };

            Vector4 boundingSphere = SFGraphics.Utils.BoundingSphereGenerator.GenerateBoundingSphere(shapeVertices);

            camera.FrameBoundingSphere(boundingSphere.Xyz, boundingSphere.W, 0);

            camera.NearClipPlane = 0.01f;
            camera.FarClipPlane  = 100;
            camera.Zoom(-0.5f);
            camera.RotationXDegrees = -50;
            camera.RotationYDegrees = -180;

            glControl1.MakeCurrent();
            GL.ClearColor(1, 1, 1, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            shape.Draw(shader, camera);
            glControl1.SwapBuffers();
        }