void loadProgram(Program &p, const std::string& name) { //can't link shaders unless a vao is bound... //bindDefaultVAO(); p.create(); string sv = rh.pathToResource(name, "vsh"); p.attach(rh.contentsOfFile(sv), GL_VERTEX_SHADER); glBindAttribLocation(p.id(), posLoc, "vertexPosition"); glBindAttribLocation(p.id(), texCoordLoc, "vertexTexCoord"); string sg = rh.pathToResource(name, "gsh"); cout << "path of vertex shader is: " << sg << endl; p.attach(rh.contentsOfFile(sg), GL_GEOMETRY_SHADER); string sp = rh.pathToResource(name, "fsh"); p.attach(rh.contentsOfFile(sp), GL_FRAGMENT_SHADER); p.link(); }
void loadProgram(Program &p, const std::string& name) { //Initializes a Program object p.create(); //Gets the path to the vertex shader (ending in ".vsh") string sv = rh.pathToResource(name, "vsh"); // cout << "path of vertex shader is: " << sv << endl; //Compiles the vertex shader and attaches it to our Program object p.attach(rh.contentsOfFile(sv), GL_VERTEX_SHADER); //Binds attribute variables to a particular ID glBindAttribLocation(p.id(), posLoc, "vertexPosition"); glBindAttribLocation(p.id(), colLoc, "vertexColor"); //Gets the path to the fragment shader (ending in ".fsh") string sp = rh.pathToResource(name, "fsh"); // cout << "path of vertex shader is: " << sp << endl; //Compiles the fragment shader and attaches it to our Program object p.attach(rh.contentsOfFile(sp), GL_FRAGMENT_SHADER); //Links the Program object to the GPU so that it can be activated when needed p.link(); }
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); }