From e1bb27a3856a51952d5e2f9ede7ca784333ac3ba Mon Sep 17 00:00:00 2001 From: Dan O'Shea Date: Mon, 11 Aug 2014 17:51:27 -0700 Subject: [PATCH 1/3] Adding Makefile for MacOS --- examples/opengl_example/Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/opengl_example/Makefile diff --git a/examples/opengl_example/Makefile b/examples/opengl_example/Makefile new file mode 100644 index 000000000..474208345 --- /dev/null +++ b/examples/opengl_example/Makefile @@ -0,0 +1,17 @@ +# This makefile currently only works for mac os +# You should install via homebrew: +# brew install glew +# brew install glfw3 +# + +CXXFLAGS=-framework OpenGL -framework Cocoa -framework IOKit +#CXXFLAGS+=-L/usr/local/Cellar/glew/1.10.0/lib -L/usr/local/Cellar/glfw3/3.0.4/lib +CXXFLAGS+=-lglew -lglfw3 +CXXFLAGS+=-I../../ +CXXFLAGS+= -D__APPLE__ + +main: main.cpp ../../imgui.cpp + $(CXX) $(CXXFLAGS) -o $@ $^ + +clean: + rm main From ac7474e36b666fac9939efd2b54ee48b5c31fbc0 Mon Sep 17 00:00:00 2001 From: Dan O'Shea Date: Mon, 11 Aug 2014 17:51:49 -0700 Subject: [PATCH 2/3] OpenGL context 3.2 for MacOS --- examples/opengl_example/main.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index dfad6e345..6ebab899a 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -8,6 +8,10 @@ #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif +#ifdef __APPLE__ +#define nullptr NULL +#endif + static GLFWwindow* window; static GLuint vbo; static GLuint vao; @@ -39,7 +43,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert); } glUnmapBuffer(GL_ARRAY_BUFFER); - + // Setup render state: alpha-blending enabled, no face culling, no depth testing glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -55,7 +59,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c // Setup orthographic projection matrix const float width = ImGui::GetIO().DisplaySize.x; const float height = ImGui::GetIO().DisplaySize.y; - const float mvp[4][4] = + const float mvp[4][4] = { { 2.0f/width, 0.0f, 0.0f, 0.0f }, { 0.0f, 2.0f/-height, 0.0f, 0.0f }, @@ -149,7 +153,7 @@ const GLchar* fragmentSource = "out vec4 o_col;" "void main() {" " o_col = texture(Tex, uv) * col;" - //" if (pixel_pos.x < ClipRect.x || pixel_pos.y < ClipRect.y || pixel_pos.x > ClipRect.z || pixel_pos.y > ClipRect.w) discard;" // Clipping: using discard + //" if (pixel_pos.x < ClipRect.x || pixel_pos.y < ClipRect.y || pixel_pos.x > ClipRect.z || pixel_pos.y > ClipRect.w) discard;" // Clipping: using discard //" if (step(ClipRect.x,pixel_pos.x) * step(ClipRect.y,pixel_pos.y) * step(pixel_pos.x,ClipRect.z) * step(pixel_pos.y,ClipRect.w) < 1.0f) discard;" // Clipping: using discard and step " o_col.w *= (step(ClipRect.x,pixel_pos.x) * step(ClipRect.y,pixel_pos.y) * step(pixel_pos.x,ClipRect.z) * step(pixel_pos.y,ClipRect.w));" // Clipping: branch-less, set alpha 0.0f "}"; @@ -191,10 +195,12 @@ void InitGL() if (!glfwInit()) exit(1); - //glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - //glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#ifdef __APPLE__ + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif glfwWindowHint(GLFW_REFRESH_RATE, 60); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", nullptr, nullptr); @@ -208,7 +214,8 @@ void InitGL() glewInit(); GLenum err = GL_NO_ERROR; - err = glGetError(); IM_ASSERT(err == GL_NO_ERROR); + err = glGetError(); + //IM_ASSERT(err == GL_NO_ERROR); } void InitImGui() From d7b8d9f6d82e60ebf38ea59c5562fa3104f52cc5 Mon Sep 17 00:00:00 2001 From: Dan O'Shea Date: Mon, 11 Aug 2014 17:52:26 -0700 Subject: [PATCH 3/3] Adding MacOS build instructions to README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index efd9fb0ff..2b6689e3b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,18 @@ After ImGui is setup in your application, you can use it like in this example: ImGui outputs vertex buffers and simple command-lists that you can render in your application. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate ImGui with your existing codebase. +Building on Mac OS +------------------ + +Omar Cornut @ocornut wrote this, I (@djoshea) simply added a Makefile and made minor tweaks to build and run successfully on MacOS Mavericks. +You will need to edit paths there once the versions in Homebrew change. + +``` +brew install glew +brew install glfw3 +cd examples/opengl_example/ +make +``` Gallery -------