当前位置: 首页>>代码示例>>C++>>正文


C++ GLSLShader::UnUse方法代码示例

本文整理汇总了C++中GLSLShader::UnUse方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLShader::UnUse方法的具体用法?C++ GLSLShader::UnUse怎么用?C++ GLSLShader::UnUse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GLSLShader的用法示例。


在下文中一共展示了GLSLShader::UnUse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawScene

//function to render scene given the combined modelview projection matrix 
//and a shader
void DrawScene(const glm::mat4& MVP, GLSLShader& shader) {
	//enable alpha blending with over compositing
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//bind the cube vertex array object
	glBindVertexArray(cubeVAOID);
	//bind the shader
	shader.Use();
	//for all cubes
	for(int k=-1;k<=1;k++) {
		for(int j=-1;j<=1;j++) {
			int index =0;
			for(int i=-1;i<=1;i++) {
				GL_CHECK_ERRORS
				//set the modelling transformation and shader uniforms
				glm::mat4 T = glm::translate(glm::mat4(1), glm::vec3(i*2,j*2,k*2));
				glUniform4fv(shader("vColor"),1, &(box_colors[index++].x));
				glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP*R*T));
				//draw the cube
				glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
				GL_CHECK_ERRORS
			}
		}
	}
	//unbind shader
	shader.UnUse();
	//unbind vertex array object
	glBindVertexArray(0);
}
开发者ID:bagobor,项目名称:opengl33_dev_cookbook_2013,代码行数:32,代码来源:main.cpp

示例2: OnRender

//display callback 
void OnRender() {
	//get the elapse time
	time = glutGet(GLUT_ELAPSED_TIME)/1000.0f * SPEED;

	//clear the colour and depth buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	//set teh camera viewing transformation
	glm::mat4 T		= glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
	glm::mat4 Rx	= glm::rotate(T,  rX, glm::vec3(1.0f, 0.0f, 0.0f));
	glm::mat4 MV	= glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
    glm::mat4 MVP	= P*MV;

	//bind the shader 
	shader.Use();
		//set the shader uniforms
		glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
		glUniform1f(shader("time"), time);
			//draw the mesh triangles
			glDrawElements(GL_TRIANGLES, TOTAL_INDICES, GL_UNSIGNED_SHORT, 0);

	//unbind the shader
	shader.UnUse();
	
	//swap front and back buffers to show the rendered result
	glutSwapBuffers();
}
开发者ID:bagobor,项目名称:opengl33_dev_cookbook_2013,代码行数:28,代码来源:main.cpp

示例3: OnRender

//display function
void OnRender() {
	//clear colour and depth buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	//set the camera transform
	glm::mat4 T		= glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
	glm::mat4 Rx	= glm::rotate(T,  rX, glm::vec3(1.0f, 0.0f, 0.0f));
	glm::mat4 Ry	= glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
	glm::mat4 MV	= Ry;
    glm::mat4 MVP	= P*MV;

	//since we have kept the terrain vertex array object bound
	//it is still bound to the context so we can directly call draw element
	//which will draw vertices from the bound vertex array object
	//bind the terrain shader
	shader.Use();				
		//pass shader uniforms
		glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
			//draw terrain mesh
			glDrawElements(GL_TRIANGLES, TOTAL_INDICES, GL_UNSIGNED_INT, 0);
	//unbind shader
	shader.UnUse();
	
	//swap front and back buffers to show the rendered result
	glutSwapBuffers();
}
开发者ID:bagobor,项目名称:opengl33_dev_cookbook_2013,代码行数:27,代码来源:main.cpp

示例4: onInit

void onInit() {
	//tex = loadImage("../textures/texture.png");
	tex = loadImage("../textures/dots.png");
	tex2 = loadImage("../textures/dots.png");
	ctv = new CTextureViewer(0, "../shaders/textureViewer.vs", "../shaders/textureViewer.frag");
	ctv->setTexture(tex);
	ctv->setTexture2(tex2);

	hist.LoadFromFile(GL_VERTEX_SHADER, "../shaders/histogram.vs");
	hist.LoadFromFile(GL_FRAGMENT_SHADER, "../shaders/histogram.frag");
	hist.CreateAndLinkProgram();

	hist.Use();

	//Create uniforms and attributes (filled later)
	hist.AddAttribute("vPosition");
	hist.AddUniform("tex");
	hist.AddUniform("textureWidth");
	hist.AddUniform("textureHeight");

	hist.UnUse();

	initTex();
	initPointVBO();
	initHistogramFBO();
}
开发者ID:mafian89,项目名称:GMU,代码行数:26,代码来源:GMU.cpp

示例5: DrawSphere

