-
Notifications
You must be signed in to change notification settings - Fork 0
/
imapp_renderer_opengl3.cpp
80 lines (61 loc) · 1.82 KB
/
imapp_renderer_opengl3.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
// imapp: standalone application starter kit
#include "imapp.h"
#include "imapp_internal.h"
#include "imgui.h"
#include "imgui_impl_opengl3.h"
#include "imapp_opengl_loader.h"
namespace ImApp
{
bool SetupRenderer() { return true; }
void ShutdownRenderer() {}
bool InitRenderer()
{
// Setup Renderer bindings
return ImGui_ImplOpenGL3_Init(IMAPP_GLSL_VERSION);
}
void BeginFrameRenderer()
{
ImGui_ImplOpenGL3_NewFrame();
}
void EndFrameRenderer(const ImVec4 &clear_col)
{
int display_w, display_h;
GetFramebufferSize(display_w, display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(clear_col.x, clear_col.y, clear_col.z, clear_col.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
#ifdef IMGUI_HAS_VIEWPORT
UpdateViewportPlatform();
#endif
}
void CleanupRenderer()
{
ImGui_ImplOpenGL3_Shutdown();
}
// Original code: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples#Example-for-OpenGL-users
bool CreateTexture(unsigned char* pixels, int width, int height, ImTextureID* out_texture_id)
{
// Create a OpenGL texture identifier
GLuint image_texture;
glGenTextures(1, &image_texture);
glBindTexture(GL_TEXTURE_2D, image_texture);
// Setup filtering parameters for display
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Upload pixels into texture
#ifdef GL_UNPACK_ROW_LENGTH
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
if (out_texture_id != NULL)
{
*out_texture_id = reinterpret_cast<ImTextureID>(image_texture);
}
return true;
}
bool UploadFonts()
{
return true;
}
}