Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Plotting Vertex arrays in OpenTK

  1. #1
    Newbie Newbie
    Join Date
    Feb 2018
    Posts
    1

    Plotting Vertex arrays in OpenTK

    I currently have a vertex array of Vector3's and I am trying to get them to plot on screen The array grows by around 256 points every second but as I redraw my OpenGL screen the array I get huge data gaps on screen and when I look at the array all of the data is there.
    Code is below

    I am using OpenTK in VB.net

    Sructure of my data
    Code :
        Structure VERTEX
            Public position As Vector3
            Public colour As Vector4
       End Structure


    I have a for loop in the sub as well and it is doing the same thing.
    Code :
        Public Sub drawGLWindow(glcontrol As GLControl, camera As Camera, PointList As List(Of BEAMLAYOUT), boundries As LoadedBoundries)
            VERTEXSizeinBytes = Vector3.SizeInBytes + Vector4.SizeInBytes
            GL.Clear(ClearBufferMask.ColorBufferBit)
            GL.Clear(ClearBufferMask.DepthBufferBit)
            Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.0, (glcontrol.Width / glcontrol.Height), 5, 5000)
            GL.MatrixMode(MatrixMode.Projection)
            GL.LoadIdentity()
            GL.LoadMatrix(perspective)
            'Load Camera
            GL.MatrixMode(MatrixMode.Modelview)
            GL.LoadIdentity()
            Dim lookat As Matrix4
            With camera
                lookat = Matrix4.LookAt(.eye.X, .eye.Y, .eye.Z, .target.X, .target.Y, .target.Z, .up.X, .up.Y, .up.Z)
            End With
            GL.LoadMatrix(lookat)
            'Enable correct Z Drawings
            GL.Enable(EnableCap.DepthTest)
            'Enable correct Z Drawings
            GL.DepthFunc(DepthFunction.Less)
            GL.Viewport(0, 0, glcontrol.Width, glcontrol.Height) 'Size of window
     
            GL.Begin(PrimitiveType.Points)
            GL.Color3(Color.Red)
            GL.PointSize(22)
            GL.Begin(PrimitiveType.Points)
            GL.Vertex3(0, 0, 0)
            GL.End()
     
     
            GL.PointSize(3)
            If gdblSurveyPoints Is Nothing Then Exit Sub
     
            'For i = 0 To gdblSurveyPoints.Count - 1
            '    Dim colour As Color = ColourChooser(gdblSurveyPoints(i).Y)
            '    GL.Begin(PrimitiveType.Points)
            '    GL.Color3(colour)
            '    GL.Vertex3(gdblSurveyPoints(i))
            '    GL.End()
            'Next
     
     
            Try
                If gvctSurveyVerticies Is Nothing Then Exit Sub
                VBO = GL.GenBuffer()
                GL.BindBuffer(BufferTarget.ArrayBuffer, VBO)
                GL.EnableClientState(ArrayCap.VertexArray)
                GL.EnableClientState(ArrayCap.ColorArray)
                GL.BufferData(BufferTarget.ArrayBuffer,
                             (VERTEXSizeinBytes * gvctSurveyVerticies.Length),
                             gvctSurveyVerticies,
                             BufferUsageHint.StaticDraw)
                GL.VertexPointer(3, VertexPointerType.Float, VERTEXSizeinBytes, 0)
                GL.ColorPointer(4, ColorPointerType.Float, VERTEXSizeinBytes, Vector3.SizeInBytes)
                GL.DrawArrays(PrimitiveType.Points, 0, gvctSurveyVerticies.Length)
            Catch ex As Exception
     
            End Try
     
            Dim lineXStart As Single = 1000000
            Dim lineXStop As Single = -1000000
            Dim lineZStart As Single = 1000000
            Dim lineZStop As Single = -1000000
            GL.Begin(PrimitiveType.Lines)
            GL.LineWidth(1)
            GL.Color3(Color.LightGray)
            Dim intSpacing As Integer = -1000000
            Do While intSpacing < 1000000
                GL.Color3(Color.LightGray)
                GL.Vertex3(intSpacing, 0, lineXStart)
                GL.Vertex3(intSpacing, 0, lineXStop)
                GL.Color3(Color.Yellow)
                GL.Vertex3(lineZStart, 0, intSpacing)
                GL.Vertex3(lineZStop, 0, intSpacing)
                intSpacing += 100
            Loop
     
            GL.End()
     
            OpenTK.Graphics.GraphicsContext.CurrentContext.SwapInterval = True 
            glcontrol.SwapBuffers() 'Takes from the 'GL' and puts into control
        End Sub

  2. #2
    Intern Contributor
    Join Date
    Dec 2016
    Location
    Ocean Shores, WA USA
    Posts
    97
    Are you adding too much in your intSpacing variable with each loop iteration?
    Jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •