add iOS support
This commit is contained in:
119
PanoPainter/GameViewController.m
Normal file
119
PanoPainter/GameViewController.m
Normal file
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// GameViewController.m
|
||||
// PanoPainter
|
||||
//
|
||||
// Created by Omar Mohamed Ali Mudhir on 07/05/17.
|
||||
// Copyright © 2017 Omar Mohamed Ali Mudhir. All rights reserved.
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#import "GameViewController.h"
|
||||
#import <OpenGLES/ES3/glext.h>
|
||||
#include "app.h"
|
||||
|
||||
@interface GameViewController () {
|
||||
}
|
||||
@property (strong, nonatomic) EAGLContext *context;
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator;
|
||||
- (void)setupGL;
|
||||
- (void)tearDownGL;
|
||||
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
|
||||
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
|
||||
@end
|
||||
|
||||
@implementation GameViewController
|
||||
|
||||
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
CGPoint touchLocation = [touch locationInView:self.view];
|
||||
float scale = self.view.contentScaleFactor;
|
||||
App::I.mouse_move(touchLocation.x * scale, touchLocation.y * scale);
|
||||
}
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
||||
{
|
||||
App::I.resize(size.width * self.view.contentScaleFactor,
|
||||
size.height * self.view.contentScaleFactor);
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
App::I.initLog();
|
||||
|
||||
|
||||
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
||||
|
||||
if (!self.context) {
|
||||
NSLog(@"Failed to create ES context");
|
||||
}
|
||||
|
||||
GLKView *view = (GLKView *)self.view;
|
||||
view.context = self.context;
|
||||
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
|
||||
|
||||
App::I.width = view.frame.size.width * view.contentScaleFactor;
|
||||
App::I.height = view.frame.size.height * view.contentScaleFactor;
|
||||
|
||||
[self setupGL];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self tearDownGL];
|
||||
|
||||
if ([EAGLContext currentContext] == self.context) {
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
{
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
if ([self isViewLoaded] && ([[self view] window] == nil)) {
|
||||
self.view = nil;
|
||||
|
||||
[self tearDownGL];
|
||||
|
||||
if ([EAGLContext currentContext] == self.context) {
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
}
|
||||
self.context = nil;
|
||||
}
|
||||
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setupGL
|
||||
{
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
App::I.init();
|
||||
}
|
||||
|
||||
- (void)tearDownGL
|
||||
{
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - GLKView and GLKViewController delegate methods
|
||||
|
||||
- (void)update
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
|
||||
{
|
||||
App::I.clear();
|
||||
App::I.update(0);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user