コード例 #1
0
void Demo::renderPartGPU(){
	
	CVK::Node* partGPUNode = new CVK::Node("partGPU");
	partGPUNode->setGeometry(partGeometry);
	partGPUNode->setMaterial(partMaterial);

	for (int j = 0; j < world->getAllPartNum(); j++){
		glm::vec3 temP = cuda->h_uVOpPos[j];	//h_uVOpPos
		//cout << temP.y << endl;
		partGPUNode->setModelMatrix(glm::translate(glm::mat4(1.0f), temP));
		partGPUNode->render();
	}
}
コード例 #2
0
ファイル: main.cpp プロジェクト: flair2005/VCTGI
int main() 
{
	// init GLFW and GLEW
	glfwInit();
	CVK::useOpenGL33CoreProfile();
	GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Normal Mapping", 0, 0);
	glfwSetWindowPos(window, 100, 50);
	glfwMakeContextCurrent(window);
	glewInit();
	glfwSetWindowSizeCallback(window, resizeCallback);
	glfwSetCharCallback(window, charCallback);

	// setup camera
	camera.setCenter(glm::vec3( 0.0f, 0.0f, 0.0f));
	camera.setRadius(5);
	camera.setNearFar(1.0f, 10.0f);
	CVK::State::getInstance()->setCamera(&camera);

	// setup light
	CVK::Light plight(glm::vec4(0.0f, 1.0, 10.0f, 1.0f), grey, glm::vec3( 0, 0, 0), 1.0f, 0.0f);
	CVK::State::getInstance()->addLight(&plight);

	// setup scene
	CVK::Node* node = new CVK::Node("Cube");
	// create and set teapot geometrie
	CVK::Cube* cube = new CVK::Cube(); 
	node->setGeometry(cube);
	// define material with diffuse color and normal texture
	CVK::Material matTex((char*)RESOURCES_PATH "/normalmapping/diffusemap.png", glm::vec3( 0.5f, 0.5f, 0.5f), glm::vec3( 0.3f, 0.3f, 0.3f), 120.0f);
	matTex.setTexture(CVK::NORMAL_TEXTURE, (char*)RESOURCES_PATH "/normalmapping/normalmap.png");
	CVK::Material matRed(glm::vec3(1.0,0.0,0.0), glm::vec3(1.0,1.0,1.0), 120.0f);
	useColorTexture = false;

	// phong shader
	const char *shadernames0[2] = {SHADERS_PATH "/NormalMapping/Phong.vert", SHADERS_PATH "/NormalMapping/Phong.frag"};
 	CVK::ShaderPhong phongShader = CVK::ShaderPhong( VERTEX_SHADER_BIT|FRAGMENT_SHADER_BIT, shadernames0);
 	//define Scene uniforms (ambient and fog)
	CVK::State::getInstance()->updateSceneSettings(glm::vec3(0.3,0.3,0.3), 0, glm::vec3(1.0,1.0,1.0), 1, 10, 1);
	// normal mapping shader
	const char *shadernames1[2] = {SHADERS_PATH "/NormalMapping/NormalMapping.vert", SHADERS_PATH "/NormalMapping/NormalMapping.frag"};
	ShaderNormalMapping normalMappingShader = ShaderNormalMapping( VERTEX_SHADER_BIT|FRAGMENT_SHADER_BIT, shadernames1);
	//use normal mapping shader
	useNormalMappingShader = false;

	// print infos
	std::cout << "Key s: " << "swap shader" << std::endl;
	std::cout << "Key m: " << "swap material" << std::endl;

	glClearColor(1.0, 1.0, 1.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);         
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);  

	while( !glfwWindowShouldClose(window))
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		// set active shader
		if(useNormalMappingShader)
			CVK::State::getInstance()->setShader(&normalMappingShader);
		else
			CVK::State::getInstance()->setShader(&phongShader);

		// set material
		if(useColorTexture)
			node->setMaterial(&matTex);
		else
			node->setMaterial(&matRed);
		
		// update camera
		camera.update(window);
		// update view, projection matrix, light uniforms
		CVK::State::getInstance()->getShader()->update();
		// render scene
		node->render();

		glfwSwapBuffers( window);
		glfwPollEvents();
	}
	glfwDestroyWindow(window);
	glfwTerminate();

	// clean up
	delete cube;
	delete node;

	return 0;
}
コード例 #3
0
void Demo::run(){

	// Init GLFW and GLEW
	glfwInit();
	CVK::useOpenGL33CoreProfile();
	GLFWwindow* window = glfwCreateWindow(windowWidth, windowHeight, "RBPE-Demo", 0, 0);
	glfwSetWindowPos( window, 100, 50);
	glfwMakeContextCurrent(window);

	glewInit();

	float pr = world->getPartRadius();
	float temp = pr * 3;
	cubeGeometry = new CVK::Cube(temp);
	partGeometry = new CVK::Sphere(pr);
	//material setzten, geht aber nur bei node, also in VO
	cubeMaterial = new CVK::Material((char*)RESOURCES_PATH "/cv_logo.bmp", black, grey, 100.0f);
	//cubeMaterial = new CVK::Material(red, white, 100.0f);	//!for transparency!
	//cubeMaterial->setAlpha(0.5);							//!for transparency!
	partMaterial = new CVK::Material(blue, white, 100.0f);

	//plane für boden
	plane = new CVK::Plane();
	CVK::Node* planeNode = new CVK::Node("Plane");
	CVK::Material mat_brick((char*)RESOURCES_PATH "/brick.bmp", black, darkgrey, 100.0f);
	planeNode->setGeometry(plane);
	planeNode->setMaterial(&mat_brick);
	planeNode->setModelMatrix(glm::rotate(glm::scale(glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, 0)), glm::vec3(10)), -90.0f, glm::vec3(1, 0, 0)));	//0.4=partdurchmesser
	demo->sceneRoot->addChild(planeNode);
	demo->partRoot->addChild(planeNode);

	camera->setCenter( glm::vec3( 0.0f, 0.0f, 0.0f));
	camera->setRadius( 30);
	camera->setNearFar( 1.0f, 100.0f);

	glfwSetWindowSizeCallback( window, resizeCallback);

	initScene();

	//load, compile and link Shader
	const char *shadernames[2] = {SHADERS_PATH "/Phong.vert", SHADERS_PATH "/Phong.frag"};
	CVK::ShaderPhong phongShader( VERTEX_SHADER_BIT|FRAGMENT_SHADER_BIT, shadernames);

	//OpenGL parameters
	glClearColor(1.0, 1.0, 1.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	CVK::State::getInstance()->setCamera( camera);

	//define light
	CVK::Light plight( glm::vec4( -1, 1, 1, 1), grey, glm::vec3( 0, 0, 0), 1.0f, 0.0f);
	CVK::State::getInstance()->addLight( &plight);

	//define Scene uniforms (ambient and fog)
	CVK::State::getInstance()->updateSceneSettings( darkgrey, 0, white, 1, 10, 1);
	CVK::State::getInstance()->setShader(&phongShader);

	//init cuda
	if(isGPU == true){
		cuda->initCUDA();
	}

	while( !glfwWindowShouldClose(window)){

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//time->startFrame();

		stepSimulation(duration);

		//Update Camera
		camera->update(window);

		//update shader and render
		phongShader.update();

		if (renderPart == false){
			//render würfel
			updateVOs();
			sceneRoot->render();
		}
		if (renderPart == true){
			//render partikel
			if (isGPU == true){
				updateVOs();
				planeNode->render();
				renderPartGPU();
			}
			else{
				partRoot->render();
			}
		}

		glfwSwapBuffers(window);
		glfwPollEvents();

		//time->endFrame();

		int fps = time->updateFPS();
		char title[64];
		sprintf_s(title, "Rigid Body | %d fps", fps);
		glfwSetWindowTitle(window, title);
	}
	cuda->~Cuda();	//free cuda stuff

	glfwDestroyWindow( window);
	glfwTerminate();
}