void Fluid2DParticlesApp::draw()
{
    // clear out the window with black
    gl::clear( Color( 0, 0, 0 ) );

    gl::color( ColorAf( 1.0f, 1.0f, 1.0f, 0.999f ) );
    float* data = const_cast<float*>( (float*)mFluid2D.rgb().data() );
    Surface32f surf( data, mFluid2D.resX(), mFluid2D.resY(), mFluid2D.resX()*sizeof(Colorf), SurfaceChannelOrder::RGB );


    if ( ! mTex ) {
        mTex = gl::Texture::create( surf );
    } else {
        mTex->update( surf );
    }
    gl::draw( mTex, getWindowBounds() );
    mTex->unbind();
    mParticles.draw();
    mParams.draw();
}
示例#2
0
void renderScene(){
        
    // Clear framebuffer & depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //where should the camera look at?
    cameraTransform();

    glDisable(GL_LIGHTING);//disable lighting not to affect the drawings of meta-objects

    drawAxes();

    drawGrid();

    glEnable(GL_LIGHTING);//resume lighting

    //WITH = All the light will NOT move with the camera (light fixed even if i rotate)
    //Because i tell at every frame to fix the light at those 2 points
    glLightfv(GL_LIGHT0, GL_POSITION, left_light_position);
    glLightfv(GL_LIGHT1, GL_POSITION, right_light_position);

    glColor3f(0.5,0.5,0.5);

    field.getCollisionPlane().draw(Vector3f(0.93, 0.82, 0)); //WTF only certain colors work. JK it's because number must be float.. then why tf there are some 255 every now and then (e.g. axes)


    glPushMatrix();
    glTranslatef(field.getBlackHoleCentre().x,field.getBlackHoleCentre().y,field.getBlackHoleCentre().z);
    glColor3f(0.7,0.5,0);
    glutSolidSphere(0.1f,4,4);
    glPopMatrix();

    field.draw();


    //TODO pause button
    field.update();
	
	glutSwapBuffers();
        
}
示例#3
0
void display () {

	if (wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	}

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	// Clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	enter3D();

	gluLookAt(camera.x, camera.y, camera.z,
			  cameraLookAt.x, cameraLookAt.y, cameraLookAt.z,
			  cameraUp.x, cameraUp.y, cameraUp.z);

	glPushMatrix();
	glScaled(1.0, -1.0, 1.0);

	if (showSky) {
		drawSky();
	}

	// Draw coordinate axis
	// glCallList(axisList);

	for (int i = 0; i < 9; i ++) {
		gravitationalForce[i].draw();
	}

	if (showGround) {
		drawGround();
	}

	if (showPipe) {
		glPushMatrix();
			drawSprinkler(emitterSpacing * emitterCount, sprinkerHeight, 100, 5.0, 40.0);
		glPopMatrix();
	}

	if (showMountains) {
		drawMoutains(3000, 0, 0);
		drawMoutains(4000, 180, -200);
		drawMoutains(5600, 45, -500);
	}

	if (showTrees) {
		drawTrees();
	}

	if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) {
		Texture::set("shine");
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	}

	particleSystem.draw();

	if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) {
		Texture::done();
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}

	/*glPushMatrix();
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(0.0, -100.0, 0.0);
	glScalef(100.0, -100.0, 100.0);
	drawModel();
	glPopMatrix();*/

	if (wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}

	glDisable(GL_DEPTH_TEST);
	enter2D();

	glColor4d(0.0, 0.0, 0.0, 1.0);
	sprintf(fpsText, "FPS:%4.2f", fps);
	drawText(GLUT_BITMAP_HELVETICA_18, windowWidth - 100, 20, fpsText);

	if (showHUD) {

		drawText(GLUT_BITMAP_HELVETICA_18, 10, 20, "Water sprinkler");

		sprintf(cameraText, "%4.2f %4.2f %4.2f", camera.x, camera.y, camera.z);
		drawText(GLUT_BITMAP_HELVETICA_12, 10, 60, cameraText);

		sprintf(particleText, "Particles: %llu", particleSystem.getParticleCount());
		drawText(GLUT_BITMAP_HELVETICA_12, 10, 100, particleText);

		if (menu) {

			// Current option
			glColor4d(0.2, 0.2, 0.2, 0.8);
			glRectd(10, windowHeight - 40, 120, windowHeight - 10);
			glColor4d(1.0, 1.0, 1.0, 1.0);
			drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, options[currentOption]);

			// Current option value
			glColor4d(0.4, 0.4, 0.4, 0.8);
			glRectd(120, windowHeight - 40, 240, windowHeight - 10);
			glColor4d(1.0, 1.0, 1.0, 1.0);

			switch (currentOption) {
			case 0: sprintf(optionValue, "%4.2f", Particle::initialVelocity); break;
			case 1: sprintf(optionValue, "%d", initialColour); break;
			case 2: sprintf(optionValue, "%d", gravityIntensity); break;
			case 3: sprintf(optionValue, "%d", Particle::startLifeSpan); break;
			case 4: sprintf(optionValue, "%s", renderModes[renderMode]); break;
			case 5: sprintf(optionValue, "%d", emitterCount); break;
			case 6: sprintf(optionValue, "%d", emitterSpacing); break;
			case 7: sprintf(optionValue, "%s", cameras[currentCamera]); break;
			case 8: sprintf(optionValue, "%4.2f", Particle::airResistance); break;
			case 9: sprintf(optionValue, "%s", cycleColours ? "On" : "Off"); break;
			case 10: sprintf(optionValue, "%d", emitFrequency); break;
			case 11: sprintf(optionValue, "%4.2f", ParticleEmitter::emitSpread); break;
			case 12: sprintf(optionValue, "%d", ParticleSystem::perEmit); break;
			case 13: sprintf(optionValue, "%s", ParticleEmitter::show ? "Yes" : "No"); break;
			case 14: sprintf(optionValue, "%s", wireframe ? "Yes" : "No"); break;
			case 15: sprintf(optionValue, "%s", showMountains ? "On" : "Off"); break;
			case 16: sprintf(optionValue, "%s", showTrees ? "On" : "Off"); break;
			case 17: sprintf(optionValue, "%s", showSky ? "On" : "Off"); break;
			case 18: sprintf(optionValue, "%s", showGround ? "On" : "Off"); break;
			case 19: sprintf(optionValue, "%s", demos[demo]->name.c_str()); break;
			case 20: sprintf(optionValue, "%1.1f", Particle::bounce); break;
			case 21: sprintf(optionValue, "%s", skyTexture ? "On" : "Off"); break;
			case 22: sprintf(optionValue, "%s", grassTexture ? "On" : "Off"); break;
			case 23: sprintf(optionValue, "%s", showPipe ? "On" : "Off"); break;
			case 24: sprintf(optionValue, "%s", ParticleEmitter::randomness ? "On" : "Off"); break;
			case 25: sprintf(optionValue, "%s", Tree::drawLeaves ? "On" : "Off"); break;
			default: sprintf(optionValue, "%s", ""); break;
			}

			drawText(GLUT_BITMAP_HELVETICA_12, 130, windowHeight - 20, optionValue);

		}
		else {
			glColor4d(1.0, 1.0, 1.0, 1.0);
			drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, "Press m to toggle menu");
		}

		for (int i = 1; i < 10; i++) {
			if (selectedGravitationalForce == i - 1) {
				glColor4d(1.0, 0.4, 0.4, 0.8);
			}
			else {
				glColor4d(0.4, 0.4, 1.0, 0.2);
			}
			glRectd(200 + ((i - 1) * 50), 10, 230 + ((i - 1) * 50), 40);
			glColor4d(0.0, 0.0, 0.0, 1.0);
			sprintf(n, "%d", i);
			drawText(GLUT_BITMAP_HELVETICA_18, 210 + ((i - 1) * 50), 30, n);
		}

	}

	if (currentCamera == 3) {
		glBegin(GL_LINES);
			glColor3d(0.8, 0.8, 0.8);
			glVertex2d((windowWidth / 2) - 30, windowHeight / 2);
			glVertex2d((windowWidth / 2) + 30, windowHeight / 2);
			glVertex2d(windowWidth / 2, (windowHeight / 2) - 30);
			glVertex2d(windowWidth / 2, (windowHeight / 2) + 30);
		glEnd();
	}

	glPopMatrix();

	glutSwapBuffers();
	glutPostRedisplay();
}
void display() { 
    glClear(GL_COLOR_BUFFER_BIT);  
    psys.draw();
    glutSwapBuffers();
}
void Demo::draw() {
  gl::clear( Color(1, 1, 1) );
  particleSystem->draw();
}
示例#6
0
void Projekt::DrawScene()
{
	//---------------------------------------------------------------------------
	// Render scene to shadow map
	//---------------------------------------------------------------------------
	mShadowMap->BindDsvAndSetNullRenderTarget(mDirect3D->GetImmediateContext());
	drawSceneToShadowMap();

	mDirect3D->GetImmediateContext()->RSSetState(0);

	// Restore back and depth buffer and viewport to the OM stage
	ID3D11RenderTargetView* renderTargets[1] = {mDirect3D->GetRenderTargetView()};
	mDirect3D->GetImmediateContext()->OMSetRenderTargets(1, renderTargets, mDirect3D->GetDepthStencilView());
	mDirect3D->GetImmediateContext()->ClearRenderTargetView(mDirect3D->GetRenderTargetView(), reinterpret_cast<const float*>(&Colors::LightSteelBlue));

	mDirect3D->GetImmediateContext()->ClearDepthStencilView(mDirect3D->GetDepthStencilView(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
	mDirect3D->GetImmediateContext()->RSSetViewports(1, &mDirect3D->GetScreenViewport());

	// Possible Wireframe render state
	if (GetAsyncKeyState('E') & 0x8000)
		mDirect3D->GetImmediateContext()->RSSetState(WireFrameRS);

	XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform);

	//---------------------------------------------------------------------------
	// Draw terrain
	//---------------------------------------------------------------------------
	//mTerrain.Draw(mDirect3D->GetImmediateContext(), mCam, mDirLights);

	mTerrain.DrawShadowed(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera(), mDirLights,
		mShadowMap->getDepthMapSRV(), &shadowTransform);

	// --------------------------------------------------------------------------

	// Camera matrices
	XMMATRIX view = mPlayer.GetCamera()->getViewMatrix();
	XMMATRIX proj = mPlayer.GetCamera()->getProjMatrix();
	XMMATRIX viewproj = mPlayer.GetCamera()->getViewProjMatrix();

	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};

	// Set per frame constants
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mPlayer.GetCamera()->getPosition());
	Effects::BasicFX->setShadowMap(mShadowMap->getDepthMapSRV());
	Effects::BasicFX->SetCubeMap(mSky->cubeMapSRV());

	Effects::NormalMapFX->SetDirLights(mDirLights);
	Effects::NormalMapFX->SetEyePosW(mPlayer.GetCamera()->getPosition());
	Effects::NormalMapFX->setShadowMap(mShadowMap->getDepthMapSRV());
	Effects::NormalMapFX->SetCubeMap(mSky->cubeMapSRV());

	XMMATRIX world;
	XMMATRIX worldInvTranspose;
	XMMATRIX worldViewProj;

	// Transform NDC space [-1,+1]^2 to texture space [0,1]^2
	XMMATRIX toTexSpace(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, -0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.0f, 1.0f);

	// Vertex size & offset
	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;

	// Draw player
	//mPlayer.Draw(mDirect3D->GetImmediateContext(), mDirLights,
		//mShadowMap->getDepthMapSRV(), &shadowTransform);

	//---------------------------------------------------------------------------
	// Draw opaque objects
	//---------------------------------------------------------------------------
	// Bind information about primitive type, and set input layout
	mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::Basic32);

	// Set our effect technique to use
	ID3DX11EffectTechnique* activeTech = Effects::BasicFX->DirLights3FogTexTech;
	ID3DX11EffectTechnique* activeSkinnedTech = Effects::NormalMapFX->DirLights3TexTech;

	D3DX11_TECHNIQUE_DESC techDesc;

	//--------------------------------------------------------------------------------
	// Draw opaque tessellated objects
	//--------------------------------------------------------------------------------
	Effects::BasicTessFX->SetDirLights(mDirLights);
	Effects::BasicTessFX->SetEyePosW(mPlayer.GetCamera()->getPosition());
	Effects::BasicTessFX->setShadowMap(mShadowMap->getDepthMapSRV());
	Effects::BasicTessFX->SetCubeMap(mSky->cubeMapSRV());

	mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);
	mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::PosNormalTexTan);

	activeTech = Effects::BasicTessFX->TessDirLights3FogTexTech;
	activeTech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT mIndex = 0; mIndex < mGenericInstances.size(); ++mIndex)
		{
			if (mGenericInstances[mIndex].isVisible)
			{
				world = XMLoadFloat4x4(&mGenericInstances[mIndex].world);
				worldInvTranspose = MathHelper::InverseTranspose(world);
				worldViewProj = world*view*proj;

				Effects::BasicTessFX->SetWorld(world);
				Effects::BasicTessFX->SetWorldInvTranspose(worldInvTranspose);
				Effects::BasicTessFX->SetWorldViewProj(worldViewProj);
				Effects::BasicTessFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
				Effects::BasicTessFX->setShadowTransform(world*shadowTransform);
				Effects::BasicTessFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));
				Effects::BasicTessFX->SetMinTessDistance(20.0f);
				Effects::BasicTessFX->SetMaxTessDistance(200.0f);
				Effects::BasicTessFX->SetMinTessFactor(0.0f);
				Effects::BasicTessFX->SetMaxTessFactor(3.0f);
				Effects::BasicTessFX->setFogStart(GameSettings::Instance()->Fog()->fogStart);
				Effects::BasicTessFX->setFogRange(GameSettings::Instance()->Fog()->fogRange);

				
				Effects::BasicTessFX->setFogColor(Colors::Silver);

				for (UINT i = 0; i < mGenericInstances[mIndex].model->meshCount; ++i)
				{
					UINT matIndex = mGenericInstances[mIndex].model->meshes[i].MaterialIndex;

					Effects::BasicTessFX->SetMaterial(mGenericInstances[mIndex].model->mat[matIndex]);

					Effects::BasicTessFX->SetDiffuseMap(mGenericInstances[mIndex].model->diffuseMapSRV[matIndex]);
					//Effects::BasicTessFX->SetNormalMap(mGenericInstances[mIndex].model->normalMapSRV[matIndex]);

					activeTech->GetPassByIndex(p)->Apply(0, mDirect3D->GetImmediateContext());
					mGenericInstances[mIndex].model->meshes[i].draw(mDirect3D->GetImmediateContext());
				}
			}
		}
	}

	// FX sets tessellation stages, but it does not disable them.  So do that here
	// to turn off tessellation.
	mDirect3D->GetImmediateContext()->HSSetShader(0, 0, 0);
	mDirect3D->GetImmediateContext()->DSSetShader(0, 0, 0);

	mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::PosNormalTexTanSkinned);

	// Skinned objects
	activeSkinnedTech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT mIndex = 0; mIndex < mGenSkinnedInstances.size(); ++mIndex)
		{
			if (mGenSkinnedInstances[mIndex].isVisible)
			{
				world = XMLoadFloat4x4(&mGenSkinnedInstances[mIndex].world);
				worldInvTranspose = MathHelper::InverseTranspose(world);
				worldViewProj = world*view*proj;

				Effects::NormalMapFX->SetWorld(world);
				Effects::NormalMapFX->SetWorldInvTranspose(worldInvTranspose);
				Effects::NormalMapFX->SetWorldViewProj(worldViewProj);
				Effects::NormalMapFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
				Effects::NormalMapFX->setShadowTransform(world*shadowTransform);
				Effects::NormalMapFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));
				Effects::NormalMapFX->setFogStart(GameSettings::Instance()->Fog()->fogStart);
				Effects::NormalMapFX->setFogRange(GameSettings::Instance()->Fog()->fogRange);
				Effects::NormalMapFX->setBoneTransforms(&mGenSkinnedInstances[mIndex].FinalTransforms[0],
					mGenSkinnedInstances[mIndex].FinalTransforms.size());


				Effects::BasicTessFX->setFogColor(Colors::Silver);

				for (UINT i = 0; i < mGenSkinnedInstances[mIndex].model->numMeshes; ++i)
				{
					UINT matIndex = mGenSkinnedInstances[mIndex].model->meshes[i].MaterialIndex;

					Effects::NormalMapFX->SetMaterial(mGenSkinnedInstances[mIndex].model->mat[matIndex]);

					Effects::NormalMapFX->SetDiffuseMap(mGenSkinnedInstances[mIndex].model->diffuseMapSRV[matIndex]);

					Effects::NormalMapFX->setNormalMap(mGenSkinnedInstances[mIndex].model->normalMapSRV[matIndex]);

					activeSkinnedTech->GetPassByIndex(p)->Apply(0, mDirect3D->GetImmediateContext());
					mGenSkinnedInstances[mIndex].model->meshes[i].draw(mDirect3D->GetImmediateContext());
				}
			}
		}
	}

	//---------------------------------------------------------------------------
	// Draw particle systems
	//---------------------------------------------------------------------------
	mFire.setEyePos(mPlayer.GetCamera()->getPosition());
	mFire.draw(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera());
	mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); // restore default

	//---------------------------------------------------------------------------
	// Draw sky
	//---------------------------------------------------------------------------
	mSky->draw(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera());

	// Unbind shadow map and AmbientMap as a shader input because we are going to render
	// to it next frame.  These textures can be at any slot, so clear all slots.
	ID3D11ShaderResourceView* nullSRV[16] = { 0 };
	mDirect3D->GetImmediateContext()->PSSetShaderResources(0, 16, nullSRV);

	// Restore default states
	mDirect3D->GetImmediateContext()->RSSetState(0);
	mDirect3D->GetImmediateContext()->OMSetDepthStencilState(0, 0);
	mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); 

	HR(mDirect3D->GetSwapChain()->Present(0, 0));
}