|
@@ -217,13 +217,50 @@ void InitGL()
|
|
|
glewInit();
|
|
|
|
|
|
GLenum err = GL_NO_ERROR;
|
|
|
+ err = glGetError(); IM_ASSERT(err == GL_NO_ERROR);
|
|
|
+}
|
|
|
+
|
|
|
+void InitImGui()
|
|
|
+{
|
|
|
+ int w, h;
|
|
|
+ glfwGetWindowSize(window, &w, &h);
|
|
|
+
|
|
|
+ ImGuiIO& io = ImGui::GetIO();
|
|
|
+ io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions.
|
|
|
+ io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable)
|
|
|
+ io.PixelCenterOffset = 0.5f; // Align OpenGL texels
|
|
|
+ io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
|
|
|
+ io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
|
|
|
+ io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
|
|
+ io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
|
|
+ io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
|
|
|
+ io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
|
|
|
+ io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
|
|
|
+ io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
|
|
|
+ io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
|
|
|
+ io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
|
|
|
+ io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
|
|
|
+ io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
|
|
|
+ io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
|
|
|
+ io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
|
|
|
+ io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
|
|
|
+ io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
|
|
+ io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
|
|
+
|
|
|
+ io.RenderDrawListsFn = ImImpl_RenderDrawLists;
|
|
|
+ io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
|
|
|
+ io.GetClipboardTextFn = ImImpl_GetClipboardTextFn;
|
|
|
+
|
|
|
+
|
|
|
+ // Setup graphics backend
|
|
|
GLint status = GL_TRUE;
|
|
|
+ GLenum err = GL_NO_ERROR;
|
|
|
err = glGetError(); IM_ASSERT(err == GL_NO_ERROR);
|
|
|
|
|
|
- // Create and compile the vertex shader
|
|
|
- vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
|
|
- glShaderSource(vertexShader, 1, &vertexSource, NULL);
|
|
|
- glCompileShader(vertexShader);
|
|
|
+ // Create and compile the vertex shader
|
|
|
+ vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
|
|
+ glShaderSource(vertexShader, 1, &vertexSource, NULL);
|
|
|
+ glCompileShader(vertexShader);
|
|
|
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
|
|
|
if (status != GL_TRUE)
|
|
|
{
|
|
@@ -233,19 +270,19 @@ void InitGL()
|
|
|
IM_ASSERT(status == GL_TRUE);
|
|
|
}
|
|
|
|
|
|
- // Create and compile the fragment shader
|
|
|
- fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
|
|
- glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
|
|
|
- glCompileShader(fragmentShader);
|
|
|
+ // Create and compile the fragment shader
|
|
|
+ fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
|
|
+ glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
|
|
|
+ glCompileShader(fragmentShader);
|
|
|
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
|
|
|
IM_ASSERT(status == GL_TRUE);
|
|
|
|
|
|
- // Link the vertex and fragment shader into a shader program
|
|
|
- shaderProgram = glCreateProgram();
|
|
|
- glAttachShader(shaderProgram, vertexShader);
|
|
|
- glAttachShader(shaderProgram, fragmentShader);
|
|
|
- glBindFragDataLocation(shaderProgram, 0, "o_col");
|
|
|
- glLinkProgram(shaderProgram);
|
|
|
+ // Link the vertex and fragment shader into a shader program
|
|
|
+ shaderProgram = glCreateProgram();
|
|
|
+ glAttachShader(shaderProgram, vertexShader);
|
|
|
+ glAttachShader(shaderProgram, fragmentShader);
|
|
|
+ glBindFragDataLocation(shaderProgram, 0, "o_col");
|
|
|
+ glLinkProgram(shaderProgram);
|
|
|
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &status);
|
|
|
IM_ASSERT(status == GL_TRUE);
|
|
|
|
|
@@ -257,7 +294,7 @@ void InitGL()
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
|
glGenVertexArrays(1, &vao);
|
|
|
glBindVertexArray(vao);
|
|
|
-
|
|
|
+
|
|
|
GLint posAttrib = glGetAttribLocation(shaderProgram, "i_pos");
|
|
|
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), 0);
|
|
|
glEnableVertexAttribArray(posAttrib);
|
|
@@ -270,38 +307,6 @@ void InitGL()
|
|
|
glVertexAttribPointer(colAttrib, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (void*)(4*sizeof(float)));
|
|
|
glEnableVertexAttribArray(colAttrib);
|
|
|
err = glGetError(); IM_ASSERT(err == GL_NO_ERROR);
|
|
|
-}
|
|
|
-
|
|
|
-void InitImGui()
|
|
|
-{
|
|
|
- int w, h;
|
|
|
- glfwGetWindowSize(window, &w, &h);
|
|
|
-
|
|
|
- ImGuiIO& io = ImGui::GetIO();
|
|
|
- io.DisplaySize = ImVec2((float)w, (float)h);
|
|
|
- io.DeltaTime = 1.0f/60.0f;
|
|
|
- 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;
|
|
|
- io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
|
|
|
- io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
|
|
|
- io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
|
|
|
- io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
|
|
|
- io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
|
|
|
- io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
|
|
|
- io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
|
|
|
- io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
|
|
|
- io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
|
|
|
- io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
|
|
|
- io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
|
|
|
- io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
|
|
- io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
|
|
- io.PixelCenterOffset = 0.5f;
|
|
|
-
|
|
|
- io.RenderDrawListsFn = ImImpl_RenderDrawLists;
|
|
|
- io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
|
|
|
- io.GetClipboardTextFn = ImImpl_GetClipboardTextFn;
|
|
|
|
|
|
// Load font texture
|
|
|
glGenTextures(1, &fontTex);
|
|
@@ -348,10 +353,10 @@ int main(int argc, char** argv)
|
|
|
time = current_time;
|
|
|
double mouse_x, mouse_y;
|
|
|
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
|
|
- io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
|
|
+ io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
|
|
io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0;
|
|
|
io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0;
|
|
|
- io.MouseWheel = (mouse_wheel != 0) ? mouse_wheel > 0.0f ? 1 : - 1 : 0;
|
|
|
+ io.MouseWheel = (mouse_wheel != 0) ? mouse_wheel > 0.0f ? 1 : - 1 : 0; // Mouse wheel: -1,0,+1
|
|
|
mouse_wheel = 0.0f;
|
|
|
ImGui::NewFrame();
|
|
|
|