raderblob's picture

transfering to vbo

Hello I am new to opentk, a few days ago i started work on a project build in vb.net around cubes using a cube class I created but to render them I used gl.begin and gl.end and I soon found out that it was slowing down my program so I found out about rendering with vbo.

I think I understand the principle(I do admit there are some things about it that i do not understand) and have been trying for a while now to transfer my rendering code to vbo.

I think that i would be able to do it if I changed to using an array of vertices but I would like to keep using my cube class because all the rest of the program relies on it for collision detection etc..
Here is the code i use to render all my cubes:

 For i = 0 To UBound(cubes)
            If delcubes(i) = 1 And cubes(i).hbl.RotateX(vturn).Z > -3 And cubes(i).hbl.RotateY(rotss).Z < renderdistance And cubes(i).hbl.RotateY(rotss).Z > -renderdistance And cubes(i).hbl.RotateY(rotss).X < renderdistance And cubes(i).hbl.RotateY(rotss).X > -renderdistance And cubes(i).hbl.RotateY(rotss).Y < renderdistance And cubes(i).hbl.RotateY(rotss).Y > -renderdistance Then
 
                If Array.IndexOf(textures, cubes(i).texture) <> 8 And Array.IndexOf(textures, cubes(i).texture) <> 2 Then
                    GL.BindTexture(TextureTarget.Texture2D, cubes(i).texture)
 
                    GL.Begin(BeginMode.Quads)
 
                    If i = selectedcube Then
                        GL.Color3(Color.Red)
                    Else
                        GL.Color3(Color.White)
                    End If
                    GL.TexCoord2(0, 0)
                    GL.Vertex3(cubes(i).hbl.RotateX(vturn).X, cubes(i).hbl.RotateX(vturn).Y, cubes(i).hbl.RotateX(vturn).Z)
                    GL.TexCoord2(1, 0)
                    GL.Vertex3(cubes(i).hbr.RotateX(vturn).X, cubes(i).hbr.RotateX(vturn).Y, cubes(i).hbr.RotateX(vturn).Z)
                    GL.TexCoord2(1, 1)
                    GL.Vertex3(cubes(i).hfr.RotateX(vturn).X, cubes(i).hfr.RotateX(vturn).Y, cubes(i).hfr.RotateX(vturn).Z)
                    GL.TexCoord2(0, 1)
                    GL.Vertex3(cubes(i).hfl.RotateX(vturn).X, cubes(i).hfl.RotateX(vturn).Y, cubes(i).hfl.RotateX(vturn).Z)
 
                    GL.TexCoord2(1, 0)
                    GL.Vertex3(cubes(i).hbl.RotateX(vturn).X, cubes(i).hbl.RotateX(vturn).Y, cubes(i).hbl.RotateX(vturn).Z)
                    GL.TexCoord2(1, 1)
                    GL.Vertex3(cubes(i).bbl.RotateX(vturn).X, cubes(i).bbl.RotateX(vturn).Y, cubes(i).bbl.RotateX(vturn).Z)
                    GL.TexCoord2(0, 1)
                    GL.Vertex3(cubes(i).bfl.RotateX(vturn).X, cubes(i).bfl.RotateX(vturn).Y, cubes(i).bfl.RotateX(vturn).Z)
                    GL.TexCoord2(0, 0)
                    GL.Vertex3(cubes(i).hfl.RotateX(vturn).X, cubes(i).hfl.RotateX(vturn).Y, cubes(i).hfl.RotateX(vturn).Z)
 
                    GL.TexCoord2(0, 0)
                    GL.Vertex3(cubes(i).hbl.RotateX(vturn).X, cubes(i).hbl.RotateX(vturn).Y, cubes(i).hbl.RotateX(vturn).Z)
                    GL.TexCoord2(1, 0)
                    GL.Vertex3(cubes(i).hbr.RotateX(vturn).X, cubes(i).hbr.RotateX(vturn).Y, cubes(i).hbr.RotateX(vturn).Z)
                    GL.TexCoord2(1, 1)
                    GL.Vertex3(cubes(i).bbr.RotateX(vturn).X, cubes(i).bbr.RotateX(vturn).Y, cubes(i).bbr.RotateX(vturn).Z)
                    GL.TexCoord2(0, 1)
                    GL.Vertex3(cubes(i).bbl.RotateX(vturn).X, cubes(i).bbl.RotateX(vturn).Y, cubes(i).bbl.RotateX(vturn).Z)
 
                    GL.TexCoord2(1, 0)
                    GL.Vertex3(cubes(i).hbr.RotateX(vturn).X, cubes(i).hbr.RotateX(vturn).Y, cubes(i).hbr.RotateX(vturn).Z)
                    GL.TexCoord2(1, 1)
                    GL.Vertex3(cubes(i).bbr.RotateX(vturn).X, cubes(i).bbr.RotateX(vturn).Y, cubes(i).bbr.RotateX(vturn).Z)
                    GL.TexCoord2(0, 1)
                    GL.Vertex3(cubes(i).bfr.RotateX(vturn).X, cubes(i).bfr.RotateX(vturn).Y, cubes(i).bfr.RotateX(vturn).Z)
                    GL.TexCoord2(0, 0)
                    GL.Vertex3(cubes(i).hfr.RotateX(vturn).X, cubes(i).hfr.RotateX(vturn).Y, cubes(i).hfr.RotateX(vturn).Z)
 
                    GL.TexCoord2(0, 0)
                    GL.Vertex3(cubes(i).hfl.RotateX(vturn).X, cubes(i).hfl.RotateX(vturn).Y, cubes(i).hfl.RotateX(vturn).Z)
                    GL.TexCoord2(1, 0)
                    GL.Vertex3(cubes(i).hfr.RotateX(vturn).X, cubes(i).hfr.RotateX(vturn).Y, cubes(i).hfr.RotateX(vturn).Z)
                    GL.TexCoord2(1, 1)
                    GL.Vertex3(cubes(i).bfr.RotateX(vturn).X, cubes(i).bfr.RotateX(vturn).Y, cubes(i).bfr.RotateX(vturn).Z)
                    GL.TexCoord2(0, 1)
                    GL.Vertex3(cubes(i).bfl.RotateX(vturn).X, cubes(i).bfl.RotateX(vturn).Y, cubes(i).bfl.RotateX(vturn).Z)
 
                    GL.TexCoord2(0, 0)
                    GL.Vertex3(cubes(i).bfl.RotateX(vturn).X, cubes(i).bfl.RotateX(vturn).Y, cubes(i).bfl.RotateX(vturn).Z)
                    GL.TexCoord2(1, 0)
                    GL.Vertex3(cubes(i).bfr.RotateX(vturn).X, cubes(i).bfr.RotateX(vturn).Y, cubes(i).bfr.RotateX(vturn).Z)
                    GL.TexCoord2(1, 1)
                    GL.Vertex3(cubes(i).bbr.RotateX(vturn).X, cubes(i).bbr.RotateX(vturn).Y, cubes(i).bbr.RotateX(vturn).Z)
                    GL.TexCoord2(0, 1)
                    GL.Vertex3(cubes(i).bbl.RotateX(vturn).X, cubes(i).bbl.RotateX(vturn).Y, cubes(i).bbl.RotateX(vturn).Z)
 
                    GL.End()
                End If
            End If
 
        Next

Thank you for any suggestion anybody may have, and if any more information about my program is required I would be pleased to give it.