53 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) 54 #define _CRT_SECURE_NO_WARNINGS 61 #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier 66 #if defined(__APPLE__) 67 #include "TargetConditionals.h" 72 #if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__ANDROID__)) || (defined(__EMSCRIPTEN__)) 78 #include <GLES3/gl3.h> 84 #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) 86 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) 88 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) 92 #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM 112 if (glsl_version == NULL)
113 glsl_version =
"#version 300 es";
115 if (glsl_version == NULL)
116 glsl_version =
"#version 130";
145 if (fb_width <= 0 || fb_height <= 0)
154 #ifdef GL_SAMPLER_BINDING 159 #ifdef GL_POLYGON_MODE 174 bool clip_origin_lower_left =
true;
175 #ifdef GL_CLIP_ORIGIN 178 clip_origin_lower_left =
false;
188 #ifdef GL_POLYGON_MODE 199 const float ortho_projection[4][4] =
201 { 2.0f/(R-L), 0.0
f, 0.0
f, 0.0
f },
202 { 0.0f, 2.0f/(T-B), 0.0
f, 0.0
f },
203 { 0.0f, 0.0f, -1.0f, 0.0f },
204 { (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
209 #ifdef GL_SAMPLER_BINDING 238 for (
int cmd_i = 0; cmd_i < cmd_list->
CmdBuffer.
Size; cmd_i++)
249 if (clip_rect.
x < fb_width && clip_rect.
y < fb_height && clip_rect.
z >= 0.0f && clip_rect.
w >= 0.0f)
252 if (clip_origin_lower_left)
253 glScissor((
int)clip_rect.
x, (
int)(fb_height - clip_rect.
w), (
int)(clip_rect.
z - clip_rect.
x), (
int)(clip_rect.
w - clip_rect.
y));
255 glScissor((
int)clip_rect.
x, (
int)clip_rect.
y, (
int)clip_rect.
z, (
int)clip_rect.
w);
270 #ifdef GL_SAMPLER_BINDING 277 glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
282 #ifdef GL_POLYGON_MODE 286 glScissor(last_scissor_box[0], last_scissor_box[1], (
GLsizei)last_scissor_box[2], (
GLsizei)last_scissor_box[3]);
293 unsigned char* pixels;
330 GLint status = 0, log_length = 0;
334 fprintf(stderr,
"ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n", desc);
338 buf.
resize((
int)(log_length + 1));
340 fprintf(stderr,
"%s\n", buf.
begin());
348 GLint status = 0, log_length = 0;
352 fprintf(stderr,
"ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc,
g_GlslVersionString);
356 buf.
resize((
int)(log_length + 1));
358 fprintf(stderr,
"%s\n", buf.
begin());
366 GLint last_texture, last_array_buffer, last_vertex_array;
372 int glsl_version = 130;
375 const GLchar* vertex_shader_glsl_120 =
376 "uniform mat4 ProjMtx;\n" 377 "attribute vec2 Position;\n" 378 "attribute vec2 UV;\n" 379 "attribute vec4 Color;\n" 380 "varying vec2 Frag_UV;\n" 381 "varying vec4 Frag_Color;\n" 385 " Frag_Color = Color;\n" 386 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" 389 const GLchar* vertex_shader_glsl_130 =
390 "uniform mat4 ProjMtx;\n" 391 "in vec2 Position;\n" 394 "out vec2 Frag_UV;\n" 395 "out vec4 Frag_Color;\n" 399 " Frag_Color = Color;\n" 400 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" 403 const GLchar* vertex_shader_glsl_300_es =
404 "precision mediump float;\n" 405 "layout (location = 0) in vec2 Position;\n" 406 "layout (location = 1) in vec2 UV;\n" 407 "layout (location = 2) in vec4 Color;\n" 408 "uniform mat4 ProjMtx;\n" 409 "out vec2 Frag_UV;\n" 410 "out vec4 Frag_Color;\n" 414 " Frag_Color = Color;\n" 415 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" 418 const GLchar* vertex_shader_glsl_410_core =
419 "layout (location = 0) in vec2 Position;\n" 420 "layout (location = 1) in vec2 UV;\n" 421 "layout (location = 2) in vec4 Color;\n" 422 "uniform mat4 ProjMtx;\n" 423 "out vec2 Frag_UV;\n" 424 "out vec4 Frag_Color;\n" 428 " Frag_Color = Color;\n" 429 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n" 432 const GLchar* fragment_shader_glsl_120 =
434 " precision mediump float;\n" 436 "uniform sampler2D Texture;\n" 437 "varying vec2 Frag_UV;\n" 438 "varying vec4 Frag_Color;\n" 441 " gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n" 444 const GLchar* fragment_shader_glsl_130 =
445 "uniform sampler2D Texture;\n" 447 "in vec4 Frag_Color;\n" 448 "out vec4 Out_Color;\n" 451 " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" 454 const GLchar* fragment_shader_glsl_300_es =
455 "precision mediump float;\n" 456 "uniform sampler2D Texture;\n" 458 "in vec4 Frag_Color;\n" 459 "layout (location = 0) out vec4 Out_Color;\n" 462 " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" 465 const GLchar* fragment_shader_glsl_410_core =
467 "in vec4 Frag_Color;\n" 468 "uniform sampler2D Texture;\n" 469 "layout (location = 0) out vec4 Out_Color;\n" 472 " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" 476 const GLchar* vertex_shader = NULL;
477 const GLchar* fragment_shader = NULL;
478 if (glsl_version < 130)
480 vertex_shader = vertex_shader_glsl_120;
481 fragment_shader = fragment_shader_glsl_120;
483 else if (glsl_version >= 410)
485 vertex_shader = vertex_shader_glsl_410_core;
486 fragment_shader = fragment_shader_glsl_410_core;
488 else if (glsl_version == 300)
490 vertex_shader = vertex_shader_glsl_300_es;
491 fragment_shader = fragment_shader_glsl_300_es;
495 vertex_shader = vertex_shader_glsl_130;
496 fragment_shader = fragment_shader_glsl_130;
#define GL_UNSIGNED_SHORT
bool ImGui_ImplOpenGL3_Init(const char *glsl_version)
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
bool ImGui_ImplOpenGL3_CreateFontsTexture()
#define GL_ACTIVE_TEXTURE
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
static bool CheckShader(GLuint handle, const char *desc)
#define glUniformMatrix4fv
static GLuint g_VertHandle
#define GL_VERTEX_ARRAY_BINDING
static int g_AttribLocationColor
static int g_AttribLocationUV
static unsigned int g_ElementsHandle
static GLuint g_ShaderHandle
#define GL_BLEND_EQUATION_ALPHA
void resize(int new_size)
#define IM_ARRAYSIZE(_ARR)
#define GL_UNPACK_ROW_LENGTH
#define glBlendEquationSeparate
#define GL_SAMPLER_BINDING
static int g_AttribLocationTex
#define GL_FRONT_AND_BACK
IMGUI_API void ScaleClipRects(const ImVec2 &sc)
#define GL_FRAGMENT_SHADER
static bool CheckProgram(GLuint handle, const char *desc)
static GLuint g_FragHandle
static int g_AttribLocationProjMtx
void ImGui_ImplOpenGL3_DestroyFontsTexture()
#define GL_TEXTURE_MIN_FILTER
#define glBlendFuncSeparate
#define glGetUniformLocation
ImVector< ImDrawCmd > CmdBuffer
#define GL_ARRAY_BUFFER_BINDING
#define glVertexAttribPointer
IMGUI_API ImGuiIO & GetIO()
IMGUI_API void GetTexDataAsRGBA32(unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel=NULL)
#define GL_INFO_LOG_LENGTH
static int g_AttribLocationPosition
static char g_GlslVersionString[32]
#define GL_BLEND_DST_ALPHA
#define glGenVertexArrays
const char * BackendRendererName
#define GL_TEXTURE_BINDING_2D
ImDrawCallback UserCallback
khronos_ssize_t GLsizeiptr
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData *draw_data)
#define glBindVertexArray
#define glDeleteVertexArrays
#define GL_TEXTURE_MAG_FILTER
#define glEnableVertexAttribArray
#define IM_OFFSETOF(_TYPE, _MEMBER)
static unsigned int g_VboHandle
ImVector< ImDrawVert > VtxBuffer
#define glGetProgramInfoLog
ImVec2 DisplayFramebufferScale
#define GL_BLEND_EQUATION_RGB
#define GL_ONE_MINUS_SRC_ALPHA
static GLuint g_FontTexture
#define GL_ELEMENT_ARRAY_BUFFER
void ImGui_ImplOpenGL3_Shutdown()
#define GL_BLEND_SRC_ALPHA
ImVector< ImDrawIdx > IdxBuffer
#define glGetAttribLocation
#define GL_COMPILE_STATUS
#define GL_CURRENT_PROGRAM
#define glGetShaderInfoLog
void ImGui_ImplOpenGL3_NewFrame()