GO-GL Building Development Environment (i)

Source: Internet
Author: User
Tags versions
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 this site Go-gl, including: GO-GLFW: Rendering window and mouse keyboard and other event processing Go-gl:opengl interface Golang binding mathgl: Math library 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), in Windows need to download the content is: Go 1.10 32-bit version: Go1.10.windows-386.msi 32-bit version of Msys2:msys2-i686-20161025.exe

After the download installation is complete, MSYS2 also needs to update and install GCC in the following steps: Open the MSYS2 command line tool and enter

Pacman-syu
After waiting for the installation to complete, close the window. Re-open the Msys2 command line and 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 Tri-Party library 3.1 GLFW installation

On the command line, enter

Go get-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

Go get-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 be installed using the latest OpenGL API 3.3 Mathgl

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

Package main

Import (
    "Runtime"
    "GITHUB.COM/GO-GL/GLFW/V3.2/GLFW"
)

func init () {
    //this is needed to arrange this main () runs on main thread.
    See documentation for functions that is only allowed to is called from the main thread.
    Runtime. Lockosthread ()
}

func main () {
    err: = GLFW. Init ()
    if err! = Nil {
        panic (err)
    }
    defer GLFW. Terminate ()

    window, err: = GLFW. CreateWindow (640, 480, "testing", nil, nil)
    if err! = 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, it means that the entire configuration is successful, and 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.