コード例 #1
0
void Flt2Scene::AddShader()
{
	//добавить шейдер в сцену

	osg::StateSet* ss = _rootNode->getOrCreateStateSet();

	//создать экземпл¤р программы
	osg::Program* program = new osg::Program;
	program->setName( "microshader" );

	osg::Shader *VertObj = new osg::Shader( osg::Shader::VERTEX );
	osg::Shader *FragObj = new osg::Shader( osg::Shader::FRAGMENT );
	program->addShader( VertObj );
	program->addShader( FragObj );

	LoadShaderSource( VertObj , "glsl/simple.vert" );
	LoadShaderSource( FragObj , "glsl/simple.frag" );

	ss->setAttributeAndModes( program, osg::StateAttribute::ON );

	//создание параметра дл¤ передачи в шейдер
	osg::Uniform *_color = new osg::Uniform( "_ZZ3SconstantColor" , osg::Vec3( 1.0f, 0.0f, 1.0f));

	//задание callback'a дл¤ динамического изменени¤ параметра
	//_color->setUpdateCallback( new GL2SceneUniformCallback );

	//добавление в состо¤ние сцены
	ss->addUniform( _color );

	//добавление uniform'ов дл¤ работы с текстурными модул¤ми
	ss->addUniform( new osg::Uniform( "u_texture0" , 0 ) );
	ss->addUniform( new osg::Uniform( "u_texture1" , 1 ) );
	ss->addUniform( new osg::Uniform( "u_texture2" , 2 ) );
	ss->addUniform( new osg::Uniform( "u_texture3" , 3 ) );
}
コード例 #2
0
/*!
	 Constructor
	 @param shaderStateSet - the OSG stateset that should be affected by this shader
	 @param shaderName - a string that contains the name of that shader
	 @param vertexProgram - the vertx shader program file
	 @param fragProgram - the fragment shader program
*/
GLSL_ShaderLoader::GLSL_ShaderLoader( osg::StateSet* shaderStateSet, std::string shaderName, std::string vertexProgram, std::string fragProgram):
	_shaderStateSet(shaderStateSet), _name(shaderName), _vertObjFile(vertexProgram), _fragObjFile(fragProgram)
{
	
	// Creates a shader program object
	_shaderProgram = new osg::Program();

	// Pass the name to that object
	_shaderProgram->setName( shaderName );

	// Creates a vertex and a fragment shader operation
	_vertObj = new osg::Shader( osg::Shader::VERTEX );
	_fragObj = new osg::Shader( osg::Shader::FRAGMENT );

	// Add this shader to the program
	_shaderProgram->addShader( _fragObj );
	_shaderProgram->addShader( _vertObj );
	
	// Load the shader from a shource file. 
	LoadShaderSource( _vertObj, _vertObjFile );
    LoadShaderSource( _fragObj, _fragObjFile );
	
	// Apply the shader program on a stateset
	_shaderStateSet->setAttributeAndModes(_shaderProgram, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);

	
}
コード例 #3
0
void MainNode::AddShader( osg::StateSet* ss )
{
    //добавить шейдер в сцену

    //создать экземпл¤р программы
    osg::Program* program = new osg::Program;
    program->setName( "microshader" );

    osg::Shader *VertObj = new osg::Shader( osg::Shader::VERTEX );
    osg::Shader *FragObj = new osg::Shader( osg::Shader::FRAGMENT );
    osg::Shader *GeomObj = new osg::Shader( osg::Shader::GEOMETRY );

    //параметры дл¤ вершинного шейдера
    program->setParameter( GL_GEOMETRY_VERTICES_OUT_EXT, 6 );
    program->setParameter( GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES );
    program->setParameter( GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP );

    program->addShader( VertObj );
    program->addShader( GeomObj );
    program->addShader( FragObj );

    LoadShaderSource( VertObj , "glsl/simple.vert" );
    LoadShaderSource( GeomObj , "glsl/simple.geom" );
    LoadShaderSource( FragObj , "glsl/simple.frag" );

    ss->setAttributeAndModes( program , osg::StateAttribute::ON );
}
コード例 #4
0
ファイル: Shader.cpp プロジェクト: colintan95/OpenGL-Projects
GLuint CreateShader(GLenum type, const char* filename) {
    GLuint shader = glCreateShader(type);
    
    char* src;
    unsigned long srcLen;
    
    LoadShaderSource(filename, &src, &srcLen);
    
    GLint logLength;
    GLint compileStatus;
    
    glShaderSource(shader, 1, &src, NULL);
    
    glCompileShader(shader);
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
    if (logLength > 0) {
        GLchar* log = (GLchar*)malloc(sizeof(GLchar) * logLength);
        glGetShaderInfoLog(shader, logLength, &logLength, log);
        std::cout << "Shader Info Log from " << filename << ": "<< std::endl;
        std::cout << log << std::endl;
        free(log);
    }
    glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
    assert(compileStatus);
    
    FreeShaderSource(&src);
    
    return shader;
}
コード例 #5
0
	OGL4ShaderPtr OGL4ShaderCompiler::CreateShaderFromFile(SHADER_TYPE type, const boost::filesystem::path& path, const std::string& entry)
	{
	
		std::string source = LoadShaderSource(path.string());
		
		
		if(source == "")
		{
			return OGL4ShaderPtr();
		}
		


		std::vector<IncludeInfo> inc_list;
		IncludeInfo inc;
		inc.file = path;
		inc.lines = GetSourceLines(source);

		inc_list.push_back(inc);
		source = ProcessInclude(path.parent_path(), source, inc_list);
		
		inc_list.push_back(inc);
		inc_list.erase(inc_list.begin());


		source = ClearVersionComment(source);

		return CreateShaderFromSource(type, source, inc_list, entry);


	}
