-
Notifications
You must be signed in to change notification settings - Fork 1
/
imapp_renderer_opengl2.cpp
90 lines (70 loc) · 2.35 KB
/
imapp_renderer_opengl2.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
// imapp: standalone application starter kit
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
// **Prefer using the code in the example_sdl_opengl3/ folder**
// See imgui_impl_sdl.cpp for details.
#include "imapp.h"
#include "imapp_internal.h"
#include "imgui.h"
#include "imgui_impl_opengl2.h"
#include "imapp_opengl_loader.h"
namespace ImApp
{
bool SetupRenderer() { return true; }
void ShutdownRenderer() {}
bool InitRenderer()
{
// Setup Renderer bindings
return ImGui_ImplOpenGL2_Init();
}
void BeginFrameRenderer()
{
ImGui_ImplOpenGL2_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);
// If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!),
// you may need to backup/reset/restore current shader using the commented lines below.
//GLint last_program;
//glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
//glUseProgram(0);
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
//glUseProgram(last_program);
#ifdef IMGUI_HAS_VIEWPORT
UpdateViewportPlatform();
#endif
}
void CleanupRenderer()
{
ImGui_ImplOpenGL2_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;
}
}