示例#1
0
///
//Renders the OctTree
//
//Parameters:
//	nodeToRender: THe node of the oct tree being rendered
//	modelViewProjectionMatrix: THe modelViewProjectionMatrix to send to the shader
//	viewMatrix: THe view matrix of the camera
//	projectionMatrix: The projection matrix of the camera
//	mesh: The mesh to draw as a representation of the oct tree
void RenderingManager_RenderOctTree(OctTree_Node* nodeToRender, Matrix* modelViewProjectionMatrix, Matrix* viewMatrix, Matrix* projectionMatrix, Mesh* mesh)
{
	//Only render trees which contain objects?

	//If this node has children, draw them too
	if(nodeToRender->children != NULL)
	{
		for(int i = 0; i < 8; i++)
		{
			RenderingManager_RenderOctTree(nodeToRender->children + i, modelViewProjectionMatrix, viewMatrix, projectionMatrix, mesh);
		}
	}
	else
	{
		//Set modelViewMatrix to identity
		Matrix_ToIdentity(modelViewProjectionMatrix);

		//Set the scale values of the modelViewProjection Matrix
		*Matrix_Index(modelViewProjectionMatrix, 0, 0) = nodeToRender->right;
		*Matrix_Index(modelViewProjectionMatrix, 1, 1) = nodeToRender->top;
		*Matrix_Index(modelViewProjectionMatrix, 2, 2) = nodeToRender->front;

		//Set modelMatrix uniform
		glProgramUniformMatrix4fv(renderingBuffer->shaderPrograms[0]->shaderProgramID, renderingBuffer->shaderPrograms[0]->modelMatrixLocation, 1, GL_TRUE, modelViewProjectionMatrix->components);

		//Construct modelViewProjection
		Matrix_TransformMatrix(viewMatrix, modelViewProjectionMatrix);
		Matrix_TransformMatrix(projectionMatrix, modelViewProjectionMatrix);
		//Set modelViewProjectionMatrix uniform
		glProgramUniformMatrix4fv(renderingBuffer->shaderPrograms[0]->shaderProgramID, renderingBuffer->shaderPrograms[0]->modelViewProjectionMatrixLocation, 1, GL_TRUE, modelViewProjectionMatrix->components);

		//Render node
		Mesh_Render(mesh, GL_LINES);
	}
}
示例#2
0
//------------------------------------------------------------------------------
void
bindProgram(GLuint program)
{
    glUseProgram(program);

    // shader uniform setting
    GLint position = glGetUniformLocation(program, "lightSource[0].position");
    GLint ambient = glGetUniformLocation(program, "lightSource[0].ambient");
    GLint diffuse = glGetUniformLocation(program, "lightSource[0].diffuse");
    GLint specular = glGetUniformLocation(program, "lightSource[0].specular");
    GLint position1 = glGetUniformLocation(program, "lightSource[1].position");
    GLint ambient1 = glGetUniformLocation(program, "lightSource[1].ambient");
    GLint diffuse1 = glGetUniformLocation(program, "lightSource[1].diffuse");
    GLint specular1 = glGetUniformLocation(program, "lightSource[1].specular");
    
    glProgramUniform4f(program, position, 0.5, 0.2f, 1.0f, 0.0f);
    glProgramUniform4f(program, ambient, 0.1f, 0.1f, 0.1f, 1.0f);
    glProgramUniform4f(program, diffuse, 0.7f, 0.7f, 0.7f, 1.0f);
    glProgramUniform4f(program, specular, 0.8f, 0.8f, 0.8f, 1.0f);
    
    glProgramUniform4f(program, position1, -0.8f, 0.4f, -1.0f, 0.0f);
    glProgramUniform4f(program, ambient1, 0.0f, 0.0f, 0.0f, 1.0f);
    glProgramUniform4f(program, diffuse1, 0.5f, 0.5f, 0.5f, 1.0f);
    glProgramUniform4f(program, specular1, 0.8f, 0.8f, 0.8f, 1.0f);

    GLint otcMatrix = glGetUniformLocation(program, "objectToClipMatrix");
    GLint oteMatrix = glGetUniformLocation(program, "objectToEyeMatrix");
    GLfloat modelView[16], proj[16], mvp[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
    glGetFloatv(GL_PROJECTION_MATRIX, proj);
    multMatrix(mvp, modelView, proj);
    glProgramUniformMatrix4fv(program, otcMatrix, 1, false, mvp);
    glProgramUniformMatrix4fv(program, oteMatrix, 1, false, modelView);
}
void renderCamSetupGL ( Scene& scene, int prog )
{
	// Set model, view, projection matrices
	Camera3D* cam = scene.getCamera ();	
	Matrix4F ident;
	ident.Identity();	
	glProgramUniformMatrix4fv( prog, scene.getParam(prog, UMODEL), 1, GL_FALSE, ident.GetDataF() );
	glProgramUniformMatrix4fv( prog, scene.getParam(prog, UVIEW), 1, GL_FALSE, cam->getViewMatrix().GetDataF() ); 
	glProgramUniformMatrix4fv( prog, scene.getParam(prog, UPROJ), 1, GL_FALSE, cam->getProjMatrix().GetDataF() );
}
示例#4
0
 void Shader::setUniform(const std::string & uniformName, const glm::mat4 & matrix)
 {
     if (m_uniforms_locations.count(uniformName))
     {
         glProgramUniformMatrix4fv(m_program_id, m_uniforms_locations[uniformName], 1, GL_FALSE, glm::value_ptr(matrix));
     }
     else
     {
         if (getUniformLocation(uniformName))
         {
             glProgramUniformMatrix4fv(m_program_id, m_uniforms_locations[uniformName], 1, GL_FALSE, glm::value_ptr(matrix));
         }
     }
 }
示例#5
0
 void Shader::setUniform(const std::string & uniformName, glm::mat4 * matrices, unsigned count)
 {
     if (m_uniforms_locations.count(uniformName))
     {
         glProgramUniformMatrix4fv(m_program_id, m_uniforms_locations[uniformName], count, GL_FALSE, &matrices[0][0][0]);
     }
     else
     {
         if (getUniformLocation(uniformName))
         {
             glProgramUniformMatrix4fv(m_program_id, m_uniforms_locations[uniformName], count, GL_FALSE, &matrices[0][0][0]);
         }
     }
 }
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glm::mat4 Projection = glm::ortho(-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f);
		glm::mat4 View = glm::mat4(1.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * View * Model;

		glProgramUniformMatrix4fv(ProgramName[LAYERING], UniformMVP[LAYERING], 1, GL_FALSE, &MVP[0][0]);
		glProgramUniformMatrix4fv(ProgramName[VIEWPORT], UniformMVP[VIEWPORT], 1, GL_FALSE, &MVP[0][0]);
		glProgramUniform1i(ProgramName[VIEWPORT], UniformDiffuse, 0);

		// Pass 1
		{
			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
			glViewportIndexedfv(0, &glm::vec4(0, 0, FRAMEBUFFER_SIZE)[0]);

			glUseProgram(ProgramName[LAYERING]);

			glBindVertexArray(VertexArrayName[LAYERING]);
			glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);
		}

		// Pass 2
		{
			GLint Border = 2;

			glBindFramebuffer(GL_FRAMEBUFFER, 0);
		
			glClearBufferfv(GL_COLOR, 0, &glm::vec4(0)[0]);
		
			glViewportIndexedfv(0, &glm::vec4(Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]);
			glViewportIndexedfv(1, &glm::vec4((WindowSize.x * 0.5f) + Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]);
			glViewportIndexedfv(2, &glm::vec4((WindowSize.x * 0.5f) + Border, (WindowSize.y * 0.5f) + 1, WindowSize * 0.5f - 2.0f * Border)[0]);
			glViewportIndexedfv(3, &glm::vec4(Border, (WindowSize.y * 0.5f) + Border, WindowSize * 0.5f - 2.0f * Border)[0]);

			glUseProgram(ProgramName[VIEWPORT]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName);
			glBindSampler(0, SamplerName);

			glBindVertexArray(VertexArrayName[VIEWPORT]);
			glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0);
		}

		return true;
	}
