OpenGL

Once you have the idea of learning OpenGL, the first thing is to figure out what OpenGL is. I touched on it a little bit when I was doing my final design, but OpenGL can be used to draw STL 3D models, so OpenGL can be used to do “complex” drawings.

What is the OpenGL

OpenGL has the purpose of drawing, but it is not a Library or SDK specific implementation, by definition, OpenGL is a “specification”, only provides some conventions about drawing, that is, what functions each function provides, what parameters it takes, what output, etc.

The specification also requires someone to implement functions according to the specification, and the implementation of the OpenGL specification is a set of real functions. From a learning perspective, learning OpenGL is about learning the specifications and using specific functions.

Why OpenGL

OpenGL is used to draw content on the screen, but all platforms provide their own UI framework for developers to use. For example, Android’s View system does not require OpenGL to draw a square or display a few lines of text. OpenGL is a very high performance drawing method and should be used to do more imaginative things, such as drawing parts of some game engines with OpenGL.

OpenGL can handle more complex drawing, and the effect is smoother.

OpenGL is a bridge between CPU and GPU. When we use OpenGL, the data is provided to GPU in a certain way to perform the drawing, so the specific implementation of OpenGL specification is usually provided by the graphics card manufacturer.

Learning OpenGL

Avoid pit instructions

  1. OpenGL is procedural, and it can be awkward in an object-oriented environment, so keep reminding yourself
  2. OpenGL is a state machine, so when you call a function, you have to think about the context

Learning resources

OpenGL is too large to start with a document. Tutorials make more sense. Just take a quick note of what I’m looking at.

  • Video: Bilibili – One of the best OpenGL tutorials
  • Website: Learn OpenGL
  • Learn OpenGL 英 文版
  • Website: OpenGL API query

The entry stage does not need to pursue the breadth of knowledge and efficiency of the tutorial, easy to understand and stick to learning is the most important, such as a certain strength can distinguish the pros and disadvantages of the tutorial, for a tutorial to learn again will not be slow.

Environment set up

Firstly, I will choose a platform and a programming language. Since OpenGL on mobile is the ES version, it has less functions, so I plan to use MacOS and Rust.

The actual implementation of OpenGL is already in the graphics driver, so in theory you don’t need to download anything to use OpenGL, but actually you need a little bit of an auxiliary library to handle things other than drawing so that we can focus on OpenGL itself. One of the most important is to create Windows. The main way to verify that OpenGL code is correct or not is to look at it with your eyes. Creating a window on a debug platform should require using the API provided by the platform, and there is no need to learn too much about this process.

I said glium.

Glium is not a good idea, because it wraps the API, so when you call a function, you have to learn how to do OpenGL, and then you have to learn how Glium wraps OpenGL. Very not recommended.

Practical effect demonstration

Learning programming must not only see without writing, the last area just put some code and effect pictures, just make notes.

Code call flow:

  1. Create an event loop to update the drawing content
  2. Create Windows to display content
  3. Create OpenGL’s context (again, OpenGL is a state machine)
  4. Open the window to give a background color

cargo run