public VAO(OpenGL gl, IShaderProgram program, VBO vbo) { _gl = gl; _program = program; VBO = vbo; var buffers = new uint[1]; gl.GenVertexArrays(1, buffers); Handle = buffers[0]; using (new Bind(program)) using (new Bind(this)) using (new Bind(vbo)) { var stride = Vect3f.SizeInBytes * 2 + Vect4f.SizeInBytes; gl.EnableVertexAttribArray(0); gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, true, stride, IntPtr.Zero); gl.BindAttribLocation(program.Handle, 0, "vert_position"); gl.EnableVertexAttribArray(1); gl.VertexAttribPointer(1, 3, OpenGL.GL_FLOAT, true, stride, new IntPtr(Vect3f.SizeInBytes)); gl.BindAttribLocation(program.Handle, 1, "vert_normal"); gl.EnableVertexAttribArray(2); gl.VertexAttribPointer(2, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(Vect3f.SizeInBytes * 2)); gl.BindAttribLocation(program.Handle, 2, "vert_colour"); } }
public Mesh(OpenGL gl, MeshType type) { this.gl = gl; this.bufferCount = 0; Type = type; uint[] arrs = new uint[1]; gl.GenVertexArrays(1, arrs); ID = arrs[0]; }
private void CreateVertexArrayObject(OpenGL gl, RenderMode renderMode) { if (this.positionBuffer == null || this.colorBuffer == null) { return; } this.vertexArrayObject = new uint[1]; gl.GenVertexArrays(1, this.vertexArrayObject); gl.BindVertexArray(this.vertexArrayObject[0]); // prepare positions { int location = shaderProgram.GetAttributeLocation(gl, in_Position); ATTRIB_INDEX_POSITION = (uint)location; gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, positionBuffer[0]); gl.VertexAttribPointer(ATTRIB_INDEX_POSITION, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero); gl.EnableVertexAttribArray(ATTRIB_INDEX_POSITION); } // prepare colors { int location = shaderProgram.GetAttributeLocation(gl, in_uv); ATTRIB_INDEX_UV = (uint)location; gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, colorBuffer[0]); gl.VertexAttribPointer(ATTRIB_INDEX_UV, 1, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero); gl.EnableVertexAttribArray(ATTRIB_INDEX_UV); } gl.BindVertexArray(0); }
public void PrepareNMVAO(OpenGL gl, NormalMaterialProgram program) { var vertArrIds = new uint[1]; gl.GenVertexArrays(1, vertArrIds); VaoNM = vertArrIds[0]; gl.BindVertexArray(VaoNM); BindNMVBOs(gl, program); gl.EnableVertexAttribArray(0); gl.BindVertexArray(0); }
public void PrepareHTVAO(OpenGL gl, HitTestProgram program) { var vertArrIds = new uint[1]; gl.GenVertexArrays(1, vertArrIds); VaoHT = vertArrIds[0]; gl.BindVertexArray(VaoHT); BindHTVBOs(gl, program); gl.EnableVertexAttribArray(0); gl.BindVertexArray(0); }
private void initGLObjects(OpenGL gl, out uint vaoHandle, out uint programHandle) { uint[] vaos = new uint[1]; gl.GenVertexArrays(1, vaos); vaoHandle = vaos[0]; programHandle = gl.CreateProgram(); }
public void PrepareVAO(OpenGL gl, LinesProgram program) { var vertArrIds = new uint[1]; gl.GenVertexArrays(1, vertArrIds); Vao = vertArrIds[0]; gl.BindVertexArray(Vao); BindVBOs(gl, program); gl.EnableVertexAttribArray(0); gl.BindVertexArray(0); }
public VAO(OpenGL gl) { _gl = gl; _gl.GenVertexArrays(2, _vao); }
private void PlaySound() { try { gl.GenVertexArrays(1, vao); gl.BindVertexArray(vao[0]); gl.GenBuffers(1, vbo); float[] vertices = new float[] { -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f }; gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vbo[0]); unsafe { fixed(float *verts = vertices) { var ptr = new IntPtr(verts); // fill the buffer to the currently binded buffer gl.BufferData(OpenGL.GL_ARRAY_BUFFER, vertices.Length * sizeof(float), ptr, OpenGL.GL_STATIC_DRAW); } } // Create the shader program. var vertexShaderSource = ManifestResourceLoader.LoadTextFile("SoundShader.vert"); var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("SoundShader.frag"); vertexShader = gl.CreateShader(OpenGL.GL_VERTEX_SHADER); gl.ShaderSource(vertexShader, vertexShaderSource); gl.CompileShader(vertexShader); // Create and compile the fragment shader fragmentShader = gl.CreateShader(OpenGL.GL_FRAGMENT_SHADER); gl.ShaderSource(fragmentShader, fragmentShaderSource); gl.CompileShader(fragmentShader); // Link the vertex and fragment shader into a shader program shaderProgram = gl.CreateProgram(); gl.AttachShader(shaderProgram, vertexShader); gl.AttachShader(shaderProgram, fragmentShader); gl.BindFragDataLocation(shaderProgram, (uint)0, "gl_FragColor"); gl.LinkProgram(shaderProgram); int[] infoLength = new int[] { 0 }; int bufSize = infoLength[0]; // Get the compile info. StringBuilder il = new StringBuilder(bufSize); gl.GetProgramInfoLog(shaderProgram, bufSize, IntPtr.Zero, il); gl.UseProgram(shaderProgram); posAttrib = gl.GetAttribLocation(shaderProgram, "position"); gl.EnableVertexAttribArray((uint)posAttrib); gl.VertexAttribPointer((uint)posAttrib, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0)); timeLoc = gl.GetUniformLocation(shaderProgram, "iGlobalTime"); sampleLoc = gl.GetUniformLocation(shaderProgram, "Spectrum"); waveLoc = gl.GetUniformLocation(shaderProgram, "Wavedata"); int resLoc = gl.GetUniformLocation(shaderProgram, "iResolution"); gl.Uniform3(resLoc, (float)this.openGLControl1.Width, (float)this.openGLControl1.Height, (float)(this.openGLControl1.Width * this.openGLControl1.Height)); Thread thread = new Thread(() => PlaySoundT(((USound)selectedObject).SoundBuffer)); thread.Start(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace.ToString()); } }