コード例 #6
0
ShaderProgram::Shader* ResourceManager::LoadShader(std::string path)
{
	ShaderProgram::Shader* shader = LoadShaderSource(path);

	CompileShader(shader);

	return shader;
}
コード例 #7
0
bool ShaderProgram::CompileShaderFromFile(const std::string &path, ShaderType type)
{
    GLchar* source = LoadShaderSource(path);
    bool ret = false;
    if(source != NULL){
        ret = CompileShaderFromSource(source, type);
        delete[] source;
    }else{
        DEBUG_MESSAGE("Could not load shader source.");
    }
    return ret;
}
コード例 #8
0
ファイル: Tools.cpp プロジェクト: antoinechene/FPS-openGL
GLuint	LoadShader(const char* filename, bool type)
{
	GLuint	shader;
	char*	src;
	GLint	Status;
	char*	log;
	GLsizei	logsize;

	logsize = 0;
	Status = GL_TRUE;
	src = NULL;
	if (type)
		shader = glCreateShader(GL_VERTEX_SHADER);
	else
		shader = glCreateShader(GL_FRAGMENT_SHADER);
	if (!glIsShader(shader))
	{
		std::cout<<"error of creation shader"<<std::endl;
		return (0);
	}
	src = LoadShaderSource(filename);
	if (src == NULL)
	{
		glDeleteShader(shader);
		return (0);
	}
	glShaderSource(shader, 1, (const GLchar**)&src, NULL);
	glCompileShader(shader);
	free (src);
	src = NULL;
	glGetShaderiv(shader, GL_COMPILE_STATUS, &Status);
	if (Status != GL_TRUE)
	{
		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logsize);
		log = (char*) malloc(logsize + 1);
		if (log == NULL)
		{
			std::cout<<"error of allocation"<<std::endl;
			return (0);
		}
		memset(log, '\0', logsize + 1);
		glGetShaderInfoLog(shader, logsize, &logsize, log);
		std::cout<<"error of compilation in the shader "<<filename<<std::endl;
		std::cout<<"error is "<<log<<std::endl;
		free (log);
		glDeleteShader(shader);
		return (0);
	}
	return (shader);
}
コード例 #9
0
ファイル: Shader.cpp プロジェクト: iamthegek/GekMediaEngine
bool Shader::Load(const char* in_vert, const char* in_frag)
{
	if(program != 0)
		return false;

	std::string source;
	LoadShaderSource(in_vert, source);
	vert = CreateShader(source, GL_VERTEX_SHADER, in_vert);

	source = "";
	LoadShaderSource(in_frag, source);
	frag = CreateShader(source, GL_FRAGMENT_SHADER, in_frag);

	program = glCreateProgram();
	glAttachShader(program, vert);
	glAttachShader(program, frag);

	glBindFragDataLocation(program, 0, "Color");
	glBindFragDataLocation(program, 1, "Normal");

	glLinkProgram(program);
	glUseProgram(program);
	return true;
}
コード例 #10
0
void TerrainShaderPatchNode::AddShader()
{
	//добавить шейдер

	//формирование сцены с шейдером
	osg::StateSet* ss = m_rootNode->getOrCreateStateSet();

	//создать экземпл¤р программы
	osg::Program* program = new osg::Program;
	program->setName( "only_geom" );

	osg::Shader *VertObj = new osg::Shader( osg::Shader::VERTEX );
	osg::Shader *FragObj = new osg::Shader( osg::Shader::FRAGMENT );
	program->addShader( VertObj );
	program->addShader( FragObj );

	LoadShaderSource( VertObj , "glsl/only_geom.vert" );
	LoadShaderSource( FragObj , "glsl/only_geom.frag" );

	ss->setAttributeAndModes( program, osg::StateAttribute::ON );

	//настроить uniform'ы
	SetupUniforms( ss );
}
コード例 #11
0
	std::string OGL4ShaderCompiler::ProcessInclude(const boost::filesystem::path& basePath, const std::string& source, std::vector<IncludeInfo>& inc_list)
	{
		std::vector<IncludeInfo> include_list = ExtractIncludeList(source);

		if(include_list.size() == 0)
		{
			return source;
		}

		std::string ret = "";
		for(size_t i = 0; i < include_list.size(); ++i)
		{
			bool included = false;
			for(auto v : inc_list)
			{
				if((basePath / v.file) == (basePath / include_list[i].file))
				{
					included = true;
					break;
				}
			}

			if(included)
			{
				continue;
			}
			
			std::string inc_source = LoadShaderSource(basePath / include_list[i].file);
			
			include_list[i].lines = GetSourceLines(inc_source);
			
			ret += ProcessInclude(basePath, inc_source, inc_list) + "\n";
			
			inc_list.push_back(include_list[i]);
		}

		ret += source;

		return ret;
	}
