3D data files can get very large. Basically, the more polygons (vertices) there are, the larger they get. But especially on the web, large files take a long time to download, which isn't practical. So this time, we'll reduce the file size with Draco, a 3D data compression program developed by Google. Draco can make files very small. We'll actually compress an OBJ file with Draco.
In recent years, techniques for doing CG on the web with JavaScript have advanced greatly, and it has become possible to develop web apps that use AR, VR, and more in the browser. The problem, however, is the file size of 3D models. 3D models such as glTF are very large for the web and take a long time to download. So we'll reduce the file size by compressing them with Draco, an open-source 3D data compression method developed by Google and adopted by glTF as an extension.
This time, I'll explain both VAOs and GLSL. A VAO is a feature that lets you write VBOs (Vertex Buffer Objects), which have existed since OpenGL 2.x, more concisely. Starting with 2.x, VBOs were introduced, which send vertex data to the GPU in advance before drawing. A VAO encapsulates multiple VBOs.
This is more groundwork, but this time we'll specify the OpenGL version and display a window. OpenGL versions are very confusing, but thankfully, recent versions have become much less so. Using GLFW in Python, we'll specify OpenGL 4.0 for the context and display a window.
You can use modern OpenGL in Python. I picked up my pen to share how moving that is. In this series, I'll explain modern OpenGL features such as VAOs using Python, with code, as clearly as I can. Since this is part 1, it mainly covers an introduction and setting up the environment, and at the end we'll write a program that displays the OpenGL version your PC supports. By the way, I'll use GLFW, which lets you configure things like the context, rather than GLUT.
OpenGL and GLSL provide a mechanism called VBO for sending data to the GPU more efficiently. So far, we've been sending data to GLSL with functions such as glBegin() and glVertex3f(). As I mentioned before, glBegin() and the like have already been removed or deprecated, and drawing with them is very slow. Here we send only the vertices to GLSL as an attribute variable, but you can send normals, colors, UVs, and other data the same way. With what we've covered so far, you should be able to write fairly efficient programs. By the way, there's also the term VAO (Vertex Array Object), which is very confusing, but it isn't another kind of VBO or an alternative to VBOs: it's a way to encapsulate VBOs.
When rendering with OpenGL, you use matrix calculations to move the objects being rendered and the camera. You could write the matrix calculations yourself in C++, but GLM (OpenGL Mathematics) already exists to help with them, so let's use it.
How to render with OpenGL 2.1 and GLSL. We draw a polygon using GLSL sample code. The whole sequence of steps OpenGL goes through to draw a world is called the pipeline. The vertex shader runs once per vertex, and the fragment shader runs once per pixel.
For drawing with OpenGL, GLUT (or FreeGLUT) would be fine, but GLUT is a bit unintuitive, makes contexts harder to understand, and is no longer maintained (presumably for good reason), so I'll use GLFW. GLFW is still maintained and has more features.