imgui_impl_opengl3.cpp
Go to the documentation of this file.
1 // dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline)
2 // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
3 // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..)
4 
5 // Implemented features:
6 // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
7 
8 // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
9 // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
10 // https://github.com/ocornut/imgui
11 
12 // CHANGELOG
13 // (minor and older changes stripped away, please see git history for details)
14 // 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
15 // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
16 // 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT).
17 // 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
18 // 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
19 // 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
20 // 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link.
21 // 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
22 // 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
23 // 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
24 // 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a NULL pointer.
25 // 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
26 // 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
27 // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
28 // 2018-01-07: OpenGL: Changed GLSL shader version from 330 to 150.
29 // 2017-09-01: OpenGL: Save and restore current bound sampler. Save and restore current polygon mode.
30 // 2017-05-01: OpenGL: Fixed save and restore of current blend func state.
31 // 2017-05-01: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
32 // 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
33 // 2016-07-29: OpenGL: Explicitly setting GL_UNPACK_ROW_LENGTH to reduce issues because SDL changes it. (#752)
34 
35 //----------------------------------------
36 // OpenGL GLSL GLSL
37 // version version string
38 //----------------------------------------
39 // 2.0 110 "#version 110"
40 // 2.1 120
41 // 3.0 130
42 // 3.1 140
43 // 3.2 150 "#version 150"
44 // 3.3 330
45 // 4.0 400
46 // 4.1 410 "#version 410 core"
47 // 4.2 420
48 // 4.3 430
49 // ES 2.0 100 "#version 100"
50 // ES 3.0 300 "#version 300 es"
51 //----------------------------------------
52 
53 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
54 #define _CRT_SECURE_NO_WARNINGS
55 #endif
56 
57 // MOD_ERIN
58 #include "imgui/imgui.h"
59 #include "imgui_impl_opengl3.h"
60 #include <stdio.h>
61 #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
62 #include <stddef.h> // intptr_t
63 #else
64 #include <stdint.h> // intptr_t
65 #endif
66 #if defined(__APPLE__)
67 #include "TargetConditionals.h"
68 #endif
69 
70 // iOS, Android and Emscripten can use GL ES 3
71 // Call ImGui_ImplOpenGL3_Init() with "#version 300 es"
72 #if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__ANDROID__)) || (defined(__EMSCRIPTEN__))
73 #define USE_GL_ES3
74 #endif
75 
76 #ifdef USE_GL_ES3
77 // OpenGL ES 3
78 #include <GLES3/gl3.h> // Use GL ES 3
79 #else
80 // Regular OpenGL
81 // About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
82 // Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
83 // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
84 #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
85 #include <GL/gl3w.h>
86 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
87 #include <GL/glew.h>
88 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
89 // MOD_ERIN
90 #include "glad/gl.h"
91 #else
92 #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
93 #endif
94 #endif
95 
96 // OpenGL Data
97 static char g_GlslVersionString[32] = "";
98 static GLuint g_FontTexture = 0;
102 static unsigned int g_VboHandle = 0, g_ElementsHandle = 0;
103 
104 // Functions
105 bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
106 {
107  ImGuiIO& io = ImGui::GetIO();
108  io.BackendRendererName = "imgui_impl_opengl3";
109 
110  // Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
111 #ifdef USE_GL_ES3
112  if (glsl_version == NULL)
113  glsl_version = "#version 300 es";
114 #else
115  if (glsl_version == NULL)
116  glsl_version = "#version 130";
117 #endif
118  IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersionString));
119  strcpy(g_GlslVersionString, glsl_version);
120  strcat(g_GlslVersionString, "\n");
121 
122  return true;
123 }
124 
126 {
128 }
129 
131 {
132  if (!g_FontTexture)
134 }
135 
136 // OpenGL3 Render function.
137 // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
138 // Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
140 {
141  // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
142  ImGuiIO& io = ImGui::GetIO();
143  int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x);
144  int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y);
145  if (fb_width <= 0 || fb_height <= 0)
146  return;
148 
149  // Backup GL state
150  GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
152  GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
153  GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
154 #ifdef GL_SAMPLER_BINDING
155  GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler);
156 #endif
157  GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
158  GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
159 #ifdef GL_POLYGON_MODE
160  GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
161 #endif
162  GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
163  GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
164  GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
165  GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb);
166  GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha);
167  GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha);
168  GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb);
169  GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha);
170  GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
171  GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
172  GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
173  GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
174  bool clip_origin_lower_left = true;
175 #ifdef GL_CLIP_ORIGIN
176  GLenum last_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&last_clip_origin); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
177  if (last_clip_origin == GL_UPPER_LEFT)
178  clip_origin_lower_left = false;
179 #endif
180 
181  // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
188 #ifdef GL_POLYGON_MODE
190 #endif
191 
192  // Setup viewport, orthographic projection matrix
193  // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps.
194  glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
195  float L = draw_data->DisplayPos.x;
196  float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
197  float T = draw_data->DisplayPos.y;
198  float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
199  const float ortho_projection[4][4] =
200  {
201  { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
202  { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
203  { 0.0f, 0.0f, -1.0f, 0.0f },
204  { (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
205  };
208  glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
209 #ifdef GL_SAMPLER_BINDING
210  glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
211 #endif
212  // Recreate the VAO every time
213  // (This is to easily allow multiple GL contexts. VAO are not shared among GL contexts, and we don't track creation/deletion of windows so we don't have an obvious key to use to cache them.)
214  GLuint vao_handle = 0;
215  glGenVertexArrays(1, &vao_handle);
216  glBindVertexArray(vao_handle);
224 
225  // Draw
226  ImVec2 pos = draw_data->DisplayPos;
227  for (int n = 0; n < draw_data->CmdListsCount; n++)
228  {
229  const ImDrawList* cmd_list = draw_data->CmdLists[n];
230  const ImDrawIdx* idx_buffer_offset = 0;
231 
234 
237 
238  for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
239  {
240  const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
241  if (pcmd->UserCallback)
242  {
243  // User callback (registered via ImDrawList::AddCallback)
244  pcmd->UserCallback(cmd_list, pcmd);
245  }
246  else
247  {
248  ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y);
249  if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
250  {
251  // Apply scissor/clipping rectangle
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));
254  else
255  glScissor((int)clip_rect.x, (int)clip_rect.y, (int)clip_rect.z, (int)clip_rect.w); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
256 
257  // Bind texture, Draw
258  glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
259  glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
260  }
261  }
262  idx_buffer_offset += pcmd->ElemCount;
263  }
264  }
265  glDeleteVertexArrays(1, &vao_handle);
266 
267  // Restore modified GL state
268  glUseProgram(last_program);
269  glBindTexture(GL_TEXTURE_2D, last_texture);
270 #ifdef GL_SAMPLER_BINDING
271  glBindSampler(0, last_sampler);
272 #endif
273  glActiveTexture(last_active_texture);
274  glBindVertexArray(last_vertex_array);
275  glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
276  glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
277  glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
278  if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
279  if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
280  if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
281  if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
282 #ifdef GL_POLYGON_MODE
283  glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
284 #endif
285  glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
286  glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
287 }
288 
290 {
291  // Build texture atlas
292  ImGuiIO& io = ImGui::GetIO();
293  unsigned char* pixels;
294  int width, height;
295  io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
296 
297  // Upload texture to graphics system
298  GLint last_texture;
299  glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
305  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
306 
307  // Store our identifier
308  io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
309 
310  // Restore state
311  glBindTexture(GL_TEXTURE_2D, last_texture);
312 
313  return true;
314 }
315 
317 {
318  if (g_FontTexture)
319  {
320  ImGuiIO& io = ImGui::GetIO();
322  io.Fonts->TexID = 0;
323  g_FontTexture = 0;
324  }
325 }
326 
327 // If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
328 static bool CheckShader(GLuint handle, const char* desc)
329 {
330  GLint status = 0, log_length = 0;
331  glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
332  glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
333  if ((GLboolean)status == GL_FALSE)
334  fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n", desc);
335  if (log_length > 0)
336  {
337  ImVector<char> buf;
338  buf.resize((int)(log_length + 1));
339  glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
340  fprintf(stderr, "%s\n", buf.begin());
341  }
342  return (GLboolean)status == GL_TRUE;
343 }
344 
345 // If you get an error please report on GitHub. You may try different GL context version or GLSL version.
346 static bool CheckProgram(GLuint handle, const char* desc)
347 {
348  GLint status = 0, log_length = 0;
349  glGetProgramiv(handle, GL_LINK_STATUS, &status);
350  glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
351  if ((GLboolean)status == GL_FALSE)
352  fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString);
353  if (log_length > 0)
354  {
355  ImVector<char> buf;
356  buf.resize((int)(log_length + 1));
357  glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
358  fprintf(stderr, "%s\n", buf.begin());
359  }
360  return (GLboolean)status == GL_TRUE;
361 }
362 
364 {
365  // Backup GL state
366  GLint last_texture, last_array_buffer, last_vertex_array;
367  glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
368  glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
369  glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
370 
371  // Parse GLSL version string
372  int glsl_version = 130;
373  sscanf(g_GlslVersionString, "#version %d", &glsl_version);
374 
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"
382  "void main()\n"
383  "{\n"
384  " Frag_UV = UV;\n"
385  " Frag_Color = Color;\n"
386  " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
387  "}\n";
388 
389  const GLchar* vertex_shader_glsl_130 =
390  "uniform mat4 ProjMtx;\n"
391  "in vec2 Position;\n"
392  "in vec2 UV;\n"
393  "in vec4 Color;\n"
394  "out vec2 Frag_UV;\n"
395  "out vec4 Frag_Color;\n"
396  "void main()\n"
397  "{\n"
398  " Frag_UV = UV;\n"
399  " Frag_Color = Color;\n"
400  " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
401  "}\n";
402 
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"
411  "void main()\n"
412  "{\n"
413  " Frag_UV = UV;\n"
414  " Frag_Color = Color;\n"
415  " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
416  "}\n";
417 
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"
425  "void main()\n"
426  "{\n"
427  " Frag_UV = UV;\n"
428  " Frag_Color = Color;\n"
429  " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
430  "}\n";
431 
432  const GLchar* fragment_shader_glsl_120 =
433  "#ifdef GL_ES\n"
434  " precision mediump float;\n"
435  "#endif\n"
436  "uniform sampler2D Texture;\n"
437  "varying vec2 Frag_UV;\n"
438  "varying vec4 Frag_Color;\n"
439  "void main()\n"
440  "{\n"
441  " gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
442  "}\n";
443 
444  const GLchar* fragment_shader_glsl_130 =
445  "uniform sampler2D Texture;\n"
446  "in vec2 Frag_UV;\n"
447  "in vec4 Frag_Color;\n"
448  "out vec4 Out_Color;\n"
449  "void main()\n"
450  "{\n"
451  " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
452  "}\n";
453 
454  const GLchar* fragment_shader_glsl_300_es =
455  "precision mediump float;\n"
456  "uniform sampler2D Texture;\n"
457  "in vec2 Frag_UV;\n"
458  "in vec4 Frag_Color;\n"
459  "layout (location = 0) out vec4 Out_Color;\n"
460  "void main()\n"
461  "{\n"
462  " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
463  "}\n";
464 
465  const GLchar* fragment_shader_glsl_410_core =
466  "in vec2 Frag_UV;\n"
467  "in vec4 Frag_Color;\n"
468  "uniform sampler2D Texture;\n"
469  "layout (location = 0) out vec4 Out_Color;\n"
470  "void main()\n"
471  "{\n"
472  " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
473  "}\n";
474 
475  // Select shaders matching our GLSL versions
476  const GLchar* vertex_shader = NULL;
477  const GLchar* fragment_shader = NULL;
478  if (glsl_version < 130)
479  {
480  vertex_shader = vertex_shader_glsl_120;
481  fragment_shader = fragment_shader_glsl_120;
482  }
483  else if (glsl_version >= 410)
484  {
485  vertex_shader = vertex_shader_glsl_410_core;
486  fragment_shader = fragment_shader_glsl_410_core;
487  }
488  else if (glsl_version == 300)
489  {
490  vertex_shader = vertex_shader_glsl_300_es;
491  fragment_shader = fragment_shader_glsl_300_es;
492  }
493  else
494  {
495  vertex_shader = vertex_shader_glsl_130;
496  fragment_shader = fragment_shader_glsl_130;
497  }
498 
499  // Create shaders
500  const GLchar* vertex_shader_with_version[2] = { g_GlslVersionString, vertex_shader };
502  glShaderSource(g_VertHandle, 2, vertex_shader_with_version, NULL);
504  CheckShader(g_VertHandle, "vertex shader");
505 
506  const GLchar* fragment_shader_with_version[2] = { g_GlslVersionString, fragment_shader };
508  glShaderSource(g_FragHandle, 2, fragment_shader_with_version, NULL);
510  CheckShader(g_FragHandle, "fragment shader");
511 
516  CheckProgram(g_ShaderHandle, "shader program");
517 
523 
524  // Create buffers
527 
529 
530  // Restore modified GL state
531  glBindTexture(GL_TEXTURE_2D, last_texture);
532  glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
533  glBindVertexArray(last_vertex_array);
534 
535  return true;
536 }
537 
539 {
543 
546  g_VertHandle = 0;
547 
550  g_FragHandle = 0;
551 
553  g_ShaderHandle = 0;
554 
556 }
#define GL_UNSIGNED_SHORT
Definition: gl.h:947
bool ImGui_ImplOpenGL3_Init(const char *glsl_version)
#define GL_TRIANGLES
Definition: gl.h:886
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
ImVec2 DisplaySize
Definition: imgui.h:1887
ImDrawList ** CmdLists
Definition: imgui.h:1882
#define GL_VIEWPORT
Definition: gl.h:970
#define glBlendFunc
Definition: gl.h:1452
bool ImGui_ImplOpenGL3_CreateFontsTexture()
#define glEnable
Definition: gl.h:1574
#define glCreateShader
Definition: gl.h:1516
void GLvoid
Definition: gl.h:981
#define GL_BLEND
Definition: gl.h:182
#define glDisable
Definition: gl.h:1548
#define GL_CULL_FACE
Definition: gl.h:283
#define GL_ACTIVE_TEXTURE
Definition: gl.h:159
#define GL_BLEND_DST_RGB
Definition: gl.h:186
#define glDeleteShader
Definition: gl.h:1532
#define glBlendEquation
Definition: gl.h:1448
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
f
static bool CheckShader(GLuint handle, const char *desc)
#define GL_FALSE
Definition: gl.h:343
#define glGenTextures
Definition: gl.h:1618
Definition: imgui.h:164
#define glShaderSource
Definition: gl.h:1844
#define glIsEnabled
Definition: gl.h:1756
#define glBindSampler
Definition: gl.h:1440
#define GL_UNSIGNED_BYTE
Definition: gl.h:922
#define glUniformMatrix4fv
Definition: gl.h:1952
static GLuint g_VertHandle
#define GL_VERTEX_ARRAY_BINDING
Definition: gl.h:958
static int g_AttribLocationColor
static int g_AttribLocationUV
int GLint
Definition: gl.h:986
#define GL_FLOAT
Definition: gl.h:348
#define glDetachShader
Definition: gl.h:1546
ImVec2 DisplayPos
Definition: imgui.h:1886
static unsigned int g_ElementsHandle
#define glLinkProgram
Definition: gl.h:1780
static GLuint g_ShaderHandle
ImVec4 ClipRect
Definition: imgui.h:1724
#define GL_BLEND_EQUATION_ALPHA
Definition: gl.h:188
int CmdListsCount
Definition: imgui.h:1883
void resize(int new_size)
Definition: imgui.h:1201
#define glBindTexture
Definition: gl.h:1442
#define IM_ARRAYSIZE(_ARR)
Definition: imgui.h:73
#define glTexImage2D
Definition: gl.h:1862
#define GL_UNPACK_ROW_LENGTH
Definition: gl.h:916
#define glBlendEquationSeparate
Definition: gl.h:1450
unsigned int GLenum
Definition: gl.h:978
#define GL_SAMPLER_BINDING
Definition: gl.h:698
unsigned int GLuint
Definition: gl.h:987
#define glTexParameteri
Definition: gl.h:1878
static int g_AttribLocationTex
#define GL_FRONT_AND_BACK
Definition: gl.h:392
#define glGetProgramiv
Definition: gl.h:1678
#define GL_FUNC_ADD
Definition: gl.h:396
unsigned short ImDrawIdx
Definition: imgui.h:1734
#define glActiveTexture
Definition: gl.h:1414
IMGUI_API void ScaleClipRects(const ImVec2 &sc)
#define GL_FRAGMENT_SHADER
Definition: gl.h:362
static bool CheckProgram(GLuint handle, const char *desc)
#define GL_ARRAY_BUFFER
Definition: gl.h:172
#define IM_ASSERT(_EXPR)
Definition: imgui.h:64
static GLuint g_FragHandle
static int g_AttribLocationProjMtx
#define GL_POLYGON_MODE
Definition: gl.h:564
#define glDrawElements
Definition: gl.h:1562
#define GL_BLEND_SRC_RGB
Definition: gl.h:192
#define GL_UNSIGNED_INT
Definition: gl.h:925
void ImGui_ImplOpenGL3_DestroyFontsTexture()
float w
Definition: imgui.h:178
#define glUseProgram
Definition: gl.h:1960
#define glAttachShader
Definition: gl.h:1416
#define glPixelStorei
Definition: gl.h:1796
#define GL_TEXTURE_MIN_FILTER
Definition: gl.h:857
T * Data
Definition: imgui.h:1170
#define glDeleteTextures
Definition: gl.h:1536
#define glBlendFuncSeparate
Definition: gl.h:1454
#define glGetUniformLocation
Definition: gl.h:1732
ImVector< ImDrawCmd > CmdBuffer
Definition: imgui.h:1790
#define GL_ARRAY_BUFFER_BINDING
Definition: gl.h:173
#define GL_SCISSOR_TEST
Definition: gl.h:714
ImTextureID TextureId
Definition: imgui.h:1725
#define glVertexAttribPointer
Definition: gl.h:2096
#define glCompileShader
Definition: gl.h:1488
#define glPolygonMode
Definition: gl.h:1808
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:2975
float z
Definition: imgui.h:178
#define GL_LINK_STATUS
Definition: gl.h:452
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
Definition: gl.h:410
#define glBufferData
Definition: gl.h:1458
unsigned char GLboolean
Definition: gl.h:979
#define GL_LINEAR
Definition: gl.h:439
static int g_AttribLocationPosition
Definition: imgui.h:176
int Size
Definition: imgui.h:1168
#define glGetIntegerv
Definition: gl.h:1672
ImTextureID TexID
Definition: imgui.h:2047
static char g_GlslVersionString[32]
#define GL_BLEND_DST_ALPHA
Definition: gl.h:185
float x
Definition: imgui.h:178
#define glGenVertexArrays
Definition: gl.h:1620
const char * BackendRendererName
Definition: imgui.h:1312
#define GL_SCISSOR_BOX
Definition: gl.h:713
#define GL_TEXTURE_BINDING_2D
Definition: gl.h:819
#define GL_VERTEX_SHADER
Definition: gl.h:969
#define GL_UPPER_LEFT
Definition: gl.h:954
float y
Definition: imgui.h:166
#define GL_STREAM_DRAW
Definition: gl.h:765
ImDrawCallback UserCallback
Definition: imgui.h:1726
khronos_ssize_t GLsizeiptr
Definition: gl.h:1019
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData *draw_data)
#define glScissor
Definition: gl.h:1842
#define glBindVertexArray
Definition: gl.h:1444
#define GL_FILL
Definition: gl.h:345
#define glDeleteVertexArrays
Definition: gl.h:1538
#define GL_DEPTH_TEST
Definition: gl.h:308
#define GL_TEXTURE_MAG_FILTER
Definition: gl.h:854
char GLchar
Definition: gl.h:996
#define glEnableVertexAttribArray
Definition: gl.h:1576
#define GL_TRUE
Definition: gl.h:891
#define IM_OFFSETOF(_TYPE, _MEMBER)
Definition: imgui.h:74
#define glGenBuffers
Definition: gl.h:1608
static unsigned int g_VboHandle
ImVector< ImDrawVert > VtxBuffer
Definition: imgui.h:1792
#define GL_TEXTURE_2D
Definition: gl.h:809
#define glGetProgramInfoLog
Definition: gl.h:1676
#define glGetShaderiv
Definition: gl.h:1704
unsigned int ElemCount
Definition: imgui.h:1723
ImVec2 DisplayFramebufferScale
Definition: imgui.h:1294
#define glBindBuffer
Definition: gl.h:1426
#define glCreateProgram
Definition: gl.h:1514
#define GL_BLEND_EQUATION_RGB
Definition: gl.h:189
int GLsizei
Definition: gl.h:989
#define GL_ONE_MINUS_SRC_ALPHA
Definition: gl.h:539
static GLuint g_FontTexture
#define glDeleteBuffers
Definition: gl.h:1520
#define GL_SRC_ALPHA
Definition: gl.h:729
#define GL_RGBA
Definition: gl.h:665
#define GL_ELEMENT_ARRAY_BUFFER
Definition: gl.h:338
#define glUniform1i
Definition: gl.h:1894
void ImGui_ImplOpenGL3_Shutdown()
#define GL_BLEND_SRC_ALPHA
Definition: gl.h:191
#define glViewport
Definition: gl.h:2098
ImVector< ImDrawIdx > IdxBuffer
Definition: imgui.h:1791
#define glGetAttribLocation
Definition: gl.h:1638
ImFontAtlas * Fonts
Definition: imgui.h:1290
T * begin()
Definition: imgui.h:1190
#define GL_COMPILE_STATUS
Definition: gl.h:259
#define GL_CURRENT_PROGRAM
Definition: gl.h:285
void * ImTextureID
Definition: imgui.h:111
#define glDeleteProgram
Definition: gl.h:1524
#define GL_TEXTURE0
Definition: gl.h:775
float y
Definition: imgui.h:178
float x
Definition: imgui.h:166
#define glGetShaderInfoLog
Definition: gl.h:1700
void ImGui_ImplOpenGL3_NewFrame()


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21