Пример #1
0
	void Text::changeColor (SDL_Color& color, SDL_Renderer* renderer)
	{
		destroy ();
		surfaceFromTTF (color);

		SDL_DestroyTexture (_texture);
		textureFromSurface (renderer);
	}
Пример #2
0
	void Text::update (const std::string& text, SDL_Color& color, SDL_Renderer* renderer)
	{
		this->text = text;
		SDL_FreeSurface (_image);
		surfaceFromTTF (color);

		SDL_DestroyTexture (_texture);
		textureFromSurface (renderer);
	}
Пример #3
0
void Renderer::drawToBuffer()
{
	cellGcmSetSurface(&surfaces[swapValue]);
	clear_buffer();

	this->SetCurrentShader(*texturedVert, *texturedFrag);
	//this->SetCurrentShader(*basicVert, *basicFrag);
	Matrix4 aProjMatrix = Matrix4::orthographic(-1, 1, -1, 1, 0, 1);
	viewMatrix = Matrix4::identity();
	viewMatrix.setElem(1,1,-1.0f);
	modelMatrix = Matrix4::identity();
	cellGcmSetDepthTestEnable(CELL_GCM_FALSE);
	currentVert->UpdateShaderMatrices(modelMatrix, viewMatrix, aProjMatrix);
	
	textureFromSurface(colorTexture, deferredLight[0]);
	initMesh->SetDefaultTexture(colorTexture);
	SetTextureSampler(currentFrag->GetParameter("texture"), initMesh->GetDefaultTexture());
	initMesh->Draw(*texturedVert, *texturedFrag);
	//initMesh->Draw(*basicVert, *basicFrag);
}
Пример #4
0
void Renderer::combineBuffers()
{
	cellGcmSetSurface(&surfaces[swapValue]);
	cellGcmSetDitherEnable(CELL_GCM_TRUE);
	clear_buffer();
	cellGcmSetCullFace(CELL_GCM_BACK);
	cellGcmSetBlendFunc(CELL_GCM_ONE, CELL_GCM_ZERO, CELL_GCM_ONE, CELL_GCM_ZERO);

	this->SetCurrentShader(*combineVert, *combineFrag);
	
	//cellGcmSetDitherEnable(CELL_GCM_TRUE);
	
	Matrix4 aProjMatrix = Matrix4::orthographic(-1, 1, -1, 1, 0, 1);
	viewMatrix = Matrix4::identity();
	modelMatrix = Matrix4::identity();
	//viewMatrix.setElem(1,1,-1.0f);
	//aProjMatrix.setElem(1,1,2.0f);
	modelMatrix = Matrix4::identity();
	currentVert->UpdateShaderMatrices(modelMatrix, viewMatrix, aProjMatrix);

	//textureFromSurface(lightEmissiveTexture, deferredLight[1]);
	//textureFromSurface(lightSpecularTexture, deferredLight[1], 1);	
	
	//textureFromSurface(colorTexture, deferredLight[0], 0);
	//textureFromSurface(colorTexture, deferredLight[0], 0);
	textureFromSurface(colorTexture, deferredLight[1], 0);
	//textureFromSurface(normalTexture, deferredLight[0], 1);

	SetTextureSampler(currentFrag->GetParameter("diffuseTex"), &colorTexture);
	//SetTextureSampler(currentFrag->GetParameter("emissiveTex"), &colorTexture);
	//SetTextureSampler(currentFrag->GetParameter("specularTex"), &colorTexture);
	//SetTextureSampler(currentFrag->GetParameter("emissiveTex"), &lightEmissiveTexture);
	//SetTextureSampler(currentFrag->GetParameter("specularTex"), &lightSpecularTexture);
	
	currentFrag->UpdateShaderVariables();
	
	initMesh->Draw(*combineVert, *combineFrag);	
}
Пример #5
0
void Renderer::drawPointLights()
{
	cellGcmSetSurface(&deferredLight[1]);
	cellGcmSetDitherEnable(CELL_GCM_FALSE);
	clear_buffer();
	this->SetCurrentShader(*pointLightVert, *pointLightFrag);
	
	cellGcmSetColorMaskMrt(CELL_GCM_COLOR_MASK_MRT1_A |
						   CELL_GCM_COLOR_MASK_MRT1_R |
						   CELL_GCM_COLOR_MASK_MRT1_G |
						   CELL_GCM_COLOR_MASK_MRT1_B);

	//cellGcmSetClearColor((0<<0)|(0<<8)|(0<<16)|(255<<24)); //glClearColor(0,0,0,1);
	//cellGcmSetClearSurface(CELL_GCM_CLEAR_Z | CELL_GCM_CLEAR_R | CELL_GCM_CLEAR_G | CELL_GCM_CLEAR_B);
	cellGcmSetBlendEnable(CELL_GCM_TRUE);
	cellGcmSetBlendFunc(CELL_GCM_ONE, CELL_GCM_ONE, CELL_GCM_ONE, CELL_GCM_ONE);
	
	textureFromSurface(depthTexture, deferredLight[0], -1);
	textureFromSurface(normalTexture, deferredLight[0], 1);

	SetTextureSampler(currentFrag->GetParameter("depthTex"), &depthTexture);
	SetTextureSampler(currentFrag->GetParameter("normTex"), &normalTexture);
		
	Vector3 cPosV = camera->GetPosition();
	float pixelSize[2] = {1.0f / screen_width, 1.0f / screen_height};
	currentFrag->SetParameter("cameraPos", (float *)&cPosV, false);
	currentFrag->SetParameter("pixelSize", pixelSize, false);

	Vector3 translate = Vector3((RAW_HEIGHT * HEIGHTMAP_X / 2.0f),
								500,
								(RAW_HEIGHT * HEIGHTMAP_Z / 2.0f));
	Matrix4 pushMatrix = Matrix4::translation(translate);
	Matrix4 popMatrix = Matrix4::translation(-translate);

	for(int x = 0; x < LIGHTS; ++x)
	{
		for(int z = 0; z < LIGHTS; ++z)
		{
			Light &l = light[(x * LIGHTS) + z];
			float radius = l.radius;

			modelMatrix = pushMatrix * 
						  Matrix4::rotation(rotation, Vector3(0, 1, 0)) *
						  popMatrix *
						  Matrix4::translation(l.position) * 
						  Matrix4::scale(Vector3(radius, radius, radius));

			l.position.setX(modelMatrix.getElem(3,0));
			l.position.setY(modelMatrix.getElem(3,1));
			l.position.setZ(modelMatrix.getElem(3,2));

			float *lPosition = (float *)&light->position;
			float *lColour = (float *)&light->colour;
			setLightShaderUniform(lPosition, lColour, &radius);
			currentVert->UpdateShaderMatrices(modelMatrix, viewMatrix, projMatrix);

			Vector3 val = l.position - cPosV;
			float dist = length(val);

			if(dist < radius)
			{
				cellGcmSetCullFace(CELL_GCM_FRONT);
			}
			else
			{
				cellGcmSetCullFace(CELL_GCM_BACK);
			}
			sphere->Draw(*pointLightVert, *pointLightFrag);
		}
	}
	
	//cellGcmSetCullFace(CELL_GCM_BACK);
	//cellGcmSetBlendFunc(CELL_GCM_ONE, CELL_GCM_ZERO, CELL_GCM_ONE, CELL_GCM_ZERO);
	//glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
	//cellGcmSetClearColor((64<<0)|(64<<8)|(64<<16));

	cellGcmSetColorMaskMrt(0);
	//glClearColor (0.2f ,0.2f ,0.2f ,1);
	//glBindFramebuffer ( GL_FRAMEBUFFER , 0);
	//glUseProgram (0);
	
}