void onCreate() {
    
    rh.loadTexture(texture, "resources/hubble.jpg");
    texture.minFilter(GL_NEAREST);
    texture.maxFilter(GL_NEAREST);
    
    rh.loadProgram(textureProgram, "resources/texture", posLoc, -1, texCoordLoc, -1);
    rh.loadProgram(phongProgram, "resources/phong", posLoc, normalLoc, texCoordLoc, -1);
    rh.loadProgram(programColor, "resources/color", posLoc, normalLoc, -1, colorLoc);
    
    MeshData md1;
    addCube(md1, true, 0.95);
    
    MeshData md2;
    addCube(md2, true, 0.5);
    
    MeshData md3;
    addCube(md3, 0.33); //this version makes normals, texcoords, and colors each side with a different default color
    
    cubeMeshBuffer1.init(md1, posLoc, normalLoc, texCoordLoc, -1);
    cubeMeshBuffer2.init(md2, posLoc, normalLoc, texCoordLoc, -1);
    
    cubeMeshBuffer3.init(md3, posLoc, normalLoc, -1, colorLoc);
    
    
    fbo.create(32, 32);

millisToNano(1000);
    
    rotateBehavior = Behavior(now()).delay(1000).length(5000).range(vec3(3.14, 3.14, 3.14)).reversing(true).repeats(-1).sine();
    
    
    proj = glm::perspective(45.0, 1.0, 0.1, 100.0);
    view = glm::lookAt(vec3(0.0,0.0,5), vec3(0,0,0), vec3(0,1,0) );
    model = glm::mat4();
    
    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, width, height);
  }
  virtual void onCreate() {

    rh.loadProgram(program, "week5a_NoiseDisplacement/noise", posLoc, normalLoc, -1, -1);

    int res = 250;
    addSphere(mesh, 1.0, res, res);

    mb.init(mesh, posLoc, normalLoc, -1, -1);

    proj = glm::perspective(glm::radians(60.0), 1.0, 0.1, 1000.0);
    view = glm::lookAt(vec3(0.0,0.0, -4.0), vec3(0,0,0), vec3(0,1,0) );
    model = glm::mat4();

    glEnable(GL_DEPTH_TEST);
    glClearColor(1.0,1.0,1.0,1.0);

    rotateBehavior = Behavior(now()).delay(0).length(10000).range(M_PI * 2.0).looping(true).repeats(-1);
  }
  virtual void onCreate() {

    rh.loadProgram(planetProgram, "week5c_ImageDistortation/planet", 0, -1, -1, -1);

    mb.init(MeshUtils::makeClipRectangle(), 0, -1, -1, -1);

    rh.loadCubeMapTexture(cubemap[0], 2048, 2048,
                          "week5c_ImageDistortation/f_negz.jpg",
                          "week5c_ImageDistortation/f_posz.jpg",
                          "week5c_ImageDistortation/f_posy.jpg",
                          "week5c_ImageDistortation/f_negy.jpg",
                          "week5c_ImageDistortation/f_negx.jpg",
                          "week5c_ImageDistortation/f_posx.jpg");

    rh.loadCubeMapTexture(cubemap[1], 2048, 2048,
                          "week5c_ImageDistortation/b_negz.jpg",
                          "week5c_ImageDistortation/b_posz.jpg",
                          "week5c_ImageDistortation/b_posy.jpg",
                          "week5c_ImageDistortation/b_negy.jpg",
                          "week5c_ImageDistortation/b_negx.jpg",
                          "week5c_ImageDistortation/b_posx.jpg");
  }
Example #4
0
  virtual void onCreate() {

    rh.loadProgram(skyboxProgram, "week5b_CubeMapping/skybox", posLoc, -1, -1, -1);
    rh.loadProgram(environmentMappingProgram, "week5b_CubeMapping/envMap", posLoc, normalLoc, -1, -1);

    MeshData cube;
    addCube(cube, 8.0);
    cubeMeshBuffer.init(cube, posLoc, normalLoc, -1, -1);
    cubeModel = mat4();
    cubeModel = glm::translate(cubeModel, vec3(0.0,0.0,40));


    obj::Model m = obj::loadModelFromFile(rh.pathToResource("week5b_CubeMapping/dragon.obj"));

    MeshData dragonMesh;

    for(std::map<std::string, std::vector<unsigned short> >::const_iterator g = m.faces.begin(); g != m.faces.end(); ++g) {

      for (int i = 0 ; i < g->second.size() ; i++) {

        dragonMesh.index(g->second[i]);
      }
    }


    for (int i = 0; i < m.vertex.size(); i+=3) {
      vec3 pos = vec3(m.vertex[i], m.vertex[i+1], m.vertex[i+2]);
      pos *= 30;
      dragonMesh.vertex(pos);
    }

    for (int i = 0; i < m.normal.size(); i+=3) {
      dragonMesh.normal(m.normal[i], m.normal[i+1], m.normal[i+2]);
    }

    dragonMeshBuffer.init(dragonMesh, posLoc, normalLoc, -1, -1);
    dragonModel = glm::mat4();
    dragonModel = glm::translate(dragonModel, vec3(0.0, -1.2, 30.0));

    MeshData skybox;
    addCube(skybox, 100.0);
    skyboxMeshBuffer.init(skybox, posLoc, -1, -1, -1);


    //create the cube map texture
    rh.loadCubeMapTexture(cmt, 2048, 2048,
                          "week5b_CubeMapping/negz.jpg",
                          "week5b_CubeMapping/posz.jpg",
                          "week5b_CubeMapping/posy.jpg",
                          "week5b_CubeMapping/negy.jpg",
                          "week5b_CubeMapping/negx.jpg",
                          "week5b_CubeMapping/posx.jpg");


    rotateBehavior = Behavior(now()).delay(1000).length(10000).range(vec3(glm::radians(360.0))).looping(true).repeats(-1);

    camera = Camera(glm::radians(60.0), (float)width/(float)height, 0.01, 1000.0);

    glEnable(GL_DEPTH_TEST);

  }