其他分享
首页 > 其他分享> > unigine ffp 渲染图片

unigine ffp 渲染图片

作者:互联网

 使用unigine版本 2.7.2

项目需求,将ffp用于对图片的畸变矫正。

int render() override
	{
		render(Game::get()->getTime());
		return 1;
	}

	
	TextureRenderPtr texturerender;
	TexturePtr tempT;
	TexturePtr tempT1;
	void render(float time)
	{
		App *app = App::get();
		Ffp *ffp = Ffp::get();
		int width = app->getWidth();
		int height = app->getHeight();
		RenderState *render_state = RenderState::get();
		
		// screen size
		
		float radius = height / 2.0f;

		if (!texturerender.get()) {
			texturerender = TextureRender::create();
			texturerender->create2D(512,512, TextureRender::TEXTURE_COLOR);
			tempT = Texture::create();
			tempT->create2D(512, 512, Texture::FORMAT_RGBA8, Texture::USAGE_RENDER);
			
			tempT1 = Texture::create();
			ImagePtr img = Image::create();
			img->load("E:/temp1/0.png");
			//img->resize(512, 512);
			tempT1->setImage(img);
		}
		render_state->saveState();
		render_state->clearStates();
		texturerender->setColorTexture(0, tempT);
		texturerender->enable();
		tempT1->bindFragment(0);
		ffp->enable();//Ffp::MODE_SOLID
		ffp->setOrtho(width, height);
		

		// begin triangles
		ffp->beginTriangles();

		// vertex colors
		const unsigned int colors[] = { 0xffff0000, 0xff00ff00, 0xff0000ff };

		// create vertices
		int num_vertex = 16;
		for (int i = 0; i < num_vertex; i++)
		{
			float angle = UNIGINE_PI2 * i / (num_vertex - 1) - time;
			float x = width / 2 + sinf(angle) * radius;
			float y = height / 2 + cosf(angle) * radius;
			ffp->addVertex(x, y);
			ffp->setTexCoord(x / width, y / height);
			//ffp->setColor(colors[i % 3]);
		}

		// create indices
		for (int i = 1; i < num_vertex; i++)
		{
			ffp->addIndex(0);
			ffp->addIndex(i);
			ffp->addIndex(i - 1);
		}

		// end triangles
		ffp->endTriangles();
		//ffp->renderScreen();
		ffp->disable();
		tempT1->unbindFragment(0);
		texturerender->disable();
		ImagePtr img = Image::create();
		tempT->getImage(img);
		img->save("E:/temp1/10.png");
		render_state->clearStates();
		render_state->restoreState();
		//src->getImage(img);
		//img->save("E:/temp1/10.png");
		
	}

 

标签:img,render,渲染,int,unigine,ffp,texturerender,create
来源: https://blog.csdn.net/qiushangren/article/details/87982393