コード例 #1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            OpenTK.Input.MouseState mouseState = OpenTK.Input.Mouse.GetState();

            if (mouseState.IsButtonDown(OpenTK.Input.MouseButton.Left))
            {
                xPosition -= e.Time;
            }
            if (mouseState.IsButtonDown(OpenTK.Input.MouseButton.Right))
            {
                xPosition += e.Time;
            }

            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 projMatrix = Matrix4.CreateOrthographicOffCenter(0, DEFAULT_WIDTH, 0, DEFAULT_HEIGHT, -1.0f, 1.0f);
            Matrix4 viewMatrix = Matrix4.Identity;

            Matrix4.CreateRotationZ((float)RotationAngle, out Matrix4 tempMatrix);
            Matrix4.CreateTranslation((float)xPosition * 200, -50.0f, 0.0f, out Matrix4 tempMatrix2);

            foreach (var obj in GameObjects)
            {
                Matrix4 mvp = tempMatrix2 * tempMatrix * obj.ModelMatrix * viewMatrix * projMatrix;

                GL.UseProgram(MainShaderProgram.ProgramId);

                GlCustomUtil.Bind3dObject(obj);

                GL.UniformMatrix4(MainShaderProgram.MatrixShaderLocation, false, ref mvp);

                GL.DrawElements(PrimitiveType.Triangles, obj.Indices.Length, DrawElementsType.UnsignedInt, 0);
                var x = GL.GetError();
            }

            SwapBuffers();
        }
コード例 #2
0
        protected override void OnLoad(EventArgs e)
        {
            GameObjects = new List <BufferData> {
                Geometry.GetTriangle1(),
                    Geometry.GetTriangle2()
            }
            .Select(x => GlCustomUtil.GeometryTo3dObject(x))
            .ToList();

            // TODO: Use the unbind function to clean up. Maybe have a class CustomGlContext.
            foreach (Object3d obj3d in GameObjects)
            {
                GlCustomUtil.Bind3dObject(obj3d);
            }

            MainShaderProgram = GlCustomUtil.CreateShaderProgram();
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.PatchParameter(PatchParameterInt.PatchVertices, 3);

            GL.Enable(EnableCap.Blend);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
        }