From 2024b3a280fa3bbf188b112c17fc0ed1621cc74c Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 28 Mar 2017 09:08:53 +0100 Subject: [PATCH] fixes for mac --- engine.xcodeproj/project.pbxproj | 30 ++++++++++++++++++++++++++++++ engine/font.cpp | 2 +- engine/layout.h | 14 +++++++++++++- engine/main.cpp | 15 ++++++++++++++- engine/pch.h | 9 ++++++--- engine/util.cpp | 2 +- 6 files changed, 65 insertions(+), 7 deletions(-) diff --git a/engine.xcodeproj/project.pbxproj b/engine.xcodeproj/project.pbxproj index edf8c7f..6c3b398 100644 --- a/engine.xcodeproj/project.pbxproj +++ b/engine.xcodeproj/project.pbxproj @@ -8,6 +8,11 @@ /* Begin PBXBuildFile section */ AD3B1EC01E3B8B7600E918E3 /* layout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD3B1EBE1E3B8B7600E918E3 /* layout.cpp */; }; + AD4C08D91E89BD0F0051D85F /* asset.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4C08CF1E89BD0F0051D85F /* asset.cpp */; }; + AD4C08DA1E89BD0F0051D85F /* bezier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4C08D11E89BD0F0051D85F /* bezier.cpp */; }; + AD4C08DB1E89BD0F0051D85F /* brush.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4C08D31E89BD0F0051D85F /* brush.cpp */; }; + AD4C08DC1E89BD0F0051D85F /* canvas.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4C08D51E89BD0F0051D85F /* canvas.cpp */; }; + AD4C08DD1E89BD0F0051D85F /* rtt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4C08D71E89BD0F0051D85F /* rtt.cpp */; }; AD58E0531E107411006ACC15 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0521E107411006ACC15 /* main.cpp */; }; AD58E05A1E10752E006ACC15 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD58E0591E10752E006ACC15 /* OpenGL.framework */; }; AD58E05C1E107536006ACC15 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD58E05B1E107536006ACC15 /* Cocoa.framework */; }; @@ -43,6 +48,16 @@ /* Begin PBXFileReference section */ AD3B1EBE1E3B8B7600E918E3 /* layout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = layout.cpp; sourceTree = ""; }; AD3B1EBF1E3B8B7600E918E3 /* layout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = layout.h; sourceTree = ""; }; + AD4C08CF1E89BD0F0051D85F /* asset.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = asset.cpp; sourceTree = ""; }; + AD4C08D01E89BD0F0051D85F /* asset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asset.h; sourceTree = ""; }; + AD4C08D11E89BD0F0051D85F /* bezier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bezier.cpp; sourceTree = ""; }; + AD4C08D21E89BD0F0051D85F /* bezier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bezier.h; sourceTree = ""; }; + AD4C08D31E89BD0F0051D85F /* brush.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = brush.cpp; sourceTree = ""; }; + AD4C08D41E89BD0F0051D85F /* brush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = brush.h; sourceTree = ""; }; + AD4C08D51E89BD0F0051D85F /* canvas.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = canvas.cpp; sourceTree = ""; }; + AD4C08D61E89BD0F0051D85F /* canvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = canvas.h; sourceTree = ""; }; + AD4C08D71E89BD0F0051D85F /* rtt.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rtt.cpp; sourceTree = ""; }; + AD4C08D81E89BD0F0051D85F /* rtt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtt.h; sourceTree = ""; }; AD58E04F1E107411006ACC15 /* engine */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = engine; sourceTree = BUILT_PRODUCTS_DIR; }; AD58E0521E107411006ACC15 /* main.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; path = main.cpp; sourceTree = ""; }; AD58E0591E10752E006ACC15 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; @@ -111,6 +126,16 @@ AD58E0511E107411006ACC15 /* engine */ = { isa = PBXGroup; children = ( + AD4C08CF1E89BD0F0051D85F /* asset.cpp */, + AD4C08D01E89BD0F0051D85F /* asset.h */, + AD4C08D11E89BD0F0051D85F /* bezier.cpp */, + AD4C08D21E89BD0F0051D85F /* bezier.h */, + AD4C08D31E89BD0F0051D85F /* brush.cpp */, + AD4C08D41E89BD0F0051D85F /* brush.h */, + AD4C08D51E89BD0F0051D85F /* canvas.cpp */, + AD4C08D61E89BD0F0051D85F /* canvas.h */, + AD4C08D71E89BD0F0051D85F /* rtt.cpp */, + AD4C08D81E89BD0F0051D85F /* rtt.h */, AD95AEC31E41EDEC002DD03A /* font.cpp */, AD95AEC41E41EDEC002DD03A /* font.h */, AD95AEC51E41EDEC002DD03A /* pch.cpp */, @@ -203,15 +228,20 @@ AD58E0791E342205006ACC15 /* tinyxml2.cpp in Sources */, AD58E06F1E2A80BC006ACC15 /* shape.cpp in Sources */, AD58E0651E2A76FD006ACC15 /* shader.cpp in Sources */, + AD4C08DA1E89BD0F0051D85F /* bezier.cpp in Sources */, AD58E0761E3421F2006ACC15 /* YGNodeList.c in Sources */, ADB61C821E3D38450093280F /* util.cpp in Sources */, + AD4C08DD1E89BD0F0051D85F /* rtt.cpp in Sources */, AD58E06B1E2A774F006ACC15 /* texture.cpp in Sources */, AD3B1EC01E3B8B7600E918E3 /* layout.cpp in Sources */, AD58E0721E2A90EF006ACC15 /* app.cpp in Sources */, + AD4C08DC1E89BD0F0051D85F /* canvas.cpp in Sources */, AD95AEC61E41EDEC002DD03A /* font.cpp in Sources */, AD58E0531E107411006ACC15 /* main.cpp in Sources */, + AD4C08D91E89BD0F0051D85F /* asset.cpp in Sources */, AD58E0681E2A7741006ACC15 /* image.cpp in Sources */, AD58E0771E3421F2006ACC15 /* Yoga.c in Sources */, + AD4C08DB1E89BD0F0051D85F /* brush.cpp in Sources */, AD95AEC71E41EDEC002DD03A /* pch.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/engine/font.cpp b/engine/font.cpp index b76c553..9cdfa20 100644 --- a/engine/font.cpp +++ b/engine/font.cpp @@ -16,7 +16,7 @@ bool Font::load(const char* ttf, int font_size) auto bitmap = std::make_unique(w*h); chars.resize(num_chars); int ret = stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size, bitmap.get(), w, h, start_char, num_chars, chars.data()); - font_tex.create(w, h, GL_LUMINANCE, bitmap.get()); + font_tex.create(w, h, GL_RED, bitmap.get()); file.close(); return true; } diff --git a/engine/layout.h b/engine/layout.h index 3f55892..6ba3dee 100644 --- a/engine/layout.h +++ b/engine/layout.h @@ -1482,7 +1482,7 @@ public: init_template("tpl-panel-brushes"); //m_layers_container = find("layers-container"); static auto icons = FindAllBrushes("data/Icons/"); - if (m_container = find("brushes")) + if ((m_container = find("brushes"))) { int count = 0; for (auto& i : icons) @@ -1538,6 +1538,18 @@ public: } AAssetDir_close(dir); #else + DIR *dp; + struct dirent *ep; + dp = opendir(folder.c_str()); + + if (dp != NULL) + { + while (ep = readdir (dp)) + names.push_back(ep->d_name); + closedir(dp); + } + else + LOG("Couldn't open the directory: %s", folder.c_str()); #endif return names; } diff --git a/engine/main.cpp b/engine/main.cpp index e30c9fe..b4e8a83 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -194,18 +194,31 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime } - (void)mouseDown:(NSEvent *)theEvent { + CGLLockContext([[self openGLContext] CGLContextObj]); auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; App::I.mouse_down(0, mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); } - (void)mouseUp:(NSEvent *)theEvent { + CGLLockContext([[self openGLContext] CGLContextObj]); auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; App::I.mouse_up(0, mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); } - (void)mouseMoved:(NSEvent *)theEvent { + CGLLockContext([[self openGLContext] CGLContextObj]); auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} +-(void)mouseDragged:(NSEvent *)theEvent +{ + CGLLockContext([[self openGLContext] CGLContextObj]); + auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); } @end @@ -257,7 +270,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime auto style = NSTitledWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask; window = [[Window alloc] initWithContentRect:r styleMask:style backing:NSBackingStoreBuffered defer:NO]; - [window setTitle:@"hello engine - ui shapes"]; + [window setTitle:@"PanoPainter 0.1.2 alpha"]; [window center]; [window makeKeyAndOrderFront:controller]; [window setContentView:view]; diff --git a/engine/pch.h b/engine/pch.h index 34ff803..a73d97c 100644 --- a/engine/pch.h +++ b/engine/pch.h @@ -1,13 +1,16 @@ //#pragma once -#define USE_VBO 0 +#define USE_VBO 1 #define USE_SAMPLER 1 #ifdef __APPLE__ #include #include - #define LOG printf - #define SHADER_VERSION "#version 300 es\n" + #include + #include + + #define LOG(M,...) printf(M"\n", ##__VA_ARGS__) + #define SHADER_VERSION "#version 150\n" #elif __ANDROID__ #include diff --git a/engine/util.cpp b/engine/util.cpp index f247e3e..f7a3337 100644 --- a/engine/util.cpp +++ b/engine/util.cpp @@ -31,5 +31,5 @@ glm::vec3 convert_rgb2hsv(const glm::vec3 c) glm::vec4 q = c.r < p.x ? glm::vec4(p.xyw, c.r) : glm::vec4(c.r, p.yzx); float d = q.x - glm::min(q.w, q.y); float e = 1.0e-10f; - return glm::vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); + return glm::vec3(fabs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); }