Я пытаюсь нарисовать треугольник, используя OpenTK и VBO.Как нарисовать треугольник с VBO и F #
Но единственное, что появляется, это коричневый фон.
open System
open OpenTK
open OpenTK.Graphics.OpenGL4
open OpenTK.Graphics
type Window(width, height, mode, title, options) =
inherit GameWindow(width, height, mode, title, options)
let mutable buffers :int = 0
let createVertexBuffer =
let vertices =
[|
new Vector3(-1.f,-1.f,0.f)
new Vector3(1.f,-1.f,0.f)
new Vector3(0.f,-1.f,0.f)
|]
buffers <- GL.GenBuffer()
GL.BindBuffer(BufferTarget.ArrayBuffer, buffers)
GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length * Vector3.SizeInBytes), vertices, BufferUsageHint.StaticDraw)
// Function for initialization.
override this.OnLoad(e) =
// The background will just cleared with blue color.
base.OnLoad(e)
//GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f)
GL.ClearColor(Color4.Brown)
//GL.Enable(EnableCap.DepthTest)
createVertexBuffer
// Function is called before first update and every time when the window is resized.
override this.OnResize(e) =
GL.Viewport(0, 0, this.Width, this.Height)
base.OnResize(e)
// Function to render and display content.
override this.OnRenderFrame(e) =
base.OnRenderFrame(e)
GL.Clear(ClearBufferMask.ColorBufferBit)
GL.Clear(ClearBufferMask.DepthBufferBit)
GL.EnableVertexAttribArray(0)
GL.BindBuffer(BufferTarget.ArrayBuffer, buffers)
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0)
GL.DrawArrays(PrimitiveType.Triangles, 0, 3)
GL.DisableVertexAttribArray(0)
// Swap the front and back buffers
this.Context.SwapBuffers()
[<EntryPoint>]
let main argv =
use window = new Window(640, 480, Graphics.GraphicsMode.Default, "Example Window", GameWindowFlags.Default)
window.Run()
0
У кого-нибудь есть представление о том, что я делаю неправильно?
В код отступа используйте 4 пробела или выделите + нажмите кнопку '{}' или ctrl + k. 4 backticks в стиле github не работают. –
Спасибо за советы @JohnPalmer. –