131 lines
3.1 KiB
Objective-C
131 lines
3.1 KiB
Objective-C
//
|
|
// 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)setupGL;
|
|
- (void)tearDownGL;
|
|
@end
|
|
|
|
@implementation GameViewController
|
|
|
|
- (void)touchesBegan:(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_down(0, touchLocation.x * scale, touchLocation.y * scale);
|
|
}
|
|
- (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)touchesEnded:(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_up(0, 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
|