There’s quite a lot going on in this function so let’s break it down. Points := make(float32, len(square), len(square)) Now that the we understand the shape and representation of the matrix we’re creating, let’s have a look at newCell which we use to actually populate the matrix: If we were to define rows and columns each equal to two, we’d create the following matrix: We’re creating a slice that is equal in length to the number of rows on the grid, and each of these slices contains a slice of cells, equal in length to the number of columns. Here we create a multi-dimensional slice to represent our game’s board, and populate each element of the matrix with a cell using a new function called newCell which we’ll write in just a moment.īefore moving on, let’s take a moment to visualize what makeCells is creating. Now let’s add a function to create the grid: We’re also going to want two more constants that define the size and shape of our grid: The cell contains a drawable which is a square Vertex Array Object just like the one we created above, and an X and Y coordinate to dictate where on the grid this cell resides. Now that we can draw one square, how about 100 of them? Let’s create a cell struct to represent each unit of our grid so that we can be flexible in the number of squares we draw: Great, now we have the ability to draw a square! OpenGL isn’t so tough after all, is it? Draw a Grid of Squares covering the Window What we’ve done is move the X-coordinate of the top vertex to the left ( -0.5), giving us a triangle like so: Open up main.go and change the triangle definition to look like so: Let’s get started! Make a Square out of Trianglesīefore we can make a square, let’s turn our triangle into a right-angle. Welcome back to the OpenGL & Go Tutorial! If you haven’t gone through Part 1 you’ll definitely want to take a step back and check it out.Īt this point you should be the proud creator of a magnificent white triangle, but we’re not in the business of using triangles as our game unit so it’s time to turn the triangle into a square, and then we’ll make an entire grid of them.
#THE GAME CREATORS SELECTING OPENGL FULL#
The full source code of the tutorial is available on GitHub. Part 1: Hello, OpenGL | Part 2: Drawing the Game Board | Part 3: Implementing the Game Related Posts Accessing the Goodreads API with Go Introducing modoc, a Lightweight Framework for Large Markdown Documents OpenGL & Go Tutorial Part 3: Implementing the Game OpenGL & Go Tutorial Part 1: Hello, OpenGL awsprof: Set Access and Secret Key Environment Variables by Profile Name