Skip to content

Commit

Permalink
Merge pull request #188 from ccawley2011/mingw32
Browse files Browse the repository at this point in the history
Fix compilation with MinGW
  • Loading branch information
CedricGuillemet authored Jul 9, 2021
2 parents 4277f2e + 08dc8a4 commit 7daa4b2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
6 changes: 5 additions & 1 deletion ImCurveEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#include <set>
#include <vector>

#if !defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <malloc.h>
#endif
#if !defined(_MSC_VER) && !defined(__MINGW64_VERSION_MAJOR)
#define _malloca(x) alloca(x)
#define _freea(x)
#endif

namespace ImCurveEdit
Expand Down
8 changes: 5 additions & 3 deletions ImGuizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
#endif
#include "imgui_internal.h"
#include "ImGuizmo.h"
#if !defined(_WIN32)

#if defined(_MSC_VER) || defined(__MINGW32__)
#include <malloc.h>
#endif
#if !defined(_MSC_VER) && !defined(__MINGW64_VERSION_MAJOR)
#define _malloca(x) alloca(x)
#define _freea(x)
#else
#include <malloc.h>
#endif

// includes patches for multiview from
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CXXFLAGS=-std=c++11
CPPFLAGS=-I. -Iexample

LIB_OBJS = ImGuizmo.o GraphEditor.o ImCurveEdit.o ImGradient.o ImSequencer.o
EXAMPLE_OBJS = example/imgui.o example/imgui_draw.o example/imgui_tables.o example/imgui_widgets.o example/main.o

EXAMPLE_NAME = example.exe
LDFLAGS=-mwindows -static-libgcc -static-libstdc++
LIBS=-limm32 -lopengl32 -lgdi32

$(EXAMPLE_NAME): $(LIB_OBJS) $(EXAMPLE_OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)

example/main.o: CXXFLAGS := -std=c++17

clean:
$(RM) $(LIB_OBJS)
$(RM) $(EXAMPLE_OBJS)
$(RM) $(EXAMPLE_NAME)
12 changes: 7 additions & 5 deletions example/ImApp.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <stdint.h> // intptr_t

#if defined(_WIN32)
// dont bother adding library
#pragma comment(lib,"opengl32.lib")
#define WINDOWS_LEAN_AND_MEAN
#include <Windows.h>
#include <GL/GL.h>
# define glGetProcAddress(name) wglGetProcAddress((LPCSTR)name)
# define glGetProcAddress(name) (void *)wglGetProcAddress((LPCSTR)name)
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
# define glGetProcAddress(name) NSGLGetProcAddress(name)
#elif defined(__sgi) || defined(__sun)
Expand Down Expand Up @@ -2579,7 +2581,7 @@ typedef float GLfloat;
#else
#define GLEXTERN
#endif
#ifdef _MSC_VER
#ifdef _WIN32
GLEXTERN void(APIENTRY* glActiveTexture) (GLenum texture);
#endif
GLEXTERN void(APIENTRY* glUniform1i) (GLint location, GLint v0);
Expand Down Expand Up @@ -2699,7 +2701,7 @@ namespace ImApp
info->hInstance = GetModuleHandle(0);

static DEVMODEA screenSettings = { { 0 },
#if _MSC_VER < 1400
#if defined(_MSC_VER) && _MSC_VER < 1400
0,0,148,0,0x001c0000,{ 0 },0,0,0,0,0,0,0,0,0,{ 0 },0,32,config.mWidth,config.mHeight,0,0, // Visual C++ 6.0
#else
0,0,156,0,0x001c0000,{ 0 },0,0,0,0,0,{ 0 },0,32,static_cast<DWORD>(config.mWidth), static_cast<DWORD>(config.mHeight),{ 0 }, 0, // Visuatl Studio 2005
Expand Down Expand Up @@ -2996,7 +2998,7 @@ namespace ImApp

LE(glUniform1i); //GLint location, GLint v0);
LE(glUniformMatrix3fv) // GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
#ifdef _MSC_VER
#ifdef _WIN32
LE(glActiveTexture); //GLenum texture);
#endif
LE(glBindFramebuffer); //GLenum target, TextureID framebuffer);
Expand Down Expand Up @@ -3085,7 +3087,7 @@ namespace ImApp
static bool IsAnyMouseButtonDown()
{
ImGuiIO& io = ImGui::GetIO();
for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++)
for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++)
if (io.MouseDown[n])
return true;
return false;
Expand Down
12 changes: 3 additions & 9 deletions example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "imgui.h"
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui_internal.h"
#define IMAPP_IMPL
#include "ImApp.h"

Expand All @@ -11,14 +13,6 @@
#include <vector>
#include <algorithm>

#include "imgui_internal.h"
//
//
// ImGuizmo example helper functions
//
//
static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); }

bool useWindow = true;
int gizmoCount = 1;
float camDistance = 8.f;
Expand Down Expand Up @@ -398,7 +392,7 @@ struct MySequence : public ImSequencer::SequenceInterface
virtual const char* GetItemLabel(int index) const
{
static char tmps[512];
sprintf_s(tmps, "[%02d] %s", index, SequencerItemTypeNames[myItems[index].mType]);
snprintf(tmps, 512, "[%02d] %s", index, SequencerItemTypeNames[myItems[index].mType]);
return tmps;
}

Expand Down

0 comments on commit 7daa4b2

Please sign in to comment.