Skip to content

Commit 6cb3fba

Browse files
authored
Opening a GL context with Win32 (#19)
* start * wording. * gl progress * fix a freeing the box bug * complete the transition. * well now it doesn't make the window! * works with an alternate window class, not sure why * fake context stuff all done * note update. * gl for win32 complete * copy main.rs to example
1 parent cfa6400 commit 6cb3fba

File tree

13 files changed

+3315
-96
lines changed

13 files changed

+3315
-96
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ version = "0.1.0"
44
authors = ["Lokathor <zefria@gmail.com>"]
55
edition = "2018"
66
license = "Zlib OR Apache-2.0 OR MIT"
7+
8+
[profile.release]
9+
lto = "thin"

book_src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
* [Opening A Window](opening_a_window/index.md)
55
* [Win32](opening_a_window/win32.md)
66
* [Win32 Cleanup](opening_a_window/win32_cleanup.md)
7+
* [Loading OpenGL](loading_opengl/index.md)
8+
* [Win32](loading_opengl/win32.md)
79
* [Appendix](appendix/index.md)
810
* [UTF-16 Literals](appendix/utf16_literals.md)

book_src/loading_opengl/index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

Comments
 (0)