GO-GL Building development environment

Source: Internet
Author: User

1. Introduction

The Go Language (Golang) is a programming language that Google introduced in 2009. Golang is an open-source language that can find its source code from GitHub. Golang is also a cross-platform language that can run on operating systems such as Windows, Linux, Mac OS X, and Plan9, and more detailed information can be found on the official website of Golang

This article mainly introduces how to use Golang to develop OpenGL program and build GO-GL development environment. When using Golang to develop OpenGL programs, it is very convenient to compare the process of a lot less configuration than C + + +.

2. Installation

The environment configured in this article can be found at the GO-GL site, which mainly includes:

    1. GO-GLFW: event handling such as render window and mouse keyboard
    2. Golang Bindings for GO-GL:OPENGL interfaces
    3. MATHGL: Mathematical Computing Library
    4. Gltext: Text Rendering Library

The installation process differs slightly depending on the operating system, and Mac OS x and Linux only need to download the latest installation package from Golang's official website. Windows differs slightly, because the GO-GLFW library relies on the GCC compiler, but not under Windows, so additional tools need to be installed.

MSYS2 can be installed under the Windows system, tested to find that the current version of GO-GLFW under 64-bit compilation error , so you can only download the Msys2 32-bit version, install the 32-bit version of GCC, The same Golang version can only install 32-bit version, with the latest version of Golang as an example (Go-1.10), under Windows need to download the content is:

    1. Go 1.10 32-bit version: Go1.10.windows-386.msi
    2. 32-bit version of Msys2:msys2-i686-20161025.exe

After the download installation is complete, MSYS2 also needs to update and install GCC as follows:

  • Open the MSYS2 command line tool and enter
  • pacman -Syu   
    • After the installation is complete, close the window. Re-open the Msys2 command line, enter
    • pacman -su   
      • Wait a while, after the update is complete, enter
      pacman -s  mingw-w64  -i686  -GCC   
      After the installation is complete, You need to set GCC to the environment variable path, where GCC is installed in Mingw32/bin in the MSYS2 installation directory, and you can view the GCC version information in cmd after the configuration is complete.


  • 3. Configure the three-party library

    3.1 GLFW Installation

    On the command line, enter

    -u github.com/go-gl/glfw/v3.2/glfw
    After successful installation, you can find the compiled GLFW library in the Go working directory ($GOPATH \pkg\windows_386\github.com\go-gl\glfw\v3.2)

3.2 GO-GL Installation

The GO-GL can be installed by selecting the version supported by OpenGL graphics, which can be installed in several different versions, introducing the appropriate version when needed, and entering

-u github.com/go-gl/gl/v4.5-core/gl

After the compilation is complete, the Golang library for OpenGL 4.5 is complete.

It is recommended that you compile v2.1 and V3.3-core and the latest version of V4.6-core three versions so that you can use Legecy OpenGL
API can also use the latest OpenGL API

3.3 Mathgl Installation

In the command line tool, enter

go get -u github.com/go-gl/mathgl/...

Wait for compilation to complete

3.4 Gltext Installation

Command Line Input

go get github.com/go-gl/gltext

4. Testing

Finally, by creating a simple GLFW window to verify that the entire installation process was successful, the code is as follows:

Create a new Helloglfw.go file

 PackageMainImport("Runtime"    "GITHUB.COM/GO-GL/GLFW/V3.2/GLFW")funcInit () {//This was needed to arrange that main () runs on main thread.    //See documentation for functions that is only allowed to being called from the main thread.Runtime. Lockosthread ()}funcMain () {err: = GLFW. Init ()ifErr! =Nil{Panic(ERR)}deferGLFW. Terminate () window, err: = GLFW. CreateWindow(640,480,"Testing",Nil,Nil)ifErr! =Nil{Panic(ERR)} Window. Makecontextcurrent () for!window. Shouldclose () {//do OpenGL stuff.Window. Swapbuffers () GLFW. Pollevents ()}}

Using the command-line tool, switch to this directory and enter

go build helloglfw.go

If you can generate a corresponding Helloglfw.exe file, the entire configuration is successful, then you can start the GO-GL journey!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.