示例#7
0
void MainWindow::paintGL() {
    glClearColor(0.1f,0.6f,0.3f,1);
    glClearDepth(1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if (thisData->elements_size) {
        //thisData->updateNormalMVP();
        glEnable(GL_DEPTH_TEST);
        glUseProgram(thisData->program);
        glBindVertexArray(thisData->vao);
        glProgramUniformMatrix4fv(thisData->program,1,1,false,glm::value_ptr(thisData->mvp));
        glProgramUniformMatrix4fv(thisData->program,2,1,false,glm::value_ptr(thisData->normal_mvp) );
        glDrawElements(GL_TRIANGLES,thisData->elements_size,GL_UNSIGNED_INT,nullptr);
        glDisable(GL_DEPTH_TEST);
    }
}
void display()
{
	glm::mat4 Projection = glm::ortho(-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f);
	glm::mat4 View = glm::mat4(1.0f);
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glProgramUniformMatrix4fv(ProgramName[LAYERING], UniformMVP[LAYERING], 1, GL_FALSE, &MVP[0][0]);
	glProgramUniformMatrix4fv(ProgramName[IMAGE_2D], UniformMVP[IMAGE_2D], 1, GL_FALSE, &MVP[0][0]);
	glProgramUniform1i(ProgramName[IMAGE_2D], UniformDiffuse, 0);

	// Pass 1
	{
		glBindSampler(0, 0);
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y));

		glUseProgram(ProgramName[LAYERING]);

		glBindVertexArray(VertexArrayName[LAYERING]);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[BUFFER_ELEMENT]);
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);
	}

	// Pass 2
	{
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		glUseProgram(ProgramName[IMAGE_2D]);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName);
		glBindSampler(0, SamplerName);

		glBindVertexArray(VertexArrayName[IMAGE_2D]);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[BUFFER_ELEMENT]);

		for(int i = 0; i < 4; ++i)
		{
			glProgramUniform1i(ProgramName[IMAGE_2D], UniformLayer, i);
			glViewportIndexedfv(0, &glm::vec4(Viewport[i])[0]);
			glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);
		}
	}

	glf::checkError("display");
	glf::swapBuffers();
}
示例#9
0
void Material::Bind()
{
	glUseProgram(program);
	for (std::unordered_map<std::string, Texture2D*>::iterator it = textures.begin(); it != textures.end(); ++it)
	{
		it->second->Bind();
	}
	for (std::unordered_map<std::string, ShaderVariable>::iterator it = uniforms.begin(); it != uniforms.end(); ++it)
	{
		ShaderVariable v = it->second;
		switch (v.size)
		{
		case 1:
			glProgramUniform1f(program, v.index, data[v.offset]);
			break;
		case 2:
			glProgramUniform2f(program, v.index, data[v.offset], data[v.offset + 1]);
			break;
		case 3:
			glProgramUniform3f(program, v.index, data[v.offset], data[v.offset + 1], data[v.offset + 2]);
			break;
		case 4:
			glProgramUniform4f(program, v.index, data[v.offset], data[v.offset + 1], data[v.offset + 2], data[v.offset + 3]);
			break;
		case 16:
			glProgramUniformMatrix4fv(program, v.index, 1, GL_TRUE, &data[v.offset]);
			break;
		}
	}
}
void display()
{
	// Compute the MVP (Model View Projection matrix)
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	// Set the value of uniforms
	glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]);
	glProgramUniform4fv(ProgramName[program::FRAG], UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	// Set the display viewport
	glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]);

	// Clear color buffer with white
	float Depth(1.0f);
	glClearBufferfv(GL_DEPTH, 0, &Depth);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

	// Bind program
	glBindProgramPipeline(PipelineName);

	// Bind vertex array & draw 
	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); // Must be called after glBindVertexArray
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);

	glf::checkError("display");
	glf::swapBuffers();
}
示例#11
0
文件: r_sky.c 项目: raynorpat/cake
void R_DrawSkyChain (msurface_t *surf)
{
	msurface_t *reversechain = NULL;
	int numindexes = 0;

	if (!surf) return;

	// push the depth range back to far end of the z-buffer
	// rogue has some pretty - unusual - brush placement and needs this
	glDepthRange (gldepthmax, gldepthmax);
	glProgramUniformMatrix4fv (gl_skycubeprog, u_skylocalMatrix, 1, GL_FALSE, r_mvpmatrix.m[0]);
	glEnable (GL_TEXTURE_CUBE_MAP_SEAMLESS);

	GL_UseProgram (gl_skycubeprog);
	GL_BindTexture (GL_TEXTURE0, GL_TEXTURE_CUBE_MAP, r_skysampler, r_skytexture);
	GL_Enable (DEPTHTEST_BIT | (gl_cull->value ? CULLFACE_BIT : 0));

	for (; surf; surf = surf->texturechain)
	{
		surf->reversechain = reversechain;
		reversechain = surf;
		numindexes += surf->numindexes;
	}

	R_DrawSurfaceChain (reversechain, numindexes);

	glDepthRange (gldepthmin, gldepthmax);
	glDisable (GL_TEXTURE_CUBE_MAP_SEAMLESS);
}
示例#12
0
void ssquadResize(RenderPacket* ssquad, float* proj, float x, float y, float w, float h)
{
    uint32 proj_loc   = glGetUniformLocation(ssquad->vsh, "proj");
    uint32 offset_loc = glGetUniformLocation(ssquad->vsh, "offset");
    glProgramUniformMatrix4fv(ssquad->vsh, proj_loc, 1, false, proj);
    glProgramUniform4f(ssquad->vsh, offset_loc, x, y, w, h);
}
void display()
{
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y + 45.0f, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x + 45.0f, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glProgramUniformMatrix4fv(ProgramName, UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));

	float Depth(1.0f);
	glClearBufferfv(GL_DEPTH, 0, &Depth);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

	glUseProgram(ProgramName);

	glBindVertexArray(VertexArrayName);
	glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 10);

	glf::swapBuffers();
	glf::checkError("display");
}
示例#14
0
static void shader_setval_data(shader_t shader, sparam_t param,
		const void *val, int count)
{
	if (!matching_shader(shader, param))
		return;

	if (param->type == SHADER_PARAM_BOOL ||
	    param->type == SHADER_PARAM_INT) {
		glProgramUniform1iv(shader->program, param->param, count, val);
		gl_success("glProgramUniform1iv");

	} else if (param->type == SHADER_PARAM_FLOAT) {
		glProgramUniform1fv(shader->program, param->param, count, val);
		gl_success("glProgramUniform1fv");

	} else if (param->type == SHADER_PARAM_VEC2) {
		glProgramUniform2fv(shader->program, param->param, count, val);
		gl_success("glProgramUniform2fv");

	} else if (param->type == SHADER_PARAM_VEC3) {
		glProgramUniform3fv(shader->program, param->param, count, val);
		gl_success("glProgramUniform3fv");

	} else if (param->type == SHADER_PARAM_VEC4) {
		glProgramUniform4fv(shader->program, param->param, count, val);
		gl_success("glProgramUniform4fv");

	} else if (param->type == SHADER_PARAM_MATRIX4X4) {
		glProgramUniformMatrix4fv(shader->program, param->param,
				count, false, val);
		gl_success("glProgramUniformMatrix4fv");
	}
}
void display()
{
	// Compute the MVP (Model View Projection matrix)
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslateZ = glm::translate(glm::mat4(1.0), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslateZ, float(Window.RotationCurrent.y), glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 ViewRotateY = glm::rotate(ViewRotateX, float(Window.RotationCurrent.x), glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 View = ViewRotateY;
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]);
	glProgramUniform1i(ProgramName[program::FRAG], UniformDiffuse, 0);

	glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

	glBindProgramPipeline(PipelineName);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, Texture2DName);

	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); //!\ Need to be called after glBindVertexArray
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, NULL, 1, 0);

	glf::checkError("display");
	glf::swapBuffers();
}
示例#16
0
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * this->view() * Model;

		glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]);
		glProgramUniform1i(ProgramName[program::FRAG], UniformDiffuse, 0);

		glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize.x, WindowSize.y)[0]);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

		glBindProgramPipeline(PipelineName);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, Texture2DName);

		glBindVertexArray(VertexArrayName);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); //!\ Need to be called after glBindVertexArray
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, nullptr, 1, 0);

		return true;
	}
