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();
	}
}
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();
}