‘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.
You can think of the data model as a description of Python as a framework. It formalizes the interfaces of the building blocks of the language itself, such as sequences, iterators, functions, classes, context managers, and so on.
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) { return1; }
Create the point
Consider the point is 3-dimensional point at (0.0, 0.0, 0.0).
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.
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.
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.