void display()
{
	// Compute the MVP (Model View Projection matrix)
	glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	// Set the value of MVP uniform.
	glProgramUniformMatrix4fv(ProgramName, UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	// Clear color buffer with black
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

	// Bind program
	glUseProgram(ProgramName);

	// Bind vertex array & draw 
	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBufferName);

	// Set the display viewport
	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));
	glProvokingVertex(GL_LAST_VERTEX_CONVENTION);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);

	glf::checkError("display");
	glf::swapBuffers();
}
示例#18
0
文件: vsMathLib.cpp 项目: pfac/CG-PI
// universal
void
VSMathLib::matrixToGL(MatrixTypes aType)
{
	if (mInit) {
	
		if (mBlocks) {
			if (mUniformName[aType] != "") {
				if (mUniformArrayIndex[aType]) {
					VSShaderLib::setBlockUniformArrayElement(mBlockName, 
														mUniformName[aType],
														mUniformArrayIndex[aType],
														mMatrix[aType]);
				}
				else {
					VSShaderLib::setBlockUniform(mBlockName, 
											mUniformName[aType], 
											mMatrix[aType]);
				}
			}
		}
		else {
			int p,loc;
			if (mUniformName[aType] != "") {
				glGetIntegerv(GL_CURRENT_PROGRAM,&p);
				loc = glGetUniformLocation(p, mUniformName[aType].c_str());
				glProgramUniformMatrix4fv(p, loc, 1, false, mMatrix[aType]);
			}
		}
	
	}
}
void display()
{
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size)[0]);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

	glBindProgramPipeline(PipelineName);

	glBindVertexArray(VertexArrayName);
	glPatchParameteri(GL_PATCH_VERTICES, VertexCount);
	glDrawArraysInstanced(GL_PATCHES, 0, VertexCount, 1);

	glf::checkError("display");
	glf::swapBuffers();
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

		glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * this->view() * Model;

		glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]);

		glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

		glBindProgramPipeline(PipelineName);

		glBindVertexArray(VertexArrayName);
		glPatchParameteri(GL_PATCH_VERTICES, VertexCount);

		assert(!validate(ProgramName[program::VERT]));
		glDrawArraysInstancedBaseInstance(GL_PATCHES, 0, VertexCount, 1, 0);

		return true;
	}