//renders sphere using the render shader
void DrawSphere(const glm::mat4& mvp) {
	renderShader.Use();
		glBindVertexArray(sphereVAOID);
		glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
			glDrawElements(GL_TRIANGLES, total_sphere_indices,GL_UNSIGNED_SHORT,0); 
	renderShader.UnUse();
}
开发者ID:bagobor,项目名称:opengl33_dev_cookbook_2013,代码行数:8,代码来源:main.cpp

示例6: DrawCloth

void DrawCloth()
{ 
	renderShader.Use();
		glBindVertexArray(clothVAOID); 
		glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));						
			glDrawElements(GL_TRIANGLES, indices.size(),GL_UNSIGNED_SHORT,0);
		//glBindVertexArray(0);
	renderShader.UnUse();
}
开发者ID:ArturSoczek,项目名称:OpenGLInsightsCode,代码行数:9,代码来源:main.cpp

示例7: DrawGrid

void DrawGrid()
{ 
	renderShader.Use();
		glBindVertexArray(gridVAOID); 
		glUniformMatrix4fv(renderShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));						
			glDrawElements(GL_LINES, grid_indices.size(),GL_UNSIGNED_SHORT,0);
		glBindVertexArray(0);
	renderShader.UnUse();
}
开发者ID:ArturSoczek,项目名称:OpenGLInsightsCode,代码行数:9,代码来源:main.cpp

示例8: computeHistogram

void computeHistogram() {
	glViewport(0, 0, WIDTH, HEIGHT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor(0.0, 0.0, 0.0, 0.0);

	glDisable(GL_DEPTH_TEST);
	//Enable blending
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);
	//Additive
	glBlendEquation(GL_FUNC_ADD);
	
	hist.Use();

	glBindBuffer(GL_ARRAY_BUFFER, HistogramVBO);

	glVertexAttribPointer(hist["vPosition"], 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GL_FLOAT), (void*)0);
	glEnableVertexAttribArray(hist["vPosition"]);

	glUniform1i(hist("tex"), 0);
	glUniform1f(hist("textureWidth"), (float)WIDTH);
	glUniform1f(hist("textureHeight"), (float)HEIGHT);

	glBindFramebuffer(GL_FRAMEBUFFER, FBO);
	//glClear(GL_COLOR_BUFFER_BIT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//Compute histogram
	glDrawArrays(GL_POINTS, 0, WIDTH*HEIGHT);


	glBindBuffer(GL_ARRAY_BUFFER, 0);
	hist.UnUse();
	//Disable blending
	glDisable(GL_BLEND);

	float hPixels[256];
	glReadPixels(0, 0, 256, 1, GL_BLUE, GL_FLOAT, hPixels);

	int sum = 0;
	if (printed != 0) 
	{
		cout << "\n\n-----------\n\n";
		for(int j = 0; j < 256; j++)
		{
			//if((j % 3) == 0)
				cout << j << ":" << hPixels[j] << endl;
				sum += hPixels[j];
		}
		cout << endl << sum << endl;
		printed--;
	}
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
开发者ID:mafian89,项目名称:GMU,代码行数:54,代码来源:GMU.cpp

示例9: OnRender

//display callback function
void OnRender() {

	GL_CHECK_ERRORS

	//clear colour and depth buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	//set the camera transform
	glm::mat4 T		= glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
	glm::mat4 Rx	= glm::rotate(T,  rX, glm::vec3(1.0f, 0.0f, 0.0f));
	glm::mat4 MV    = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
	 
	//1) Render scene from the light's POV
	//enable rendering to FBO
 	glBindFramebuffer(GL_FRAMEBUFFER,fboID);
	//clear depth buffer
	glClear(GL_DEPTH_BUFFER_BIT);
	//reset viewport to the shadow map texture size
	glViewport(0,0,SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT);
	
	//enable front face culling
	glCullFace(GL_FRONT);
		//draw scene from the point of view of light
		DrawScene(MV_L, P_L);
	//enable back face culling
	glCullFace(GL_BACK);

	//restore normal rendering path
	//unbind FBO, set the default back buffer and reset the viewport to screen size
	glBindFramebuffer(GL_FRAMEBUFFER,0);
	glDrawBuffer(GL_BACK_LEFT);
	glViewport(0,0,WIDTH, HEIGHT);

	//2) Render scene from point of view of eye
	DrawScene(MV, P, 0 );

	//bind light gizmo vertex array object
	glBindVertexArray(lightVAOID); {
		//set the flat shader
		flatshader.Use();
			//set the light's transform and render 3 lines
			glm::mat4 T = glm::translate(glm::mat4(1), lightPosOS);
			glUniformMatrix4fv(flatshader("MVP"), 1, GL_FALSE, glm::value_ptr(P*MV*T));
				glDrawArrays(GL_LINES, 0, 6);
		//unbind shader
		flatshader.UnUse();
	}
		
	//unbind the vertex array object
	glBindVertexArray(0);	

	//swap front and back buffers to show the rendered result
	glutSwapBuffers();
}
开发者ID:bagobor,项目名称:opengl33_dev_cookbook_2013,代码行数:55,代码来源:main.cpp

