bool NullTechnique::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, "../shaders/null_technique_vertex.glsl")) {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, "../shaders/null_technique_fragment.glsl")) {
        return false;
    }

    if (!Finalize()) {
        return false;
    }

    m_WVPLocation = GetUniformLocation("gWVP");

  if (m_WVPLocation == INVALID_UNIFORM_LOCATION) {
    return false;
  }

  return true;
}
//-------------------------------------------------------------------------------------------------
WorldShader::WorldShader( const char *name ) {
	AddShader( "glsl\\worldshader.v.glsl", GL_VERTEX_SHADER );
	AddShader( "glsl\\worldshader.f.glsl", GL_FRAGMENT_SHADER );
	Link();
	
	AddUniform( u_pattern_sampler, "sampler_patterns" );
	AddUniform( u_noise_sampler, "sampler_noise" );
	AddUniform( u_global_translation, "global_translation" );
	AddUniform( u_camera, "camera" );
	AddUniform( u_skylight_color, "skylight_color" );
	AddUniform( u_skylight_intensity, "skylight_intensity" );
	AddUniform( u_fog_distance, "fog_distance" );
	AddUniform( u_fog_length, "fog_length" );
	
	AddAttribute( a_instance_translation, "instance_translation", 1 );
	AddAttribute( a_instance_form, "instance_form", 1 );
	AddAttribute( a_instance_texture, "instance_texture", 1 );
	AddAttribute( a_instance_color, "instance_color", 1, 4 );
	//AddAttribute( attribInstanceColor2, "instance_color_2", 1 );
	//AddAttribute( attribInstanceColor3, "instance_color_3", 1 );
	//AddAttribute( attribInstanceColor4, "instance_color_4", 1 );

	AddUniform( u_texture_sampler, "sampler_texture" );
	AddUniform( u_texture_translation, "texture_translation" );
	AddUniform( u_opacity, "opacity" );
	AddUniform( u_fog_color, "fog_color" );

	AddUniform( u_light_brightness, "light_brightness" );
	AddUniform( u_light_colors, "light_colors" );
	AddUniform( u_light_positions, "light_positions" );

	Register( name );
}
Beispiel #3
0
bool BlurTech::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, "../tutorial46/shaders/blur.vs")) {
        return false;
    }


    if (!AddShader(GL_FRAGMENT_SHADER, "../tutorial46/shaders/blur.fs")) {
        return false;
    }

    if (!Finalize()) {
        return false;
    }

    m_inputTextureUnitLocation = GetUniformLocation("gColorMap");

	if (m_inputTextureUnitLocation == INVALID_UNIFORM_LOCATION) {
		return false;
	}
    
    Enable();
    
    glUniform1i(m_inputTextureUnitLocation, INPUT_TEXTURE_UNIT_INDEX);

	return true;
}
Beispiel #4
0
bool LightingTechnique::Init()
{
	if (!Technique::Init()) {
		return false;
	}

	if (!AddShader(GL_VERTEX_SHADER, "lighting.vs")) {
		return false;
	}

	if (!AddShader(GL_FRAGMENT_SHADER, "lighting.fs")) {
		return false;
	}

	if (!Finalize()) {
		return false;
	}

	m_WVPLocation = GetUniformLocation("gWVP");
	m_samplerLocation = GetUniformLocation("gSampler");
	m_dirLightColorLocation = GetUniformLocation("gDirectionalLight.Color");
	m_dirLightAmbientIntensityLocation = GetUniformLocation("gDirectionalLight.AmbientIntensity");

	if (m_dirLightAmbientIntensityLocation == 0xFFFFFFFF ||
		m_WVPLocation == 0xFFFFFFFF ||
		m_samplerLocation == 0xFFFFFFFF ||
		m_dirLightColorLocation == 0xFFFFFFFF)
	{
		return false;
	}

	return true;
}
Beispiel #5
0
    static inline const program_t& Create(const std::string& mat_name , const std::string& preprocessorDefinitions = std::string())
    {
        const uint16_t version = GLSL_VERSION;
        const std::string  comp_str = GLSL_VERSION>=150 ?" compatibility":"";

        const std::string  mat_name_cut = GetMaterialName(mat_name);

        if(GetPrograms().find(mat_name_cut)==GetPrograms().end())
        {
            program_t p;
            p.program = new osg::Program;
            p.program->setName(mat_name_cut);

            static osg::Shader* ssv = AddShader(shaders::VS, "shadow", version, comp_str, string());
            static osg::Shader* ssf = AddShader(shaders::FS, "shadow", version, comp_str, string());

            p.program->addShader( ssv );
            p.program->addShader( ssf );
            
            p.program->addShader( AddShader(shaders::VS, mat_name_cut, version, comp_str, preprocessorDefinitions));
            p.program->addShader( AddShader(shaders::FS, mat_name_cut, version, comp_str, preprocessorDefinitions));

            p.program->addBindAttribLocation( "tangent" , 6 );
            p.program->addBindAttribLocation( "binormal", 7 );

            GetPrograms()[mat_name_cut]=p;
        }

        return GetPrograms()[mat_name_cut];
    }