void display()
{
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glProgramUniform4fv(ProgramName, UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);
	glProgramUniformMatrix4fv(ProgramName, UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));

	float Depth(1.0f);
	glClearBufferfv(GL_DEPTH, 0, &Depth);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

	glUseProgram(ProgramName);

	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBufferName);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, 0, 1, 4);

	glf::swapBuffers();
	glf::checkError("display");
}
示例#22
0
void SuzanneGL::Update()
{
	if (processInput)
	{
		float rotAmount = 0.0f;
		glm::mat4 rotMatrix;
		if (input.right || input.left)
		{
			if (input.right)
				rotAmount = rotDelta;
			if (input.left)
				rotAmount = -rotDelta;
			rotMatrix = glm::rotate(glm::mat4(1.0f), glm::radians(rotAmount), up);
		}
		else if (input.up || input.down)
		{
			if (input.up)
				rotAmount = -rotDelta;
			if (input.down)
				rotAmount = rotDelta;
			rotMatrix = glm::rotate(glm::mat4(1.0f), glm::radians(rotAmount), right);
		}

		eye = glm::vec3(rotMatrix * glm::vec4(eye, 1.0f));
		right = glm::normalize(-glm::cross(up, (center - eye)));

		glm::mat4 viewMatrix = glm::lookAt(eye, center, up);
		glProgramUniformMatrix4fv(shaderProgram, viewMatrixIndex, 1, GL_FALSE, glm::value_ptr(viewMatrix));
		input.Reset();
	}
}
示例#23
0
文件: shader.cpp 项目: MEC402/cruft
void
ShaderProgram::setUniform(const char* param, const glm::mat4& val)
{
  unsigned int loc = getUniformLocation(param);
  //  gl_check(glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(val)));
  gl_check(glProgramUniformMatrix4fv(m_programId, loc, 1, GL_FALSE, glm::value_ptr(val)));
}
void renderFB(GLuint Texture2DName)
{
	glm::mat4 Perspective = glm::perspective(45.0f, float(Window.Size.x) / Window.Size.y, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Perspective * View * Model;
	
	glProgramUniformMatrix4fv(ProgramName[program::VERTEX], UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

	glBindMultiTextureEXT(GL_TEXTURE0, GL_TEXTURE_2D, Texture2DName);
	glBindSampler(0, SamplerName);

	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);

	glf::checkError("renderFB");
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		// Compute the MVP (Model View Projection matrix)
		glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * this->view() * Model;

		// Set the value of uniforms
		glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]);
		glProgramUniform4fv(ProgramName[program::FRAG], UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		// Set the display viewport
		glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize.x, WindowSize.y)[0]);

		// Clear color buffer with white
		float Depth(1.0f);
		glClearBufferfv(GL_DEPTH, 0, &Depth);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		// Bind program
		glBindProgramPipeline(PipelineName);

		// Bind vertex array & draw 
		glBindVertexArray(VertexArrayName);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); // Must be called after glBindVertexArray
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0);

		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glm::mat4 Projection = glm::ortho(-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f);
		glm::mat4 View = glm::mat4(1.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * View * Model;

		glProgramUniformMatrix4fv(ProgramName[LAYERING], UniformMVP[LAYERING], 1, GL_FALSE, &MVP[0][0]);
		glProgramUniformMatrix4fv(ProgramName[VIEWPORT], UniformMVP[VIEWPORT], 1, GL_FALSE, &MVP[0][0]);

		// Pass 1
		{
			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
	//		glBindFramebuffer(GL_FRAMEBUFFER, 0);
			glViewportIndexedfv(0, &glm::vec4(0, 0, FRAMEBUFFER_SIZE)[0]);

			glBindProgramPipeline(PipelineName[LAYERING]);
			glBindVertexArray(VertexArrayName[LAYERING]);
			glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 4, 0);
		}

		// Pass 2
		{
			GLint Border = 2;

			glBindFramebuffer(GL_FRAMEBUFFER, 0);
			glViewportIndexedfv(0, &glm::vec4(Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]);
			glViewportIndexedfv(1, &glm::vec4((WindowSize.x * 0.5f) + Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]);
			glViewportIndexedfv(2, &glm::vec4((WindowSize.x * 0.5f) + Border, (WindowSize.y * 0.5f) + 1, WindowSize * 0.5f - 2.0f * Border)[0]);
			glViewportIndexedfv(3, &glm::vec4(Border, (WindowSize.y * 0.5f) + Border, WindowSize * 0.5f - 2.0f * Border)[0]);

			glBindProgramPipeline(PipelineName[VIEWPORT]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName);
			glBindSampler(0, SamplerName);

			glBindVertexArray(VertexArrayName[VIEWPORT]);
			glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 4, 0);
		}

		return true;
	}
