Difference between revisions of "Mmc-august-2012/Lab3"

From CCRMA Wiki
Jump to: navigation, search
(OpenGL bootup)
(Lab 3 - Sound Flares)
Line 1: Line 1:
 
= Lab 3 - Sound Flares =
 
= 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 can be flung around using multitouch, and make sound when they collide with the walls of their world (which coincide with the sides of your phone's screen).  
+
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 ==
 
== OpenGL bootup ==
Create a new single-view application. Now, we will integrate code from the aptly titled "graphicsStuff" ([https://github.com/downloads/markcerqueira/mobile-music/graphicsStuff.zip download here]). Add all of the files in graphicsStuff to the project. Also, you will need to add <tt>GLKit.framework</tt> and <tt>OpenGLES.framework</tt> to the project, by opening "(Project Name)" in the left sidebar, then "Targets - (Project Name)", then "Build Phases", then "Link Binary With Libraries".  
+
Create a new single-view application. Now, we will integrate code from the aptly titled "graphicsStuff" ([https://github.com/downloads/markcerqueira/mobile-music/graphicsStuff.zip download here]). Add all of the files in graphicsStuff to the project. Also, you will need to add <tt>GLKit.framework</tt> and <tt>OpenGLES.framework</tt> 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 <tt>AppDelegate.m</tt>:
  
Also add <tt>MoAudio</tt> as before, along with <tt>CoreAudio.framework</tt> and <tt>AudioToolbox.framework</tt>. Note that, instead of putting
+
- (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 <tt>GLViewController</tt>, 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 <tt>glClearColor</tt>. The <tt>GLViewController</tt> method <tt>glkView:drawInRect:</tt> is the place where pretty much all OpenGL drawing commands should go; <tt>glClearColor</tt> 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 <tt>MoAudio</tt> as before, along with <tt>CoreAudio.framework</tt> and <tt>AudioToolbox.framework</tt>, as we will soon be mapping audio to the graphics.

Revision as of 03:57, 15 August 2012

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.