/// <summary> /// Creates vertex data based on the file provided. Sets up VBO and VAO. /// Throws exceptions if the file cannot be loaded or the VBO cannot be /// created. Finds the bounds of the figure. Sets the figures /// coordinates to it's "restore" position. /// </summary> public void Load() { VertexDataList vdl = new VertexDataList(); bool correctFile = vdl.LoadDataFromVRML(fileString); if (!correctFile) throw new Exception("Could not load data from file."); verts = vdl.VertexArray(); GL.GenBuffers(1, out vboHandle); GL.BindBuffer(BufferTarget.ArrayBuffer, vboHandle); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * BlittableValueType.StrideOf(verts)), verts, BufferUsageHint.StaticDraw); int size; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size); if (verts.Length * BlittableValueType.StrideOf(verts) != size) throw new Exception("VBO creation failed."); GL.GenVertexArrays(1, out vaoHandle); GL.BindVertexArray(vaoHandle); int vertColorLoc = GL.GetAttribLocation(ShaderLoader.Instance.ProgramHandle, "VertexColor"); GL.EnableVertexAttribArray(vertColorLoc); GL.VertexAttribPointer(vertColorLoc, 3, VertexAttribPointerType.Float, true, 36, 12); int vertPosLoc = GL.GetAttribLocation(ShaderLoader.Instance.ProgramHandle, "VertexPosition"); GL.EnableVertexAttribArray(vertPosLoc); GL.VertexAttribPointer(vertPosLoc, 3, VertexAttribPointerType.Float, true, 36, 0); int vertNormLoc = GL.GetAttribLocation(ShaderLoader.Instance.ProgramHandle, "VertexNormal"); GL.EnableVertexAttribArray(vertNormLoc); GL.VertexAttribPointer(vertNormLoc, 3, VertexAttribPointerType.Float, true, 36, 24); GL.BindVertexArray(0); FindBounds(); Restore(); }