// initScene is one time initialization that creates a single VAO func (tb *tbtag) initScene() { tb.mvp32 = &render.M4{} tb.initData() // Bind the OpenGL calls and dump some version info. gl.Init() fmt.Printf("%s %s", gl.GetString(gl.RENDERER), gl.GetString(gl.VERSION)) fmt.Printf(" GLSL %s\n", gl.GetString(gl.SHADING_LANGUAGE_VERSION)) // Gather the one scene into this one vertex array object. gl.GenVertexArrays(1, &tb.vao) gl.BindVertexArray(tb.vao) // vertex data. var vbuff uint32 gl.GenBuffers(1, &vbuff) gl.BindBuffer(gl.ARRAY_BUFFER, vbuff) gl.BufferData(gl.ARRAY_BUFFER, int64(len(tb.points)*4), gl.Pointer(&(tb.points[0])), gl.STATIC_DRAW) var vattr uint32 = 0 gl.VertexAttribPointer(vattr, 4, gl.FLOAT, false, 0, 0) gl.EnableVertexAttribArray(vattr) // texture coordatinates var tbuff uint32 gl.GenBuffers(1, &tbuff) gl.BindBuffer(gl.ARRAY_BUFFER, tbuff) gl.BufferData(gl.ARRAY_BUFFER, int64(len(tb.tcoords)*4), gl.Pointer(&(tb.tcoords[0])), gl.STATIC_DRAW) var tattr uint32 = 2 gl.VertexAttribPointer(tattr, 2, gl.FLOAT, false, 0, 0) gl.EnableVertexAttribArray(tattr) // faces data. var ebuff uint32 gl.GenBuffers(1, &ebuff) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebuff) gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, int64(len(tb.faces)), gl.Pointer(&(tb.faces[0])), gl.STATIC_DRAW) // create texture and shaders after all the data has been set up. tb.initTexture() tb.initShader() tb.ortho = lin.NewOrtho(0, 4, 0, 4, 0, 10) // set some state that doesn't need to change during drawing. gl.ClearColor(0.0, 0.0, 0.0, 1.0) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.TEXTURE_2D) }
// initScene is one time initialization that creates a single VAO func (sf *sftag) initScene() { sf.mvp32 = &render.M4{} sf.sTime = time.Now() sf.initData() // Bind the OpenGL calls and dump some version info. gl.Init() fmt.Printf("%s %s", gl.GetString(gl.RENDERER), gl.GetString(gl.VERSION)) fmt.Printf(" GLSL %s\n", gl.GetString(gl.SHADING_LANGUAGE_VERSION)) gl.GenVertexArrays(1, &sf.vao) gl.BindVertexArray(sf.vao) // vertex data. var vbuff uint32 gl.GenBuffers(1, &vbuff) gl.BindBuffer(gl.ARRAY_BUFFER, vbuff) gl.BufferData(gl.ARRAY_BUFFER, int64(len(sf.points)*4), gl.Pointer(&(sf.points[0])), gl.STATIC_DRAW) var vattr uint32 = 0 gl.VertexAttribPointer(vattr, 4, gl.FLOAT, false, 0, 0) gl.EnableVertexAttribArray(vattr) // faces data. var ebuff uint32 gl.GenBuffers(1, &ebuff) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebuff) gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, int64(len(sf.faces)), gl.Pointer(&(sf.faces[0])), gl.STATIC_DRAW) // create texture and shaders after all the data has been set up. shader := &data.Shader{} loader := data.NewLoader() loader.Load("fire", &shader) sf.shaders = gl.CreateProgram() if err := gl.BindProgram(sf.shaders, shader.Vsh, shader.Fsh); err != nil { fmt.Printf("Failed to create program: %s\n", err) } sf.mvpref = gl.GetUniformLocation(sf.shaders, "Mvpm") sf.gTime = gl.GetUniformLocation(sf.shaders, "time") sf.sizes = gl.GetUniformLocation(sf.shaders, "resolution") sf.ortho = lin.NewOrtho(0, 4, 0, 4, 0, 10) // set some state that doesn't need to change during drawing. gl.ClearColor(0.0, 0.0, 0.0, 1.0) }