-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOGL_Immediate_2D.cpp
114 lines (103 loc) · 3.12 KB
/
OGL_Immediate_2D.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "OGL_Immediate_2D.h"
float gl33_FPS; // le nombre de frames par seconde
DWORD gl33_lastTime = 0; // dernier timeGetTime() pour le calcul du FPS
DWORD gl33_nbHits = 0; // nombre de hits entre 2 secondes
bool gl33_init = false;
int text_CreateTextureCircle(GLFWwindow* glfww)
{
glfwMakeContextCurrent(glfww);
// si pwidth etpheight sont !=NULL ils renvoient la taille de l'image
/* Generate texture */
GLuint texid;
UINT8 texel[64] = { 0,255,255,255,255,255,255,0,
255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,
0,255,255,255,255,255,255,0 };
//ZeroMemory(texel, 64);
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);
/* Setup texture filters */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, 8, 8, 0, GL_RED, GL_UNSIGNED_BYTE, texel);
return texid;
}
bool gl33_InitWindow(GLFWwindow** glfwnWin, int width, int height, const char* title, HWND hParent)
{
// Initializing GLFW
if (!gl33_init)
{
if (!glfwInit())
{
return false;
}
gl33_init = true;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_DECORATED, false);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); //We don't want the old OpenGL
*glfwnWin = glfwCreateWindow(width, height, title, NULL, NULL);
if (!*glfwnWin)
{
return false;
}
glfwMakeContextCurrent(*glfwnWin);
if (hParent)
{
HWND oglwin = glfwGetWin32Window(*glfwnWin);
SetParent(oglwin, hParent);
const LONG nNewStyle = (GetWindowLong(oglwin, GWL_STYLE) & ~WS_POPUP) | WS_CHILDWINDOW;
SetWindowLong(oglwin, GWL_STYLE, nNewStyle);
}
while (glGetError() != GL_NO_ERROR);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
return false;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return true;
}
float gl33_SwapBuffers(GLFWwindow* fwWin,bool calcFPS)
{
if (calcFPS)
{
if (gl33_lastTime > 0)
{
DWORD acTime, elpsTime;
acTime = timeGetTime();
elpsTime = acTime - gl33_lastTime;
if (elpsTime > 1000)
{
gl33_FPS = (float)((1.0f * gl33_nbHits) / (elpsTime / 1000.0f));
gl33_lastTime = acTime;
gl33_nbHits = 0;
}
gl33_nbHits++;
}
else
{
gl33_FPS = 0;
gl33_lastTime = timeGetTime();
}
}
glfwMakeContextCurrent(fwWin);
glfwSwapBuffers(fwWin);
glClear(GL_COLOR_BUFFER_BIT);
return gl33_FPS;
}