unigine ffp 渲染图片

 使用unigine版本 2.7.2
项目需求,将ffp通过设置uv用于对图片的畸变矫正。

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();
    render_state->clearBuffer(RenderState::BUFFER_COLOR, vec4(0.0f));//清空当前输出的render中的colorbuffer的内容
	tempT1->bindFragment(0);//因为在shader中,输入的纹理都是通过纹理坐标[0,1]来访问的,输入的大小与输出的大小可以不用有任何关联
	ffp->enable();//Ffp::MODE_SOLID
	ffp->setOrtho(width, height);//宽和高的设定,也就是下面的vertex的范围。默认是范围是[0,1]
		

	// 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++)//vertexs
	{
		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);//x [0,width] y[0,height]
		ffp->setTexCoord(x / width, y / height);
		//ffp->setColor(colors[i % 3]);
	}

	// create indices
	for (int i = 1; i < num_vertex; i++)//triangles
	{
		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");
		
}

unigine ffp 渲染图片_第1张图片

你可能感兴趣的:(unigine,c++,ffp)