コード例 #1
0
ファイル: main.go プロジェクト: pdelbarba/gl3-examples
		matrix = matrix.Multiply(math3d.MakeZRotationMatrix(angle)).Transposed()
		display()
	}

	// Free resources
	free()

	runtime.UnlockOSThread()
}

func free() {
	program.Delete()
	vboTriangle.Delete()
}

var matrix = math3d.MakeIdentity()

func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	program.Use()

	uniformMTransform.UniformMatrix4fv(1, false, matrix)

	vboTriangle.Bind(gl.ARRAY_BUFFER)

	attributeCoord3d.EnableArray()
	// Describe our vertices array to OpenGL (it can't guess its format automatically)
コード例 #2
0
ファイル: main.go プロジェクト: pdelbarba/gl3-examples
func main() {
	// We need to lock the goroutine to one thread due time.Ticker
	runtime.LockOSThread()

	var err os.Error
	err = glfw.Init()
	if err != nil {
		fmt.Printf("GLFW: %s\n", err)
		return
	}
	defer glfw.Terminate()

	// You could probably change the required versions down
	glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3)
	glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3)
	glfw.OpenWindowHint(glfw.OpenGLProfile, 1)

	// Open Window with 8 bit Alpha
	err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 8, 0, glfw.Windowed)
	if err != nil {
		fmt.Printf("GLFW: %s\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetWindowTitle(WindowTitle)
	glfw.SetWindowSizeCallback(onResize)

	major, minor, rev := glfw.GLVersion()
	if major < 3 {
		fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev)
		fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.")
	}

	initStatus := gl.Init() // Init glew
	if initStatus != 0 {
		fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus)
	}

	// Enable transparency in OpenGL
	gl.Enable(gl.BLEND)
	gl.Enable(gl.DEPTH_TEST)
	//gl.DepthFunc(gl.LESS)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	initResources()

	// We are limiting the calls to display() (frames per second) to 60. This prevents the 100% cpu usage.
	ticker := time.NewTicker(int64(second) / 60) // max 60 fps
	for {
		<-ticker.C
		angle := float32(glfw.Time())
		anim := math3d.MakeYRotationMatrix(angle)
		model := math3d.MakeTranslationMatrix(0, 0, -4)
		view := math3d.MakeLookAtMatrix(math3d.Vector3{0, 2, 0}, math3d.Vector3{0, 0, -4}, math3d.Vector3{0, 1, 0})
		projection := math3d.MakePerspectiveMatrix(45, float32(ScreenWidth)/float32(ScreenHeight), 0.1, 10.0)
		matrix = math3d.MakeIdentity().Multiply(projection).Multiply(view).Multiply(model).Multiply(anim)
		program.Use()
		uniformMTransform.UniformMatrix4fv(1, false, matrix.Transposed())
		display()
	}

	// Free resources
	free()

	runtime.UnlockOSThread()
}