Beispiel #6
0
bool Res::Init() {
	Shader* shader = nullptr;
	Texture* texture = nullptr;

	// block shader
	shader = new Shader();
	if (!shader->Init("res/block.vert", "res/block.frag")) return false;
	AddShader("block", shader);

	// simpler color shader
	shader = new Shader();
	if (!shader->Init("res/color.vert", "res/color.frag")) return false;
	AddShader("color", shader);


	std::vector<byte> buffer, image;
	LodePNG::loadFile(buffer, "res/blocks.png");
	LodePNG::Decoder decoder;
	decoder.decode(image, buffer);

	int dim = decoder.getWidth();

	texture = Texture::Create3DTexture(dim, dim, decoder.getHeight() / dim, image.data());
	AddTexture("blocks", texture);

	return true;
}
Beispiel #7
0
static void CompileShaders()
{
	GLuint ShaderProgram = glCreateProgram();

	AddShader(ShaderProgram, GL_VERTEX_SHADER, pVS);
	AddShader(ShaderProgram, GL_FRAGMENT_SHADER, pFS);

	glLinkProgram(ShaderProgram);
	GLint Success;
	glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &Success);
	if (!Success)
	{
		GLchar InfoLog[1024] = {0};
		glGetProgramInfoLog(ShaderProgram, 1024, NULL, InfoLog);
		fprintf(stderr, "Error : Link Error '%s'\n", InfoLog);
		exit(0);
	}
	gWorldLocation = glGetUniformLocation(ShaderProgram, "gWorld");

	assert(gWorldLocation != 0xFFFFFFFF);
	glValidateProgram(ShaderProgram);
	glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &Success);
	if (!Success)
	{
		GLchar InfoLog[1024] = {0};
		glGetProgramInfoLog(ShaderProgram, 1024, NULL, InfoLog);
		fprintf(stderr, "Error : Invalid shader program '%s'\n", InfoLog);
		exit(1);
	}
	glUseProgram(ShaderProgram);
}
bool ShadowMapTechnique::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, "shadow_map.vs")) {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, "shadow_map.fs")) {
        return false;
    }

    if (!Finalize()) {
        return false;
    }

    m_WVPLocation = GetUniformLocation("gWVP");
    m_textureLocation = GetUniformLocation("gShadowMap");

    if (m_WVPLocation == INVALID_UNIFORM_LOCATION ||
        m_textureLocation == INVALID_UNIFORM_LOCATION) {
        return false;
    }

    return true;
}
Beispiel #9
0
Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) : IObject("shader")
{
	AddShader(ShaderType::Vertex, vertexPath);
	AddShader(ShaderType::Fragment, fragmentPath);

	Reload(true);
}
Beispiel #10
0
bool LineShader::Init()
{
	if (!Shader::Init()) {
		return false;
	}

	if (!AddShader(GL_VERTEX_SHADER, "Resources/shader/Line.vs")) {
		return false;
	}
	if (!AddShader(GL_FRAGMENT_SHADER, "Resources/shader/Line.fs")) {
		return false;
	}
	if (!Finalize()) {
		return false;
	}

	m_MVPLocation = GetUniformLocation("MVP");
	if (m_MVPLocation == INVALID_UNIFORM_LOCATION) {
		return false;
	}

	m_LineColorLocation = GetUniformLocation("LineColor");
	if (m_LineColorLocation == INVALID_UNIFORM_LOCATION) {
		return false;
	}

	return true;
}
Beispiel #11
0
void CompileShader()
{
	shaderProgram = glCreateProgram();
	string vs, fs;
	if (!ReadFile(VSFile, vs))
		exit(1);
	if (!ReadFile(FSFile, fs))
		exit(1);

	AddShader(shaderProgram, vs.c_str(), GL_VERTEX_SHADER);
	AddShader(shaderProgram, fs.c_str(), GL_FRAGMENT_SHADER);

	GLint success;
	GLchar errorLog[1024];
	glLinkProgram(shaderProgram);
	glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
	if (success == 0)
	{
		glGetProgramInfoLog(shaderProgram, 1024, NULL, errorLog);
		fprintf(stderr, "Link error : %s\n", errorLog);
		exit(1);
	}

	glValidateProgram(shaderProgram);
	glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &success);
	if (success == 0)
	{
		glGetProgramInfoLog(shaderProgram, 1024, NULL, errorLog);
		fprintf(stderr, "Validate error : %s\n", errorLog);
		exit(1);
	}
}
bool MotionBlurTechnique::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, "shaders/motion_blur.vs")) {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, "shaders/motion_blur.fs")) {
        return false;
    }

    if (!Finalize()) {
        return false;
    }
    
    m_colorTextureLocation = GetUniformLocation("gColorTexture");
    m_motionTextureLocation = GetUniformLocation("gMotionTexture");
    
    if (m_motionTextureLocation == INVALID_UNIFORM_LOCATION ||
        m_colorTextureLocation == INVALID_UNIFORM_LOCATION) {
        return false;
    }

	return true;
}
bool DSDirLightPassTech::Init()
{
	if (!Technique::Init())
	{
		return false;
	}

	if (!AddShader(GL_VERTEX_SHADER, "shaders/light_pass.vs"))
	{
		return false;
	}

	if (!AddShader(GL_FRAGMENT_SHADER, "shaders/dir_light_pass.fs"))
	{
		return false;
	}

	if (!Finalize()) {
		return false;
	}

	m_dirLightLocation.Color = GetUniformLocation("gDirectionalLight.Base.Color");
	m_dirLightLocation.AmbientIntensity = GetUniformLocation("gDirectionalLight.Base.AmbientIntensity");
	m_dirLightLocation.Direction = GetUniformLocation("gDirectionalLight.Direction");
	m_dirLightLocation.DiffuseIntensity = GetUniformLocation("gDirectionalLight.Base.DiffuseIntensity");

	if (m_dirLightLocation.AmbientIntensity == INVALID_UNIFORM_LOCATION ||
		m_dirLightLocation.Color == INVALID_UNIFORM_LOCATION ||
		m_dirLightLocation.DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
		m_dirLightLocation.Direction == INVALID_UNIFORM_LOCATION) {
		return false;
	}

	return DSLightPassTech::Init();
}
Beispiel #14
0
bool GeomPassTech::Init()
{
	if (!Technique::Init()) {
		return false;
	}

	if (!AddShader(GL_VERTEX_SHADER, "engine/shaders/geometry_pass.vs")) {
		return false;
	}

	if (!AddShader(GL_FRAGMENT_SHADER, "engine/shaders/geometry_pass.fs")) {
		return false;
	}

	if (!Finalize()) {
		return false;
	}

	m_WVPLocation = GetUniformLocation("gWVP");

	if (m_WVPLocation == INVALID_UNIFORM_LOCATION) {
		return false;
	}

	return true;
}
bool PickingTechnique::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, pVS)) {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, pFS)) {
        return false;
    }
    
    if (!Finalize()) {
        return false;
    }

    m_WVPLocation = GetUniformLocation("gWVP");
    m_objectIndexLocation = GetUniformLocation("gObjectIndex");
    m_drawIndexLocation = GetUniformLocation("gDrawIndex");

    if (m_WVPLocation == INVALID_UNIFORM_LOCATION ||
        m_objectIndexLocation == INVALID_UNIFORM_LOCATION ||
        m_drawIndexLocation == INVALID_UNIFORM_LOCATION) {
        return false;
    }

    return true;
}
bool ShadowMapTechnique::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, "../tutorial43/shaders/shadow_map.vs")) {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, "../tutorial43/shaders/shadow_map.fs")) {
        return false;
    }

    if (!Finalize()) {
        return false;
    }

    m_WVPLocation = GetUniformLocation("gWVP");
    m_WorldMatrixLocation = GetUniformLocation("gWorld");
    m_lightWorldPosLoc = GetUniformLocation("gLightWorldPos");

    if (m_WVPLocation == INVALID_UNIFORM_LOCATION ||
	m_WorldMatrixLocation == INVALID_UNIFORM_LOCATION ||
        m_lightWorldPosLoc == INVALID_UNIFORM_LOCATION) {
        return false;
    }

    return true;
}
bool NullTechnique::Init()
{
    if (!Technique::Init()) {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, "shaders/null_technique.vs")) {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, "shaders/null_technique.fs")) {
        return false;
    }
    BindAttribLocation(0, "Position");
    if (!Finalize()) {
        return false;
    }

    m_WVPLocation = GetUniformLocation("gWVP");

	if (m_WVPLocation == INVALID_UNIFORM_LOCATION) {
		return false;
	}

	return true;
}
Beispiel #18
0
FCGLShaderProgramRef FCGLShaderManager::AddProgram( std::string name, std::string shaderName )
{
	FCGLShaderProgramRefMapByStringIter i = m_programs.find( name );
		
	if( i == m_programs.end() ) 
	{
		std::string vertexShaderName = shaderName + ".vsh";
		std::string fragmentShaderName = shaderName + ".fsh";
		
		FCGLShaderRef vertexShader = AddShader( vertexShaderName );
		FCGLShaderRef fragmentShader = AddShader( fragmentShaderName );
		
		// build program
		
		if( name == kFCKeyShaderDebug ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgramDebug( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShaderWireframe ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgramWireframe( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShaderFlatUnlit ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgramFlatUnlit( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShaderNoTexVLit ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgramNoTexVLit( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShaderNoTexPLit ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgramNoTexPLit( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShader1TexVLit ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgram1TexVLit( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShader1TexPLit ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgram1TexPLit( vertexShader, fragmentShader ) );
		} 
		else if ( name == kFCKeyShaderTest ) 
		{
			m_programs[ name ] = FCGLShaderProgramRef( new FCGLShaderProgramTest( vertexShader, fragmentShader ) );
		} 
		else {
			FC_FATAL( std::string("Unknown shader: ") + name );
		}
		
		FC_LOG( std::string("Linked GL program: ") + name );
		
//		[self.programs setValue:ret forKey:name];
	}
	
	return m_programs[ name ];
}
Beispiel #19
0
ShaderProgram::ShaderProgram(Shader *vertex, Shader *fragment)
{
    m_filename = "";
    m_object = glCreateProgram();
    
    AddShader(Shader::Create(vertex->m_filename));
    AddShader(Shader::Create(fragment->m_filename));
    
    Link();
}
Beispiel #20
0
ShaderProgram::ShaderProgram(std::string vertex, std::string fragment)
{
    m_filename = "";
    m_object = glCreateProgram();
    
    AddShader(Shader::Create(vertex));
    AddShader(Shader::Create(fragment));
    
    Link();
}
Beispiel #21
0
void Window::TextureDisplayer_Activation(){
    SetCurrentDirectory("TextureLoad");
    TextureDisplayer_Adress=AddShader("TexLoad.frag",GL_FRAGMENT_SHADER,-1);
    AddShader("TexLoad.geo",GL_GEOMETRY_SHADER,TextureDisplayer_Adress);
    AddShader("TexLoad.vert",GL_VERTEX_SHADER,TextureDisplayer_Adress);
    ConsoleEcho("12345");
    GLuint Type[1]={GL_GEOMETRY_SHADER_BIT | GL_VERTEX_SHADER_BIT |GL_FRAGMENT_SHADER_BIT};
    SetActiveInternProgram(&TextureDisplayer_Adress,Type,1);
    TextureDisplayer_Inited=true;
    ConsoleEcho("Tes Suposé activé");
}
Beispiel #22
0
static void CompileShaders()
{
	GLuint ShaderProgram = glCreateProgram();
	if (ShaderProgram == 0)
	{
		fprintf(stderr, "glCreateProgram() error\n");
		exit(1);
	}

	std::string vs, fs;
	if (!Util_ReadFile(pVSFileName, vs))
	{
		fprintf(stderr, "ReadFile(VS) fail, file = %s\n", pVSFileName);
		exit(1);
	}

	if (!Util_ReadFile(pFSFileName, fs))
	{
		fprintf(stderr, "ReadFile(FS) fail, file = %s\n", pFSFileName);
		exit(1);
	}

	AddShader(ShaderProgram, vs.c_str(), GL_VERTEX_SHADER);
	AddShader(ShaderProgram, fs.c_str(), GL_FRAGMENT_SHADER);


	GLint success = 0;
	GLchar log[1024] = { 0 };

	glLinkProgram(ShaderProgram);
	glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &success);
	if (success == 0)
	{
		glGetProgramInfoLog(ShaderProgram, sizeof(log), NULL, log);
		fprintf(stderr, "glLinkProgram fail: '%s'\n", log);
		exit(1);
	}

	glValidateProgram(ShaderProgram);
	glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &success);
	if (success == 0)
	{
		glGetProgramInfoLog(ShaderProgram, sizeof(log), NULL, log);
		fprintf(stderr, "glValidateProgram fail: '%s'\n", log);
		exit(1);
	}

	glUseProgram(ShaderProgram);

	gWorldLocation = glGetUniformLocation(ShaderProgram, "gWorld");
	assert(gWorldLocation != 0xFFFFFFFF);
}
bool LightingTechnique::Init()
{
    if (!Technique::Init())
    {
        return false;
    }

    if (!AddShader(GL_VERTEX_SHADER, pVS))
    {
        return false;
    }

    if (!AddShader(GL_FRAGMENT_SHADER, pFS))
    {
        return false;
    }

    if (!Finalize())
    {
        return false;
    }

    m_WVPLocation = GetUniformLocation("gWVP");
    m_WorldMatrixLocation = GetUniformLocation("gWorld");
    m_samplerLocation = GetUniformLocation("gSampler");

    m_eyeWorldPosition = GetUniformLocation("gEyeWorldPos");
    m_matSpecularIntensityLocation = GetUniformLocation("gMatSpecularIntensity");
    m_matSpecularPowerLocation = GetUniformLocation("gSpecularPower");

    m_dirLightLocation.Color = GetUniformLocation("gDirectionalLight.Color");
    m_dirLightLocation.AmbientIntensity = GetUniformLocation("gDirectionalLight.AmbientIntensity");
    m_dirLightLocation.Direction = GetUniformLocation("gDirectionalLight.Direction");
    m_dirLightLocation.DiffuseIntensity = GetUniformLocation("gDirectionalLight.DiffuseIntensity");

    if (m_dirLightLocation.AmbientIntensity == 0xFFFFFFFF ||
        m_WVPLocation == 0xFFFFFFFF ||
        m_WorldMatrixLocation == 0xFFFFFFFF ||
        m_samplerLocation == 0xFFFFFFFF ||
        m_dirLightLocation.Color == 0xFFFFFFFF ||
        m_dirLightLocation.DiffuseIntensity == 0xFFFFFFFF ||
        m_eyeWorldPosition == 0xFFFFFFFF ||
        m_matSpecularIntensityLocation == 0xFFFFFFFF ||
        m_matSpecularPowerLocation == 0xFFFFFFFF ||
        m_dirLightLocation.Direction == 0xFFFFFFFF) {
        return false;
    }

    return true;
}
Beispiel #24
0
//Create a vertex and fragment shader  
void Shader::CreateShader(char *vertexPath, char *fragmentPath)
{
	//Create a handle for the program
	m_ProgramHandle = glCreateProgram();

	//Add vertex shader to the program
	AddShader(vertexPath, VERTEX_SHADER);

	//Add fragment shader to the program
	AddShader(fragmentPath, FRAGMENT_SHADER);

	//Link the shaders in the program and check for errors
	LinkShaders();
}
void CreateShaderProgram()
{
    /* Allocate shader object */
    ShaderProgram = glCreateProgram();

    if (ShaderProgram == 0) 
    {
        fprintf(stderr, "Error creating shader program\n");
        exit(1);
    }

    /* Load shader code from file */
    VertexShaderString = LoadShader("vertexshader.vs");
    FragmentShaderString = LoadShader("fragmentshader.fs");

    /* Separately add vertex and fragment shader to program */
    AddShader(ShaderProgram, VertexShaderString, GL_VERTEX_SHADER);
    AddShader(ShaderProgram, FragmentShaderString, GL_FRAGMENT_SHADER);

    GLint Success = 0;
    GLchar ErrorLog[1024];

    /* Link shader code into executable shader program */
    glLinkProgram(ShaderProgram);

    /* Check results of linking step */
    glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &Success);

    if (Success == 0) 
    {
        glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
        fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
        exit(1);
    }

    /* Check if shader program can be executed */ 
    glValidateProgram(ShaderProgram);
    glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &Success);

    if (!Success) 
    {
        glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
        fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
        exit(1);
    }

    /* Put linked shader program into drawing pipeline */
    glUseProgram(ShaderProgram);
}
Beispiel #26
0
bool InnterShader::Init() {
    if(!ShaderBasic::Init()) {
        return false;
    }
    if(!AddShader(GL_VERTEX_SHADER, NULL, vertexShaderSource)) {
        return false;
    }
    if(!AddShader(GL_FRAGMENT_SHADER, NULL, fragmentShaderSource)) {
        return false;
    }
    if(!LinkProgram()) {
        return false;
    }
    return true;
}
static void CompileShaders()
{
    GLuint ShaderProgram = glCreateProgram();

    if (ShaderProgram == 0) {
        fprintf(stderr, "Error creating shader program\n");
        exit(1);
    }
	
    string vs, fs;

    if (!ReadFile(pVSFileName, vs)) {
        exit(1);
    };

    if (!ReadFile(pFSFileName, fs)) {
        exit(1);
    };

    AddShader(ShaderProgram, vs.c_str(), GL_VERTEX_SHADER);
    AddShader(ShaderProgram, fs.c_str(), GL_FRAGMENT_SHADER);

    GLint Success = 0;
    GLchar ErrorLog[1024] = { 0 };

    glLinkProgram(ShaderProgram);
    glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &Success);
	if (Success == 0) {
		glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
		fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
        exit(1);
	}

    glValidateProgram(ShaderProgram);
    glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &Success);
    if (!Success) {
        glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
        fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
        exit(1);
    }

    glUseProgram(ShaderProgram);

    gWVPLocation = glGetUniformLocation(ShaderProgram, "gWVP");
    assert(gWVPLocation != 0xFFFFFFFF);
    gSampler = glGetUniformLocation(ShaderProgram, "gSampler");
    assert(gSampler != 0xFFFFFFFF);
}
Beispiel #28
0
GLuint CompileShaders()
{
	//Start the process of setting up our shaders by creating a program ID
	//Note: we will link all the shaders together into this ID
	shaderProgramID = glCreateProgram();
	if (shaderProgramID == 0) {
		fprintf(stderr, "Error creating shader program\n");
		system("pause");
		exit(1);
	}

	// Create two shader objects, one for the vertex, and one for the fragment shader
	AddShader(shaderProgramID, "../Shaders/simpleVertexShader.txt", GL_VERTEX_SHADER);
	//	AddShader(shaderProgramID, "../Shaders/skybox_technique.vert", GL_VERTEX_SHADER);
	AddShader(shaderProgramID, "../Shaders/simpleFragmentShader.txt", GL_FRAGMENT_SHADER);
	//	AddShader(shaderProgramID, "../Shaders/skybox_technique.frag", GL_FRAGMENT_SHADER);

	GLint Success = 0;
	GLchar ErrorLog[1024] = { 0 };


	// After compiling all shader objects and attaching them to the program, we can finally link it
	glLinkProgram(shaderProgramID);
	// check for program related errors using glGetProgramiv
	glGetProgramiv(shaderProgramID, GL_LINK_STATUS, &Success);
	if (Success == 0) {
		glGetProgramInfoLog(shaderProgramID, sizeof(ErrorLog), NULL, ErrorLog);
		fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
		system("pause");
		exit(1);
	}

	// program has been successfully linked but needs to be validated to check whether the program can execute given the current pipeline state
	glValidateProgram(shaderProgramID);
	// check for program related errors using glGetProgramiv
	glGetProgramiv(shaderProgramID, GL_VALIDATE_STATUS, &Success);
	if (!Success) {
		glGetProgramInfoLog(shaderProgramID, sizeof(ErrorLog), NULL, ErrorLog);
		fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
		system("pause");
		exit(1);
	}
	// Finally, use the linked shader program
	// Note: this program will stay in effect for all draw calls until you replace it with another or explicitly disable its use
	glUseProgram(shaderProgramID);

	return shaderProgramID;
}
Beispiel #29
0
bool Technique::LoadShader ( GLenum shaderType, const char * pFilename )
{
  char *pShaderText = 0;
  return
    LoadShaderTextFile ( pFilename, pShaderText ) &&
    AddShader ( shaderType, pShaderText );
}
Beispiel #30
0
Shader* ShaderManager::AddShader(std::string n_name)
{
  Shader* tmp_newShader = new Shader(GetResourcePath(n_name));
  tmp_newShader->Init();
  AddShader(n_name, tmp_newShader);
  return tmp_newShader;
}