hannesh's picture

Rendering a VBO

Hi there!

I'm a newbie to OpenGL, I moved here from DirectX using XNA, which I have tons of experience with.

So I've realised that the main ways to render things in OpenGL are to call Begin and then start specifying vertices, this seems slow.
I know that the other way is to use a VBO, I think I've succesfully created a VBO and filled it with data, but i'm not sure how to draw it. I'm pretty clueless about what to do in my draw function.

I'm used to DirectX's:


Some code on how to do this or an explanation would be most helpful.




Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hannesh's picture

I managed to solve the problem myself by reading someone elses code.

Here's how I got it working, please tell me if I'm doing anything wrong or badly:

uint VBOid;
        protected override void OnLoad(EventArgs e)
            GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
            GL.GenBuffers(1, out VBOid);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
            myVertex[] vertices = new myVertex[4]
                new myVertex(new Vector3(-0.5f, -0.5f, 0.0f)),
                new myVertex(new Vector3(-0.5f, 0.5f, 0.0f)),
                new myVertex(new Vector3(0.5f, 0.5f, 0.0f)),
                new myVertex(new Vector3(0.5f, -0.5f, 0.0f)),
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(4 * myVertex.SizeInBytes), vertices, BufferUsageHint.StaticDraw); 
        protected override void OnRenderFrame(FrameEventArgs e)
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.VertexPointer(3, VertexPointerType.Float, 0, 0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
            GL.DrawArrays(BeginMode.Quads, 0, 4);