Mmc-august-2012/Lab3

From CCRMA Wiki
Revision as of 03:57, 15 August 2012 by Spencer (Talk | contribs) (Lab 3 - Sound Flares)

Jump to: navigation, search

Lab 3 - Sound Flares

In this lab, we will experiment with interaction between real-time sound and graphics using OpenGL. The goal is to build a graphical world inhabited by "flares". These graphical particles will follow your fingers around as you touch the screen, and make sound corresponding to their location on screen.

OpenGL bootup

Create a new single-view application. Now, we will integrate code from the aptly titled "graphicsStuff" (download here). Add all of the files in graphicsStuff to the project. Also, you will need to add GLKit.framework and OpenGLES.framework to the project, by opening "(Project Name)" in the left sidebar, then "Targets - (Project Name)", then "Build Phases", then "Link Binary With Libraries". Change this part of AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

to this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.rootViewController = [[GLViewController alloc] init];
    [self.window makeKeyAndVisible];
    return YES;
}

This will make GLViewController, which draws itself using OpenGL, the primary view of the application. Test that you have everything working by changing the background color to red, using glClearColor. The GLViewController method glkView:drawInRect: is the place where pretty much all OpenGL drawing commands should go; glClearColor is already in this method, so you can just change the specified color from black (0,0,0,1) to red (1,0,01).

Also add MoAudio as before, along with CoreAudio.framework and AudioToolbox.framework, as we will soon be mapping audio to the graphics.