示例#1
0
func (v *VBO) DeleteVBO() {
	if v.vboVerts != 0 {
		gl.DeleteBuffers(1, &v.vboVerts)
	}
	if v.vboIndices != 0 {
		gl.DeleteBuffers(1, &v.vboIndices)
	}
	if v.vao != 0 {
		gl.DeleteVertexArrays(1, &v.vao)
	}
}
示例#2
0
func (renderer *Renderer) Loop() {

	defer glog.Flush()

	if err := glfw.Init(); err != nil {
		glog.Fatalln("GLFW failed to initialize:", err)
		glog.Info("GLFW failed to init")
	}

	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 2)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	glfw.WindowHint(glfw.Resizable, glfw.False)

	window, windowError := glfw.CreateWindow(800, 600, "OpenGL", nil, nil)

	if windowError != nil {
		glog.Info("oops")
		panic(windowError)
	}
	glog.Info("Buffer")
	defer func() {
		window.Destroy()
		glfw.Terminate()
		glog.Info("ending")
		renderer.ended = true
		//system_end <- true
	}()

	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	renderer.keyCallback = func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
		glog.Infof("key: %v, scancode: %v, action: %v, mods: %v", key, scancode, action, mods)
	}

	window.SetKeyCallback(renderer.keyCallback)

	//<-system_start
	renderer.started = true
	//system_started <- true
	gl.ClearDepth(1.0)

	var vboID uint32
	gl.GenBuffers(1, &vboID)
	var vertexData = []float32{
		1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1,
	}
	gl.BindBuffer(gl.ARRAY_BUFFER, vboID)
	gl.BufferData(gl.ARRAY_BUFFER, len(vertexData)*4, gl.Ptr(vertexData), gl.STATIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	//get shaders
	vertexShader, fragmentShader := getShaders()
	program, err := newProgram(vertexShader, fragmentShader)
	program.UseProgram()

	if err != nil {
		panic(err)
	}

	//bind attributes

	//	L:
	for !window.ShouldClose() {

		//renderer.drawGame(program)
		gl.EnableVertexAttribArray(0)
		gl.BindBuffer(gl.ARRAY_BUFFER, vboID)
		gl.VertexAttribPointer(
			0,
			3,
			gl.FLOAT,
			false,
			0,
			gl.PtrOffset(0))
		gl.DrawArrays(gl.TRIANGLES, 0, 3)
		gl.DisableVertexAttribArray(0)
		window.SwapBuffers()
		glfw.PollEvents()
	}

	if vboID != 0 {
		gl.DeleteBuffers(1, &vboID)
	}

}
示例#3
0
/* Frees the GPU memory allocated by this vertex buffer. Resets Id, Size and Elements to 0 */
func (vbo *VertexBuffer) Delete() {
    if vbo.Id != 0 {
        gl.DeleteBuffers(1, &vbo.Id)
        *vbo = VertexBuffer { }
    }
}
示例#4
0
func (glRenderer *OpenglRenderer) DestroyGeometry(geometry *renderer.Geometry) {
	gl.DeleteBuffers(1, &geometry.VboId)
	gl.DeleteBuffers(1, &geometry.IboId)
}