void CGLSLRayCasting::init(const string& _vertfile,const string& _fragfile){
	
	m_SimpleVertexShader = CreateShaderFromFile(_vertfile);
	
	m_FragmentShader = CreateShaderFromFile(_fragfile);
	m_Program = glCreateProgram();
	glAttachShader(m_Program, m_SimpleVertexShader);
	glAttachShader(m_Program, m_FragmentShader);GetGLError("glTexImage3D");
	glLinkProgram(m_Program);
	string names[]={"voltexture","threshold"};
	for(int i=0;i<sizeof(names)/sizeof(names[0]);i++){
		m_Map[0].insert(pair<string,int>(names[i],glGetUniformLocation(m_Program,names[i].c_str())));
		
	}GetGLError("glTexImage3D");
	glUseProgram(m_Program);
	glUniform1f(m_Map[0]["threshold"],m_threshold);
	glUniform1i(m_Map[0]["voltexture"],0);
	glUseProgram(0);
	m_SliceVertexShader= CreateShaderFromFile("slice.vert");
	m_SliceProgram = glCreateProgram();GetGLError("glTexImage3D");
	glAttachShader(m_SliceProgram, m_SliceVertexShader);GetGLError("glTexImage3D");
	glAttachShader(m_SliceProgram, m_FragmentShader);GetGLError("glTexImage3D");
	glLinkProgram(m_SliceProgram);GetGLError("glTexImage3D");
	checklinkstatus(m_SliceProgram);GetGLError("glTexImage3D");
	glUseProgram(m_SliceProgram);GetGLError("glTexImage3D");
	string names2[]={"voltexture","threshold"};//,"frontIdx"};
	for(int i=0;i<sizeof(names2)/sizeof(names2[0]);i++){
		m_Map[1].insert(pair<string,int>(names2[i],
			glGetUniformLocation(m_SliceProgram,names2[i].c_str())));GetGLError("glTexImage3D");
	}
	
	
	
}
Beispiel #2
0
void CPlyRender::InitShader(void)
{
	mProgram = CreateShaderFromFile("./CubeMap/reflect.vert","./CubeMap/reflact.frag");
	mCubeSampUniform=glGetUniformLocation(mProgram, "cubemap");
	glUseProgram(mProgram);
	glUniform1i(mCubeSampUniform,0);
	glUseProgram(0);
}
Beispiel #3
0
void CausticsRender::InitGeometry(){
	stringstream vertex_shader_name;
	vertex_shader_name << "./" << PROJECT_NAME << "/refract.vert";
	stringstream fragment_shader_name;
	fragment_shader_name << "./" << PROJECT_NAME << "/refract.frag";
	string vt= vertex_shader_name.str();
	string fg = fragment_shader_name.str();
	mProgram = CreateShaderFromFile(vt, fg);
	glUseProgram(mProgram);

	int total = -1;
	glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTES, &total);
	for (int i = 0; i<total; ++i) {
		int name_len = -1, num = -1;
		GLenum type = GL_ZERO;
		char name[100];
		glGetActiveAttrib(mProgram, GLuint(i), sizeof(name) - 1, &name_len, &num, &type, name);
		name[name_len] = 0;
		cout << "name:" << name << endl;
	}
	int vploc = glGetAttribLocation(mProgram, "vPosition");
	int nloc = glGetAttribLocation(mProgram, "normal");

	mMatrixLocation = glGetUniformLocation(mProgram, "uModelViewProj");
	mCubeSampUniform = glGetUniformLocation(mProgram, "cubemap");
	glUniform1i(mCubeSampUniform, 0);


	mModel.LoadPlyData(mFileName.c_str());
	glGenVertexArrays(1, &mPlayerVao);//新しいvaoが作られ、名前が割り振られる。
	glBindVertexArray(mPlayerVao);//vaoがアクティブになる
	
	

	GLuint ebo = 0;
	glGenBuffers(1, &ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*mModel.mTriangleNum * 3, mModel.m_Indices, GL_STATIC_DRAW);

	GLuint vbo[2];
	glGenBuffers(2, vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vec3<float>)*mModel.mVertNum, mModel.m_Verts, GL_STATIC_DRAW);

	
	
	glVertexAttribPointer(vploc, 3, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(vploc);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
	
	glBufferData(GL_ARRAY_BUFFER, sizeof(vec3<float>)*mModel.mVertNum, mModel.m_Normals, GL_STATIC_DRAW);
	glVertexAttribPointer(nloc, 3, GL_FLOAT, GL_TRUE, 0, NULL);
	glEnableVertexAttribArray(nloc);
	
	miffy::GetGLError("InitGeometry");
	
}
Beispiel #4
0
	bool ShaderStock::Init()
	{
		auto assetManager = AssetManager::GetInstance();
		auto exceptionManager = ExceptionManager::GetInstance();

		shadowShader = assetManager->CreateShaderFromFile("fx/shadow.fx");
		if (shadowShader != nullptr)
		{
			shadowShader->SetTechnique("Shadow");
		}
		else
		{
			exceptionManager->PushException(Ptr<Exception>::New("속潼shadow shader呵겨。"));
			return false;
		}

		skyBoxShader = Game::GetInstance()->GetAssetManager()->CreateShaderFromFile("fx/skybox.fx");
		if (skyBoxShader != nullptr)
		{
			skyBoxShader->SetTechnique("SkyBox");
		}
		else
		{
			exceptionManager->PushException(Ptr<Exception>::New("속潼skybox shader呵겨。"));
			return false;
		}

		meshShader = assetManager->CreateShaderFromFile("fx/mesh.fx");
		if (meshShader != nullptr)
		{
			meshShader->SetTechnique("Mesh");
		}
		else
		{
			exceptionManager->PushException(Ptr<Exception>::New("속潼mesh shader呵겨。"));
			return false;
		}

		spriteShader = Game::GetInstance()->GetAssetManager()->CreateShaderFromFile("fx/sprite.fx");
		if (spriteShader != nullptr)
		{
			spriteShader->SetTechnique("Sprite");
		}
		else
		{
			exceptionManager->PushException(Ptr<Exception>::New("속潼sprite shader呵겨。"));
			return false;
		}

		terrainShader = Game::GetInstance()->GetAssetManager()->CreateShaderFromFile("fx/terrain.fx");
		if (terrainShader != nullptr)
		{
			terrainShader->SetTechnique("Terrain");
		}
		else
		{
			exceptionManager->PushException(Ptr<Exception>::New("속潼terrain shader呵겨。"));
			return false;
		}

		terrainShadowShader = Game::GetInstance()->GetAssetManager()->CreateShaderFromFile("fx/terrainShadow.fx");
		if (terrainShadowShader != nullptr)
		{
			terrainShadowShader->SetTechnique("Shadow");
		}
		else
		{
			exceptionManager->PushException(Ptr<Exception>::New("속潼terrain shadow shader呵겨。"));
			return false;
		}

		return true;
	}
Beispiel #5
0
VertexShader::VertexShader(std::string const & fileName) :
  Shader() {
    CreateShaderFromFile(fileName);
}