@ -13,6 +13,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplGlfwGL3_Init() so user can override the GLSL version e.g. "#version 150".
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
// 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value and WM_SETCURSOR message handling).
// 2018-02-20: Inputs: Renamed GLFW callbacks exposed in .h to not include GL3 in their name.
@ -31,6 +32,10 @@
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
// 2016-04-30: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
# endif
# include "imgui.h"
# include "imgui_impl_glfw_gl3.h"
@ -51,6 +56,7 @@ static bool g_MouseJustPressed[3] = { false, false, false };
static GLFWcursor * g_MouseCursors [ ImGuiMouseCursor_COUNT ] = { 0 } ;
// OpenGL3 data
static char g_GlslVersion [ 32 ] = " #version 150 " ;
static GLuint g_FontTexture = 0 ;
static int g_ShaderHandle = 0 , g_VertHandle = 0 , g_FragHandle = 0 ;
static int g_AttribLocationTex = 0 , g_AttribLocationProjMtx = 0 ;
@ -258,8 +264,7 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
glGetIntegerv ( GL_ARRAY_BUFFER_BINDING , & last_array_buffer ) ;
glGetIntegerv ( GL_VERTEX_ARRAY_BINDING , & last_vertex_array ) ;
const GLchar * vertex_shader =
" #version 150 \n "
const GLchar * vertex_shader =
" uniform mat4 ProjMtx; \n "
" in vec2 Position; \n "
" in vec2 UV; \n "
@ -274,7 +279,6 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
" } \n " ;
const GLchar * fragment_shader =
" #version 150 \n "
" uniform sampler2D Texture; \n "
" in vec2 Frag_UV; \n "
" in vec4 Frag_Color; \n "
@ -284,11 +288,14 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
" Out_Color = Frag_Color * texture( Texture, Frag_UV.st); \n "
" } \n " ;
const GLchar * vertex_shader_with_version [ 2 ] = { g_GlslVersion , vertex_shader } ;
const GLchar * fragment_shader_with_version [ 2 ] = { g_GlslVersion , fragment_shader } ;
g_ShaderHandle = glCreateProgram ( ) ;
g_VertHandle = glCreateShader ( GL_VERTEX_SHADER ) ;
g_FragHandle = glCreateShader ( GL_FRAGMENT_SHADER ) ;
glShaderSource ( g_VertHandle , 1, & vertex_shader , 0 ) ;
glShaderSource ( g_FragHandle , 1, & fragment_shader , 0 ) ;
glShaderSource ( g_VertHandle , 2, vertex_shader_with_version , NULL ) ;
glShaderSource ( g_FragHandle , 2, fragment_shader_with_version , NULL ) ;
glCompileShader ( g_VertHandle ) ;
glCompileShader ( g_FragHandle ) ;
glAttachShader ( g_ShaderHandle , g_VertHandle ) ;
@ -347,12 +354,20 @@ static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
glfwSetCharCallback ( window , ImGui_ImplGlfw_CharCallback ) ;
}
bool ImGui_ImplGlfwGL3_Init ( GLFWwindow * window , bool install_callbacks )
bool ImGui_ImplGlfwGL3_Init ( GLFWwindow * window , bool install_callbacks , const char * glsl_version )
{
g_Window = window ;
// Store GL version string so we can refer to it later in case we recreate shaders.
if ( glsl_version = = NULL )
glsl_version = " #version 150 " ;
IM_ASSERT ( ( int ) strlen ( glsl_version ) + 2 < IM_ARRAYSIZE ( g_GlslVersion ) ) ;
strcpy ( g_GlslVersion , glsl_version ) ;
strcat ( g_GlslVersion , " \n " ) ;
// Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
ImGuiIO & io = ImGui : : GetIO ( ) ;
io . KeyMap [ ImGuiKey_Tab ] = GLFW_KEY_TAB ; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
io . KeyMap [ ImGuiKey_Tab ] = GLFW_KEY_TAB ;
io . KeyMap [ ImGuiKey_LeftArrow ] = GLFW_KEY_LEFT ;
io . KeyMap [ ImGuiKey_RightArrow ] = GLFW_KEY_RIGHT ;
io . KeyMap [ ImGuiKey_UpArrow ] = GLFW_KEY_UP ;