added resizing to osx window
This commit is contained in:
@@ -85,7 +85,7 @@ void App::load_layout()
|
||||
std::stack<NodePair> stack;
|
||||
|
||||
tinyxml2::XMLDocument xml;
|
||||
auto ret = xml.LoadFile("data\\layout.xml");
|
||||
auto ret = xml.LoadFile("data/layout.xml");
|
||||
auto x_root = xml.RootElement();
|
||||
|
||||
NodePair current = { y_root, x_root };
|
||||
@@ -299,6 +299,7 @@ void App::init()
|
||||
" frag = col;"
|
||||
"}";
|
||||
|
||||
#ifdef _WIN32
|
||||
static CONSOLE_SCREEN_BUFFER_INFO info;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
|
||||
// colors: http://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c
|
||||
@@ -317,7 +318,8 @@ void App::init()
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), info.wAttributes);
|
||||
}, nullptr);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
|
||||
#endif
|
||||
|
||||
load_layout();
|
||||
|
||||
for (auto& s : shapes_list)
|
||||
@@ -431,10 +433,6 @@ void App::update(float dt)
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(box.x, height - box.y - 1 - box.w, box.z, box.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
//glScissor(10, height - 10 - 1 - 50, 480, 50);
|
||||
|
||||
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
||||
@@ -455,6 +453,7 @@ void App::update(float dt)
|
||||
shader_color.use();
|
||||
shader_color.u_mat4("mvp", mvp);
|
||||
plane.draw_stroke();
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
tex.unbind();
|
||||
sampler.unbind();
|
||||
|
||||
@@ -85,10 +85,18 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
// Add your drawing codes here
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
|
||||
// We draw on a secondary thread through the display link
|
||||
// When resizing the view, -reshape is called automatically on the main
|
||||
// thread. Add a mutex around to avoid the threads accessing the context
|
||||
// simultaneously when resizing
|
||||
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||
App::I.update(now - _prevTime);
|
||||
|
||||
[[self openGLContext] flushBuffer];
|
||||
//[[self openGLContext] flushBuffer];
|
||||
// returning NO will cause the layer to NOT be redrawn
|
||||
|
||||
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
|
||||
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
@@ -111,6 +119,78 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
- (void)drawRect:(NSRect)dirtyRect
|
||||
{
|
||||
NSLog(@"drawRect");
|
||||
// Add your drawing codes here
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
|
||||
// We draw on a secondary thread through the display link
|
||||
// When resizing the view, -reshape is called automatically on the main
|
||||
// thread. Add a mutex around to avoid the threads accessing the context
|
||||
// simultaneously when resizing
|
||||
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||
App::I.update(0);
|
||||
|
||||
//[[self openGLContext] flushBuffer];
|
||||
// returning NO will cause the layer to NOT be redrawn
|
||||
|
||||
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
|
||||
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||
}
|
||||
|
||||
- (void)reshape
|
||||
{
|
||||
[super reshape];
|
||||
|
||||
// We draw on a secondary thread through the display link. However, when
|
||||
// resizing the view, -drawRect is called on the main thread.
|
||||
// Add a mutex around to avoid the threads accessing the context
|
||||
// simultaneously when resizing.
|
||||
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||
|
||||
// Get the view size in Points
|
||||
NSRect viewRectPoints = [self bounds];
|
||||
|
||||
#if SUPPORT_RETINA_RESOLUTION
|
||||
|
||||
// Rendering at retina resolutions will reduce aliasing, but at the potential
|
||||
// cost of framerate and battery life due to the GPU needing to render more
|
||||
// pixels.
|
||||
|
||||
// Any calculations the renderer does which use pixel dimentions, must be
|
||||
// in "retina" space. [NSView convertRectToBacking] converts point sizes
|
||||
// to pixel sizes. Thus the renderer gets the size in pixels, not points,
|
||||
// so that it can set it's viewport and perform and other pixel based
|
||||
// calculations appropriately.
|
||||
// viewRectPixels will be larger than viewRectPoints for retina displays.
|
||||
// viewRectPixels will be the same as viewRectPoints for non-retina displays
|
||||
NSRect viewRectPixels = [self convertRectToBacking:viewRectPoints];
|
||||
|
||||
#else //if !SUPPORT_RETINA_RESOLUTION
|
||||
|
||||
// App will typically render faster and use less power rendering at
|
||||
// non-retina resolutions since the GPU needs to render less pixels.
|
||||
// There is the cost of more aliasing, but it will be no-worse than
|
||||
// on a Mac without a retina display.
|
||||
|
||||
// Points:Pixels is always 1:1 when not supporting retina resolutions
|
||||
NSRect viewRectPixels = viewRectPoints;
|
||||
|
||||
#endif // !SUPPORT_RETINA_RESOLUTION
|
||||
App::I.resize(viewRectPixels.size.width, viewRectPixels.size.height);
|
||||
|
||||
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||
}
|
||||
- (void)renewGState
|
||||
{
|
||||
// Called whenever graphics state updated (such as window resize)
|
||||
|
||||
// OpenGL rendering is not synchronous with other rendering on the OSX.
|
||||
// Therefore, call disableScreenUpdatesUntilFlush so the window server
|
||||
// doesn't render non-OpenGL content in the window asynchronously from
|
||||
// OpenGL content, which could cause flickering. (non-OpenGL content
|
||||
// includes the title bar and drawing done by the app with other APIs)
|
||||
[[self window] disableScreenUpdatesUntilFlush];
|
||||
|
||||
[super renewGState];
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -122,7 +202,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Controller : NSWindowController
|
||||
@interface Controller : NSWindowController<NSWindowDelegate>
|
||||
@end @implementation Controller
|
||||
- (void)keyDown:(NSEvent *)theEvent
|
||||
{
|
||||
@@ -131,6 +211,10 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
{
|
||||
[[NSApplication sharedApplication] terminate:nil];
|
||||
}
|
||||
}
|
||||
- (void)windowDidResize:(NSNotification *)notification
|
||||
{
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -156,10 +240,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
|
||||
view = [[View alloc] initWithFrame:r];
|
||||
|
||||
window = [[Window alloc] initWithContentRect:r
|
||||
styleMask:NSTitledWindowMask|NSMiniaturizableWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
auto style = NSTitledWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask;
|
||||
window = [[Window alloc] initWithContentRect:r styleMask:style backing:NSBackingStoreBuffered defer:NO];
|
||||
[window setTitle:@"hello engine - ui shapes"];
|
||||
[window center];
|
||||
[window makeKeyAndOrderFront:controller];
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl3.h>
|
||||
#include <sys/stat.h>
|
||||
#elif _WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <windows.h>
|
||||
|
||||
@@ -45,7 +45,7 @@ void Shape::draw_stroke() const
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
bool Rect::create(float w, float h)
|
||||
bool RectShape::create(float w, float h)
|
||||
{
|
||||
static GLushort idx[6 + 8] {
|
||||
0, 1, 2,
|
||||
|
||||
@@ -178,7 +178,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class Rect : public Shape
|
||||
class RectShape : public Shape
|
||||
{
|
||||
bool create(float w, float h);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user