Container sequences: can hold different types. They contain references to the objects.

list, tuple, collections.deque

Flat sequences: can hold one type. They physically sotre the value.

str, bytes, bytearray, memoryview, array.array

Another way of grouping:

Mutable seuqences:

list, byte, array.array, collections.deque and memoryview

Immutable sequences:

tuple, str, bytes

Read more »

‘Tinny Ray Tracer’ introduces the ray tracing under 300 lines code. It was a great fun to follow the instructions and made the renderer. We learn the algorithm layer by layer, with one color at beginning, then with diffusion, reflection and refraction at last.

This article add some extended notes and resources together for a thorough understanding of geometric calculation along with ray tracing.

Read more »

Add GLEW

GLEW

The OpenGL Extension Wrangler Library (GLEW) is a cross-platform open-source C/C++ extension loading library. GLEW provides efficient run-time mechanisms for determining which OpenGL extensions are supported on the target platform.

Download the library from the above link and add it to your project.

Note: If you use the static library of GLEW - glew32s.lib, you have to set the GLEW_STATIC in the preprocessor. Otherwise it won’t work

Point

Now all is set, let’s draw one single point in the window to get a sense of how OpenGL works.

Include your library

#include <GL/glew.h>

Initialize GLEW

if (glewInit() != GLEW_OK)
{
return 1;
}

Create the point

Consider the point is 3-dimensional point at (0.0, 0.0, 0.0).

static const GLfloat vertices[] = {
0.0f, 0.0f, 0.0f,
}

Generate a Vertex Buffer Object

Vertex Buffer Object is the way you send your data to GPU. We store our vertices data in the buffer and submit the buffer to GPU.

GLuint VBO;
glGenBuffers(1, &VBO)
// the first parameter is the how many Vertex Buffer Objects you want to generate. The second parameter is the buffer.

Bind buffer

The buffer is generated in a generic way. It doesn’t know what type of the data is. It’s the job of the next function to tell the buffer what we intend to do with the buffer.

glBindBuffer(GL_ARRAY_BUFFER, VBO);

// Tell GPU the data to store in it is an array of vertices.

Bind data

Now we are going to bind our data to the buffer.

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

Enable Vertex Attributes

Following code is to write in the main loop.

By default of the pipeline, for vertices without shader the index we are referring to is 0.

glEnableVertexAttribArray(0);

Interpretation of the data

Tell GPU how to interpret the data in buffer.

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

The first parameter: index of the attribute The second parameter: number of components(3 for X, Y and Z) The third parameter: data type of each component The forth parameter: weather to be normalized before it is used in the pipeline. The fifth parameter: stride The sixth parameter: array buffer offset.

Draw the Point

glDrawArrays(GL_POINTS, 0, 1);

Now you should see a point in the middle of the window.

Draw the triangle

replace the data point with

static const GLfloat vertices[] = {
0.0f, 1.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
};

And the draw function.

glDrawArrays(GL_TRIANGLES, 0, 3);

Then you should see

Create Project

Create am empty visual C++ project in Visual Studio(Get Visual Studio).

Add GLFW

To write a game engine, we start with the window at first.

OpenGL doesn’t concern about the management of windows and inputs. Therefor we use GLFW to deal with it.

GLFW is an Open Source, multi-platform library for OpenGL, which provides a simple API for creating window and receiving input.

Following the steps to setup GLFW library.

add dependencies

Create a “Dependencies” directory in the root folder of the project.

Download GLFW and put the library in “Dependencies”.

include

Add the include directory in the property.

library

Add the library directory in the property.

Main function

Create a main.cpp in the root directory.

#include <iostream>
#include <GLFW/glfw3.h>

int main()
{
if(!glwInit())
std::cout << "Failed the initialize GLFW" << std::endl;
else
std::cout << "Success!" << std::endl;

system("PAUSE");
return 0;
}

Run it to see if the GLFW works as we expect.

If it succeed, we can implement our first window.

#include <iostream>
#include <GLFW/glfw3.h>

int main()
{
if (!glfwInit())
return 1;

//create a window with 800px width and 600px height, name it as what you like
GLFWwindow *window = glfwCreateWindow(800, 600, "MyEngine", NULL, NULL);

if (!window)
{
std::cout << "Failed to initialize GLFW " << std::endl;
return 1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
glfwSwapBuffers(window);
}
glfwTerminate();
system("PAUSE");
return 0;
}

Now you should see a window.

In the next chapter we are going to include the OpenGL Extension Wrangler Library and draw our first triangle.

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment