|
| 1 | + |
| 2 | +# Loading Open GL |
| 3 | + |
| 4 | +While the *usage* of Open GL is basically the same across platforms, |
| 5 | +the precise details of how to first initialize Open GL varies. |
| 6 | + |
| 7 | +The general idea is that we need to do two things: |
| 8 | + |
| 9 | +1) Create an [Open GL context](https://www.khronos.org/opengl/wiki/OpenGL_Context) |
| 10 | + and make it "current". |
| 11 | + A GL context is what holds all of the drawing state for GL. |
| 12 | + Each GL Context must only be current in a single thread at a time, |
| 13 | + otherwise you'll get undefined behavior. |
| 14 | + Also, a thread's current context is a thread-local variable, |
| 15 | + so you can't have more than one context current in a thread at a time. |
| 16 | + Also, a context is associated with a particular window's drawing area. |
| 17 | + Usually you have just one window, |
| 18 | + and so you have only one GL context, |
| 19 | + meaning that don't need to worry about any of that. |
| 20 | + If you're trying to use GL with more than one window at a time, |
| 21 | + things can get tricky. |
| 22 | +2) Load the GL function pointers. |
| 23 | + Unfortunately, you can't access GL like it was a normal dynamic library. |
| 24 | + At least, you can't on Windows and Linux. |
| 25 | + We'll have a whole fun time |
| 26 | + [loading function pointers](https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions) manually. |
| 27 | + |
| 28 | +## Acknowledgements |
| 29 | + |
| 30 | +For this portion of the guide I'd like to give an incredible acknowledgement to |
| 31 | +[glowcoil](https://github.com/glowcoil), who wrote the |
| 32 | +[raw-gl-context](https://github.com/glowcoil/raw-gl-context) |
| 33 | +crate, which gives come very clean and clear examples of how you open a GL context on the major platforms. |
0 commit comments