This repository was archived by the owner on Mar 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.cpp
More file actions
59 lines (45 loc) · 1.21 KB
/
Copy pathcontext.cpp
File metadata and controls
59 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "context.h"
#include "config.h"
Context::Context(HWND window) : m_window(window), m_frame_count(0) {
PIXELFORMATDESCRIPTOR pfd{};
pfd.nSize = sizeof pfd;
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;
m_device = GetDC(window);
int i = ChoosePixelFormat(m_device, & pfd);
SetPixelFormat(m_device, i, &pfd);
m_gl = wglCreateContext(m_device);
wglMakeCurrent(m_device, m_gl);
glEnable(GL_TEXTURE_2D);
// If you don't specify these two things,
// you won't get transparency on _anything_, no matter how hard you
// scream the word "RGBA".
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GetClientRect(window, &m_rect);
SetTimer(window, ANIM_TIMER_ID, SIXTY_FPS, NULL);
}
Context::~Context() {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_gl);
ReleaseDC(m_window, m_device);
KillTimer(m_window, ANIM_TIMER_ID);
}
HDC Context::device() {
return m_device;
}
HGLRC Context::gl() {
return m_gl;
}
RECT Context::rect() {
return m_rect;
}
unsigned int &Context::frame_count() {
return m_frame_count;
}
double Context::t() {
return m_frame_count / cfg[Cfg::TimeDivisor];
}