protected override void OnLoad(EventArgs e) { GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //solid = new Cube(); var data = new List<OpenGLVertex> { new OpenGLVertex {Position = new Vector3(-1, -1, 0), Colour =new Color4(0.118f, 0.118f, 0.118f, 1f).ToVector4()},//bottom left new OpenGLVertex {Position = new Vector3(1, -1, 0), Colour= new Color4(0.118f, 0.118f, 0.118f, 1f).ToVector4() }, //bottom right new OpenGLVertex {Position = new Vector3(1, 1, 0), Colour = new Color4(0.176f, 0.176f, 0.188f, 1f).ToVector4() },//top right new OpenGLVertex {Position = new Vector3(-1, 1, 0), Colour = new Color4(0.176f, 0.176f, 0.188f, 1f).ToVector4()},//top left }; _ubo = new CameraUBO(); _shader = new FlatShaderProgram(); _basicShader = new BasicShaderProgram(_ubo); _vbo = new VBO(data) { BeginMode = BeginMode.Quads }; _vao = new VAO(_shader, _vbo); var dotdata = new List<OpenGLVertex> { new OpenGLVertex {Position = new Vector3(0, 0, 0)}, new OpenGLVertex {Position = new Vector3(10, 10, 0)}, }; _dotsvbo = new VBO(dotdata) { BeginMode = BeginMode.Lines }; _dotsvao = new VAO(_basicShader, _dotsvbo); var stl = new STL("rounded_cube.stl", Color.GreenYellow); var cubedata = new List<OpenGLVertex>(); var col = stl.Color.ToVector4(); foreach (var ele in stl.Elements) { cubedata.Add(new OpenGLVertex { Position = ele.P1.ToVector3(), Normal = ele.Normal.ToVector3(), Colour = col }); cubedata.Add(new OpenGLVertex { Position = ele.P2.ToVector3(), Normal = ele.Normal.ToVector3(), Colour = col }); cubedata.Add(new OpenGLVertex { Position = ele.P3.ToVector3(), Normal = ele.Normal.ToVector3(), Colour = col }); } _geovbo = new VBO(cubedata) { BeginMode = BeginMode.Triangles }; _geovao = new VAO(_basicShader, _geovbo); var err = GL.GetError(); if (err != ErrorCode.NoError) Console.WriteLine("Error at OnLoad: " + err); }
public VAO(IShaderProgram program, VBO vbo) { _program = program; VBO = vbo; GL.GenVertexArrays(1, out _handle); using (new Bind(program)) using (new Bind(this)) using (new Bind(vbo)) { var stride = Vector3.SizeInBytes * 2 + Vector4.SizeInBytes; GL.EnableVertexAttribArray(0); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, true, stride, 0); GL.BindAttribLocation(program.Handle, 0, "vert_position"); GL.EnableVertexAttribArray(1); GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, true, stride, Vector3.SizeInBytes); GL.BindAttribLocation(program.Handle, 1, "vert_normal"); GL.EnableVertexAttribArray(2); GL.VertexAttribPointer(2, 4, VertexAttribPointerType.Float, false, stride, Vector3.SizeInBytes * 2); GL.BindAttribLocation(program.Handle, 2, "vert_colour"); } }