Ejemplo n.º 1
0
//--------------------------------------------------------------
// Create shader from shader program files
//--------------------------------------------------------------
bool Shader::CreateShader(const char* shadName)
{
	vertShaderId = glCreateShader(GL_VERTEX_SHADER);
	fragShaderId = glCreateShader(GL_FRAGMENT_SHADER);

	shaderName = shadName;
	string prefix("Src\\");
	string suffixVert(".vs");
	string suffixFrag(".fs");
	string pathVertShader = prefix;

	pathVertShader += shaderName;
	pathVertShader += suffixVert;
	//pathVertShader = prefix + shaderName + suffixVert;

	string pathFragShader = prefix;
	pathFragShader += shaderName;
	pathFragShader += suffixFrag;

	ReadSource(vertShaderId, pathVertShader.c_str());
	ReadSource(fragShaderId, pathFragShader.c_str());

	CompileSource(vertShaderId, "vertex");
	CompileSource(fragShaderId, "fragment");

	// Create the shader program object
	shaderProgId = glCreateProgram();

	// Attach the shader objects to the shader program object
	glAttachShader(shaderProgId, vertShaderId);
	glAttachShader(shaderProgId, fragShaderId);
  
	// Delete the shader objects
	glDeleteShader(vertShaderId);
	glDeleteShader(fragShaderId);

	// Link the shader program object to the application
	glLinkProgram(shaderProgId);
	GLint linked;
	glGetProgramiv(shaderProgId, GL_LINK_STATUS, &linked);
	if ( linked == GL_FALSE )
	{
		cerr << "Link error : " << shaderName.c_str() << endl;
		return false;
	}
	PrintProgramInfoLog();

	return true;
}
Ejemplo n.º 2
0
bool D3D12Shader::Build(const ShaderDescriptor& shaderDesc)
{
    if (IsShaderSourceCode(shaderDesc.sourceType))
        return CompileSource(shaderDesc);
    else
        return LoadBinary(shaderDesc);
}
Ejemplo n.º 3
0
	void ShaderCode::CreateFromFile( std::string FileName, GLuint target )
	{
		std::cout<<"Loading from '"<<FileName<<"'.\n";
		std::ifstream File ( FileName );
		if ( !File.is_open())
		{
			std::cout<<"File '"<<FileName<<"' not found."<<std::endl;
			return;
		}

		std::string Source;
		std::string line;
		while ( File.good() )
		{
			getline( File, line );
			Source.append( line );
			Source.append( "\n" );
		}
		CompileSource( Source, target );
	}
Ejemplo n.º 4
0
	void ShaderCode::CreateFromString( std::string Source, GLuint target )
	{
		CompileSource( Source, target );
	}