Overloaded touch functions in child of UIView not working
I am trying to get touch input functionality in the in an OpenGLES application but am having a trouble getting it working. Any help with this problem would be very much appreciated.
I have compared this to many examples and cannot see what is missing that is causing this problem.
None of the four touch functions are getting called in my code (touchesBegan, touchesMoved, touchesEnded and touchesCancelled).
CFiOSAppDelegate.h:
#pragma once
#ifndef __CFIOSAPPDELEGATE_H__
#define __CFIOSAPPDELEGATE_H__
#include "ICFApplication.h"
#include "CFiOSEAGLView.h"
@interface CFiOSAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow* m_pWindow;
CFiOSEAGLView* m_pCFiOSEAGLView;
NSTimer* m_pAnimationTimer;
ICFApplication* m_pTheApp;
}
@property (nonatomic, retain) UIWindow* m_pWindow;
@property (nonatomic, retain) CFiOSEAGLView* m_pCFiOSEAGLView;
-(void) startAnimationWithInterval: (NSTimeInterval) interval;
@end
#endif
CFiOSAppDelegate.mm
#include "CFiOSAppDelegate.h"
#include "CFiOSEAGLView.h"
#include "CFPlatformiOS.h"
// Static Function Prototypes
extern ICFApplication* CreateiOSApplication();
// Implementation
@implementation CFiOSAppDelegate
@synthesize m_pWindow;
@synthesize m_pCFiOSEAGLView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
m_pWindow = [[UIWindow alloc ] initWithFrame:[[UIScreen mainScreen] bounds]];
[m_pWindow setUserInteractionEnabled:YES];
[m_pWindow setMultipleTouchEnabled:YES];
[m_pWindow makeKeyAndVisible];
m_pCFiOSEAGLView = [[CFiOSEAGLView alloc] initWithFrame:m_pWindow.frame];
[ m_pWindow addSubview:m_pCFiOSEAGLView ];
// Setup the EAGL layer for the new view
CAEAGLLayer* pEAGLLayer = static_cast< CAEAGLLayer* >(m_pCFiOSEAGLView.layer);
pEAGLLayer.opaque = YES;
pEAGLLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool: NO],
kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8,
kEAGLDrawablePropertyColorFormat,
nil];
m_pCFiOSEAGLView.m_pEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
[EAGLContext setCurrentContext:m_pCFiOSEAGLView.m_pEAGLContext];
//create App
m_pTheApp = CreateiOSApplication();
//init App
m_pTheApp->Initialise();
[ m_pCFiOSEAGLView becomeFirstResponder ];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self startAnimationWithInterval: 1.0 / 60.0];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
-(void) startAnimationWithInterval:(NSTimeInterval)interval
{
if( m_pAnimationTimer )
{
[m_pAnimationTimer invalidate];
m_pAnimationTimer = NULL;
}
if( !m_pTheApp )
return;
m_pAnimationTimer = [NSTimer scheduledTimerWithTimeInterval: interval target: self selector: @selector(frameUpdate) userInfo: nil repeats: YES];
}
- (void)dealloc
{
[EAGLContext setCurrentContext:nil];
[m_pCFiOSEAGLView release];
[m_pWindow release];
[super dealloc];
}
-(void) frameUpdate
{
//run the game in here.
m_pTheApp->Run();
}
@end
CFiOSEAGLView.h
#pragma once
#ifndef __CFIOSEAGLVIEW_H__
#define __CFIOSEAGLVIEW_H__
#import <UIKit/UIKit.h>
typedef enum
{
UNIFORM_TRANSLATE,
NUM_UNIFORMS
} eUNIFORM_INDEX;
typedef enum
{
ATTRIB_VERTEX,
ATTRIB_COLOUR,
NUM_ATTRIBUTES
} eATTRIBUTE_INDEX;
@interface CFiOSEAGLView : UIView
{
@private
EAGLContext* m_pEAGLContext;
i32 m_iFrameBufferWidth;
i32 m_iFrameBufferHeight;
u32 m_uiFrameBufferID;
u32 m_uiRenderBufferID;
}
@property (nonatomic, retain) EAGLContext* m_pEAGLContext;
@end
#endif
CFiOSEAGLView.mm
#import <QuartzCore/QuartzCore.h>
#include "CFRendererOpenGLES.h"
#include "CFiOSEAGLView.h"
@implementation CFiOSEAGLView
@synthesize m_pEAGLContext;
// You must implement this method
+ (Class)layerClass
{
return [CAEAGLLayer class];
}
- (void)layoutSubviews
{
m_uiFrameBufferID = 0;
m_uiRenderBufferID = 0;
// Create and bind a frame buffer
glGenFramebuffersOES(1, &m_uiFrameBufferID);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_uiFrameBufferID);
// Create and bind a render buffer, set it to be the primary color output of the frame buffer
glGenRenderbuffersOES(1, &m_uiRenderBufferID);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_uiRenderBufferID);
// Tell the layer to display the contents of the main render buffer
[m_pEAGLContext renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: static_cast< CAEAGLLayer *>(self.layer)];
// Get the dimensions of the render buffer
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &m_iFrameBufferWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &m_iFrameBufferHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, m_uiRenderBufferID);
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
CFDebug::PrintError("Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CFDebug::Print("Touch began");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CFDebug::Print("Touch move");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CFDebug::Print("touches work!");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
CFDebug::Print("touches work!");
}
@end
iPhone 4, iOS 4.2