示例10: OnRender

void OnRender() {
	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
	GL_CHECK_ERRORS

	shader.Use();

	drawDefaultBox();

	shader.UnUse();

	glutSwapBuffers();
}
开发者ID:GunioRobot,项目名称:all,代码行数:12,代码来源:main.cpp

示例11: DrawClothPoints

void DrawClothPoints()
{ 
	particleShader.Use();
		//glBindVertexArray(clothVAOID); 
		glUniform1i(particleShader("selected_index"), selected_index);
		glUniformMatrix4fv(particleShader("MV"), 1, GL_FALSE, glm::value_ptr(mMV));	
		glUniformMatrix4fv(particleShader("MVP"), 1, GL_FALSE, glm::value_ptr(mMVP));										
			//draw the masses last						
			glDrawArrays(GL_POINTS, 0, total_points);					
		glBindVertexArray(0);
	particleShader.UnUse();	
}
开发者ID:ArturSoczek,项目名称:OpenGLInsightsCode,代码行数:12,代码来源:main.cpp

示例12: OnRender

//display function
void OnRender() {
	//clear the colour and depth buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	//bind shader
	shader.Use();
		//draw the full screen quad
		glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
	//unbind shader
	shader.UnUse();

	//swap front and back buffers to show the rendered result
	glutSwapBuffers();
}
开发者ID:bagobor,项目名称:opengl33_dev_cookbook_2013,代码行数:15,代码来源:main.cpp

示例13: InitShaders

void InitShaders(void)
{
	shader.LoadFromFile(GL_VERTEX_SHADER, "../CGE_solarsystem/shader.vert");
	shader.LoadFromFile(GL_FRAGMENT_SHADER, "../CGE_solarsystem/shader.frag");
	shader.CreateAndLinkProgram();
	shader.Use();
	shader.AddAttribute("vVertex");
	shader.AddAttribute("vUV");
	shader.AddUniform("MVP");
	shader.AddUniform("textureMap");
	glUniform1i(shader("textureMap"), 0);
	shader.UnUse();

	GL_CHECK_ERRORS
}
开发者ID:karinmae,项目名称:CGE,代码行数:15,代码来源:SolarSystem.cpp

示例14: OnRender

void OnRender() {
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glm::mat4 T		= glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
	glm::mat4 Rx	= glm::rotate(T,  rX, glm::vec3(1.0f, 0.0f, 0.0f));
	glm::mat4 Ry	= glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));
	glm::mat4 MV	= Ry;
    glm::mat4 MVP	= P*MV;

	//glBindVertexArray(vaoID);
		shader.Use();				
			glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
				glDrawElements(GL_TRIANGLES, TOTAL_INDICES, GL_UNSIGNED_INT, 0);
		shader.UnUse();
	//glBindVertexArray(0);

	glutSwapBuffers();
}
开发者ID:EiffelOberon,项目名称:opengl33_dev_cookbook_2013,代码行数:17,代码来源:main.cpp

示例15: OnRender

//display callback function
void OnRender() {
	GL_CHECK_ERRORS
	//set the camera transform
	glm::mat4 Tr	= glm::translate(glm::mat4(1.0f),glm::vec3(0.0f, 0.0f, dist));
	glm::mat4 Rx	= glm::rotate(Tr,  rX, glm::vec3(1.0f, 0.0f, 0.0f));
	glm::mat4 MV    = glm::rotate(Rx, rY, glm::vec3(0.0f, 1.0f, 0.0f));

	//clear the colour and depth buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	//get the combined modelview projection matrix
    glm::mat4 MVP	= P*MV;

	//render the grid object
	grid->Render(glm::value_ptr(MVP));

	//set the modelling transform to move the marhing result to origin
	glm::mat4 T = glm::translate(glm::mat4(1), glm::vec3(-0.5,-0.5,-0.5));

	//if rendering mode set to wireframe we set the front and back 
	//polygon mode to line
	if(bWireframe)
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	
	//set the volume marcher vertex array object
	glBindVertexArray(volumeMarcherVAO);
		//bind the shader
		shader.Use();
			//set the shader uniforms
			glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP*T));
				//render the triangles
				glDrawArrays(GL_TRIANGLES, 0, marcher->GetTotalVertices());
		//unbind the shader
		shader.UnUse();
	
	//restore the default polygon mode
	if(bWireframe)
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	//swap front and back buffers to show the rendered result
	glutSwapBuffers();
}
开发者ID:RebelliousX,项目名称:opengl33_dev_cookbook_2013,代码行数:43,代码来源:main.cpp


注:本文中的GLSLShader::UnUse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。