func initScene() { halfW, halfH := float32(Width)*0.5, float32(Height)*0.5 Projection = mgl.Ortho2D(-halfW, halfW, -halfH, halfH).Mul4( mgl.Translate3D(-halfW, -halfH, 0)) ModelView = mgl.Ident4f().Mul4(mgl.Scale3D(100, 100, 0)) MVP <- Projection.Mul4(ModelView) gl.Disable(gl.DEPTH_TEST) gl.DepthMask(false) program := Program(FragmentShader(fsh), VertexShader(vsh)) gl.UseProgram(uint(program)) uMVP = gl.GetUniformLocation(program, "uMVP") attrPos = gl.GetAttribLocation(program, "pos") attrColor = gl.GetAttribLocation(program, "color") gl.EnableVertexAttribArray(uint(attrPos)) gl.EnableVertexAttribArray(uint(attrColor)) gl.ClearColor(0.0, 0.0, 0.0, 1.0) gl.VertexAttribPointer(uint(attrPos), 2, gl.FLOAT, false, 0, uintptr(gl.Void(&POSITION[0]))) gl.VertexAttribPointer(uint(attrColor), 4, gl.FLOAT, false, 0, uintptr(gl.Void(&COLOR[0]))) }
func draw(width, height int) { gl.Viewport(0, 0, width, height) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.BindBuffer(gl.ARRAY_BUFFER, verticesArrayBuffer) gl.VertexAttribPointer(attrPos, 4, gl.FLOAT, false, 0, 0) gl.BindBuffer(gl.ARRAY_BUFFER, colorsArrayBuffer) gl.VertexAttribPointer(attrColor, 4, gl.FLOAT, false, 0, 0) gl.DrawArrays(gl.TRIANGLES, 0, 3) gl.Flush() gl.Finish() }
func draw(width, height int) { gl.Viewport(0, 0, width, height) gl.Clear(gl.COLOR_BUFFER_BIT) gl.BindBuffer(gl.ARRAY_BUFFER, verticesArrayBuffer) gl.VertexAttribPointer(attrPos, 4, gl.FLOAT, false, 6*4, 0) // bind texture - FIX size of vertex gl.VertexAttribPointer(attrTexIn, 2, gl.FLOAT, false, 6*4, 4*4) gl.ActiveTexture(gl.TEXTURE0) gl.BindTexture(gl.TEXTURE_2D, textureBuffer) gl.Uniform1i(unifTexture, 0) gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4) gl.Flush() gl.Finish() }