Skip to content

Commit

Permalink
Resize GLView on Window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
jhanssen committed Sep 4, 2017
1 parent 6d186b3 commit df1895b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions clients/mac/View.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ -(void) drawRect: (NSRect) bounds
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
if (texture) {
GLfloat texMatrix[16] = {0};
GLfloat texMatrix[16] = {0};
GLint saveMatrixMode;

// Reverses and normalizes the texture
Expand All @@ -65,7 +65,6 @@ -(void) drawRect: (NSRect) bounds

glGetIntegerv(GL_MATRIX_MODE, &saveMatrixMode);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadMatrixf(texMatrix);
glMatrixMode(saveMatrixMode);

Expand All @@ -84,6 +83,19 @@ -(void) drawRect: (NSRect) bounds
}
@end

@interface WindowController : NSWindowController <NSWindowDelegate> {
@public GLView* view;
@public NSWindow* window;
}
@end

@implementation WindowController
- (void)windowDidResize:(NSNotification *)notification {
glViewport(0, 0, window.frame.size.width, window.frame.size.height);
[view setNeedsDisplay:YES];
}
@end

class ViewPrivate
{
public:
Expand Down Expand Up @@ -207,6 +219,10 @@ static void audioOutput(void *inClientData, AudioQueueRef inAQ,
[window center];
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];

WindowController* controller = [[WindowController alloc] init];
controller->window = window;
[window setDelegate:controller];

NSView* content_view = [window contentView];
[content_view setAutoresizesSubviews:YES];
GLView* glview = [[[GLView alloc]
Expand All @@ -216,6 +232,8 @@ static void audioOutput(void *inClientData, AudioQueueRef inAQ,
[content_view addSubview:glview];
[glview retain];

controller->view = glview;

glview->texture = 0;
glview->width = w;
glview->height = h;
Expand Down

0 comments on commit df1895b

Please sign in to comment.