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();
	}
Beispiel #2
0
  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();
  }
Program ResourceCreator::createProgram(const char* pVertexShaderName, const char* pFragmentShaderName)
{
    Program program;

    std::string vertexShaderFilename = std::string("./data/shaders/") + pVertexShaderName + ".vert";
    std::string fragmentShaderFilename = std::string("./data/shaders/") + pFragmentShaderName + ".frag";


    std::string vertShaderSource = ReadFile(vertexShaderFilename.c_str());
    if (vertShaderSource.length() == 0)
    {
        std::cerr << "Couldn't read file: " << vertexShaderFilename << std::endl;
        return program;
    }


    std::string fragShaderSource = ReadFile(fragmentShaderFilename.c_str());
    if (fragShaderSource.length() == 0) {
        std::cerr << "Couldn't read file: " << fragmentShaderFilename << std::endl;
        return program;
    }

    if (!program.create(vertShaderSource.c_str(), fragShaderSource.c_str()))
    {
        std::cerr << "Failed to make program with vertex shader " << vertexShaderFilename << " and fragment shader " << fragmentShaderFilename << "." << std::endl;
        return program;
    }

    return program;
}
Beispiel #4
0
 Program create(std::string const& vertShaderPath, std::string const& fragShaderPath, IncludeCommonCode icc)
 {
     Program prog;
     prog.create(vertShaderPath, fragShaderPath);
     ShaderFiles sf = ShaderFiles(vertShaderPath, lastModifyTime(vertShaderPath), std::string(), static_cast<std::uint64_t>(0), fragShaderPath, lastModifyTime(fragShaderPath));
     mProgs.emplace_back(prog, sf);
     return prog;
 }
Beispiel #5
0
 Program create(std::string const& vertShaderPath, std::string const& geomShaderPath, std::string const& fragShaderPath, IncludeCommonCode icc)
 {
     Program prog;
     prog.create(vertShaderPath, geomShaderPath, fragShaderPath);
     ShaderFiles sf{ vertShaderPath, lastModifyTime(vertShaderPath), geomShaderPath, lastModifyTime(geomShaderPath), fragShaderPath, lastModifyTime(fragShaderPath) };
     mProgs.emplace_back(prog, sf);
     return prog;
 }
  void loadProgram(Program &p, const std::string& name) {

    p.create();

    p.attach(p.loadText(name + ".vsh"), GL_VERTEX_SHADER);
    glBindAttribLocation(p.id(), posLoc, "vertexPosition");
    glBindAttribLocation(p.id(), normalLoc, "vertexNormal");

    p.attach(p.loadText(name + ".fsh"), GL_FRAGMENT_SHADER);

    p.link();
  }