示例#27
0
void Material::SetFloat4x4(std::string name, Matrix& value)
{
	int location = glGetUniformLocation(program, name.c_str());
	if (location == -1)
	{
		//std::cout << "Attempt made to set invalid uniform variable: " << name << std::endl;
	}
	glProgramUniformMatrix4fv(program, location, 1, GL_TRUE, &value.m11);
}
示例#28
0
//--------------------------------------------------------------------------
void HelperRenderer::Draw(		const glm::mat4& _projection,
                                const glm::mat4& _view,
                                const std::vector<Helper::Ptr>& _helpers)
{
    // Render lighting pass
    glUseProgram(program.id);
    glf::CheckError("Check program");
    glm::mat4 transform = _projection * _view;
    glProgramUniformMatrix4fv(program.id, transformVar,  1, GL_FALSE, &transform[0][0]);

    // Render at the same resolution than the original window
    // Draw all helpers
    for(unsigned int i=0; i<_helpers.size(); ++i)
    {
        glProgramUniformMatrix4fv(program.id, 	modelVar,  1, 	GL_FALSE, &_helpers[i]->transform[0][0]);
        _helpers[i]->vao.Draw(_helpers[i]->type,_helpers[i]->vbuffer.count);
    }
}
示例#29
0
void shader_setmatrix4(shader_t shader, sparam_t param,
		const struct matrix4 *val)
{
	if (matching_shader(shader, param)) {
		glProgramUniformMatrix4fv(shader->program, param->param, 1,
				false, val->x.ptr);
		gl_success("glProgramUniformMatrix4fv");
	}
}
示例#30
0
void pass(int width, int height, PassType type)
{
	glClear(GL_DEPTH_BUFFER_BIT);
	glClear(GL_COLOR_BUFFER_BIT);

	glProgramUniform1f(gs.program, COLOR, gs.color);

	//gs.lightPosition = glm::vec3(sin(gs.time / 10) * 1.5, cos(gs.time / 10) * 1.5, 3.5);
	glProgramUniform3fv(gs.program, LIGHT, 1, &gs.lightPosition[0]);

	switch (type)
	{
	case PassType::light:
		{
			glm::mat4 perspective = glm::perspective(45.0, (double)width / (double)height, 1.0, 100.0);
			glm::mat4 lookAt = glm::lookAt(gs.lightPosition, glm::vec3(0, 0, 0), glm::vec3(0, 0, 1));
			gs.mat = perspective*lookAt;
			gs.matLight = gs.mat;
			break;
		}
	default:
	case PassType::mainCamera:
		{
			glm::mat4 perspective = glm::perspective(45.0, (double)width / (double)height, 1.0, 100.0);
			//glm::mat4 lookAt = glm::lookAt(glm::vec3(3.5, 3.5, 2.5), glm::vec3(0, 0, 0), glm::vec3(0, 0, 1));
			glm::mat4 lookAt = glm::lookAt(glm::vec3(sin(gs.time / 10)*5.0, cos(gs.time / 10)*5.0, 1.5), glm::vec3(0, 0, 0), glm::vec3(0, 0, 1));
			gs.mat = perspective*lookAt;
			break;
		}
	}

	glProgramUniformMatrix4fv(gs.program, MATRIX, 1, false, &gs.mat[0][0]);
	glProgramUniformMatrix4fv(gs.program, MATRIXLIGHT, 1, false, &gs.matLight[0][0]);

	glUseProgram(gs.program);
	glBindVertexArray(gs.vao);

	{
		glDrawArrays(GL_TRIANGLES, 0, gs.bufferSize);
	}

	glBindVertexArray(0);
	glUseProgram(0);
}