예제 #1
0
파일: screen.c 프로젝트: 00001/plan9port
char *
getcmdstr(void)
{
	Event ev;
	int e;
	static ulong timekey = 0;
	ulong tracktm = 0;
	Dir *dir;

	if(track){
		if(timekey == 0)
			timekey = etimer(0, 5000);
		dir = dirstat(track);
		if(dir != nil){
			tracktm = dir->mtime;
			free(dir);
		}
	}
	for (;;) {
		e = event(&ev);
		if(resized){
			resized = 0;
			return "p";
		}
		if ((e & Emouse) && ev.mouse.buttons) {
			mouse = ev.mouse;
			return getmousestr();
		} else if (e & Ekeyboard)
			return getkbdstr(ev.kbdc);	/* sadly, no way to unget */
		else if (e & timekey) {
			if((dir = dirstat(track)) != nil){
				if(tracktm < dir->mtime){
					free(dir);
					return "q";
				}
				free(dir);
			}
		}
	}
}
예제 #2
0
void renderingTh(Tiin* t)
{
	t->display->makeActive(true);

	glm::vec3 dir = glm::vec3 (-0.7,-0.8,0.5);
	PhongShader skyShader;
	skyShader.setAmbient( glm::vec3 (0.1, 0.1, 0.1));
	skyShader.setDirLight( DirectionalLight (BaseLight( glm::vec3 (1.f,1.f,1.f), 2.0f), dir ));
	
	PhongTerrainShader shader;
	shader.setAmbient( glm::vec3 (0.1, 0.1, 0.1));
	shader.setDirLight( DirectionalLight( BaseLight( glm::vec3 (1.f,1.f,1.f), 1.5f), dir ));
	
	Texture* tex[3];
	tex[0] = new Texture(std::string(RESOURCE_FOLDER) + std::string("images/grass5.jpg"), GL_LINEAR);
	tex[1] = new Texture(std::string(RESOURCE_FOLDER) + std::string("images/rock3.jpg"), GL_LINEAR_MIPMAP_LINEAR);
	tex[2] = new Texture (std::string(RESOURCE_FOLDER) + std::string("images/rock4.jpg"), GL_LINEAR);

	Material terrainMaterial( glm::vec3 (1,1,1), 4.f);
	for ( int i = 0; i < 3 ; i++ )
	{
		terrainMaterial.addTexture(tex[i]);
	}

	Mesh skydome("resources/models/skydome.obj");
	Transform skyt(	glm::vec3(0,-5,0), glm::quat(0,0,0,1), 5000.f);


	Material skyMaterial( glm::vec3 (1,1,1), 2.f);
	Texture* tex2 = new Texture(std::string(RESOURCE_FOLDER) + std::string("images/sky.png"));
	skyMaterial.addTexture(tex2);


	float height = 4000.f;
	Generator gen(2000.f, 128, height);


	sf::Clock clock;
	//float old_time = clock.getElapsedTime().asSeconds();
	float frame = 0.0f;

	sf::Clock ftime;
	while(t->display->isRunning())
	{
	//	float delta_time;

	//	delta_time = clock.getElapsedTime().asSeconds() - old_time;	
	//	old_time = clock.getElapsedTime().asSeconds();

		float elsin = sinf(clock.getElapsedTime().asSeconds() * 0.2f);
		float elcos = cosf(clock.getElapsedTime().asSeconds() * 0.2f);
		 dir = glm::vec3 ( -elsin , -elcos , 0);

		 shader.setDirLight( DirectionalLight( BaseLight( glm::vec3 (0.8,0.8,0.8), 2.f ), dir ));
		 glm::vec3 ddir = dir * -1.f;
		 skyShader.setDirLight( DirectionalLight( BaseLight( glm::vec3 (0.8,0.8,0.8), 2.f ), ddir ));

		t->display->clear(0.5, 0.6, 0.7, 1.0);

        /* Render here */

		stimer("Prepare draw");	
		glm::vec3 camPos = t->camera->getAbsolutePos();
		Tmatricies pipe;
		pipe.view = t->camera->getView();
		pipe.projection = t->camera->getProjection();


		std::vector<glm::mat4> model;
		for (int i = 0; i < gen.counter; i++)
		{
			model.push_back(gen.m_chList[i]->getTransform().getTransMat());
		}

		//skydome
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_CULL_FACE);
		//glCullFace(GL_BACK);
		skyt.setPos( camPos - glm::vec3(0,2000,0));
		pipe.model = skyt.getTransMat();
		skyShader.bind();
		skyShader.updateUniforms( pipe, skyMaterial);
		skydome.draw();
		glBindTexture(GL_TEXTURE_2D, 0);
		//glCullFace(GL_FRONT);
		glEnable(GL_CULL_FACE);
		glEnable(GL_DEPTH_TEST);
		skyShader.unbind();


		etimer("Prepare draw");	
		if (wire)
			glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
		else
			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
        //
		// std::cout << "wire received " << ((wire) ? "true" : "false") << std::endl;
		stimer("Draw");	


		shader.bind();
		for (int i = 0; i < gen.counter; i++)
		{
			pipe.model = model[i];
			shader.updateUniforms(  pipe, terrainMaterial);
			gen.m_chList[i]->m_mesh->draw();
		}
		etimer("Draw");	

		glm::vec3 plPos = t->camera->getAbsolutePos();
		gen.generateChunkFromPos(plPos.x, plPos.z);

		frame++;
		if (ftime.getElapsedTime().asSeconds() >= 1.f)
		{
			std::cout << "fps: " << frame << std::endl;
			frame = 0;
			ftime.restart();
			
		}
		t->display->update();
	}


}