コード例 #12
0
ファイル: shader.cpp プロジェクト: jmazar/Ogl
void Shader::CreateShaderFromFile(std::string const & fileName) {
  LoadShaderSource(fileName);
  m_shader = CreateShader();
  CompileShader();
}
コード例 #13
0
ファイル: moShaderGLSL.cpp プロジェクト: inaes-tic/tv-moldeo
void moShaderGLSL::LoadVertShader(moText vert_filename)
{
    moText vert_source = LoadShaderSource(vert_filename);
    CreateVertShader(vert_source);
}
コード例 #14
0
ファイル: moShaderGLSL.cpp プロジェクト: inaes-tic/tv-moldeo
void moShaderGLSL::LoadShader(moText vert_filename, moText frag_filename)
{
    moText vert_source = LoadShaderSource(vert_filename);
    moText frag_source = LoadShaderSource(frag_filename);
    CreateShader(vert_source, frag_source);
}
コード例 #15
0
ファイル: moShaderGLSL.cpp プロジェクト: inaes-tic/tv-moldeo
void moShaderGLSL::LoadFragShader(moText frag_filename)
{
    moText frag_source = LoadShaderSource(frag_filename);
    CreateFragShader(frag_source);
}
コード例 #16
0
ファイル: shader.c プロジェクト: superkehoed/midterm
bool InitializeShader(Shader_T *s, const char *vsfile, const char *fsfile)
{
	bool success = true;
	GLuint vertexShader;
	GLuint fragmentShader;
	GLint vShaderCompiled = GL_FALSE;
	GLint fShaderCompiled = GL_FALSE;
	GLint programSuccess = GL_TRUE;
	GLchar *txt;
	unsigned long len;	
	//Generate program
	s->id = glCreateProgram();
	s->vertex_attrib = -1;
	s->uv_attrib = -1;
	//Create vertex shader
	vertexShader = glCreateShader( GL_VERTEX_SHADER );
	//Set vertex source
	LoadShaderSource(vsfile, &txt, &len);
	glShaderSource( vertexShader, 1, &txt, NULL );
	//Compile vertex source
	glCompileShader( vertexShader );
	ValidateShader(vertexShader, vsfile);
	UnloadShaderSource(&txt);
	//Check vertex shader for errors
	glGetShaderiv( vertexShader, GL_COMPILE_STATUS, &vShaderCompiled );
	if( vShaderCompiled != GL_TRUE )
	{
		printf( "Unable to compile vertex shader %d!\n", vertexShader );
		printShaderLog( vertexShader );
        success = false;
	}
	else
	{
		//Attach vertex shader to program
		glAttachShader( s->id, vertexShader );
		//Create fragment shader
		LoadShaderSource(fsfile, &txt, &len);
		fragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
		//Set fragment source
		glShaderSource( fragmentShader, 1, &txt, NULL );
		//Compile fragment source
		glCompileShader( fragmentShader );
		ValidateShader(fragmentShader, fsfile);
		UnloadShaderSource(&txt);
		//Check fragment shader for errors
		glGetShaderiv( fragmentShader, GL_COMPILE_STATUS, &fShaderCompiled );
		if( fShaderCompiled != GL_TRUE )
		{
			printf( "Unable to compile fragment shader %d!\n", fragmentShader );
			printShaderLog( fragmentShader );
			success = false;
		}
		else
		{
			//Attach fragment shader to program
			glAttachShader( s->id, fragmentShader );
			//Link program
			glLinkProgram( s->id );
			//Check for errors
			glGetProgramiv( s->id, GL_LINK_STATUS, &programSuccess );
			if( programSuccess != GL_TRUE )
			{
				printf( "Error linking program %d!\n", s->id );
				printProgramLog( s->id );
				success = false;
			}
			else
			{
				//Get vertex attribute location
				s->uv_attrib = glGetAttribLocation( s->id, "vertexUV" );
				s->vertex_attrib = glGetAttribLocation( s->id, "vertexPosition" );
				if( s->vertex_attrib == -1 )
				{
					printf( "vertexPosition is not a valid glsl program variable!\n" );
					success = false;
				}
				if(s->uv_attrib == -1 )
				{
					printf( "vertexTex is not a valid glsl program variable!\n" );
					success = false;
				}
			}
		}
	}
	return success;
}
コード例 #17
0
void MaterialShaderEquation::SetSourceName(const std::string& name) {
	m_source = LoadShaderSource(name);
}