当前位置: 首页>>代码示例>>C++>>正文


C++ Printer::SetColor方法代码示例

本文整理汇总了C++中Printer::SetColor方法的典型用法代码示例。如果您正苦于以下问题:C++ Printer::SetColor方法的具体用法?C++ Printer::SetColor怎么用?C++ Printer::SetColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Printer的用法示例。


在下文中一共展示了Printer::SetColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: InteractiveDemo

int InteractiveDemo( void )
{
	if (SDL_Init(SDL_INIT_VIDEO) == -1) {
		std::cout << SDL_GetError() << std::endl;
		return 1;
	}
	atexit(SDL_Quit);
	if (SDL_SetVideoMode(512, 512, 24, SDL_SWSURFACE|SDL_DOUBLEBUF) == NULL) {
		std::cout << SDL_GetError() << std::endl;
		return 1;
	}
	SDL_WM_SetCaption("SWSL test", NULL);

	const float side_len = 300.0f;
	const float base_len = side_len * sin(mmlPI / 3.0f);

	mmlVector<2> a_pos  = mmlVector<2>(side_len * 0.5f,     0.0f);
	mmlVector<2> b_pos  = mmlVector<2>(side_len,        base_len);
	mmlVector<2> c_pos  = mmlVector<2>(    0.0f,        base_len);
	mmlVector<2> center = (a_pos + b_pos + c_pos) / 3.0f;
	a_pos -= center;
	b_pos -= center;
	c_pos -= center;

	SDL_Event        event;
	swsl::Shader     shader;
	bool             quit = false;
	bool             reload_shader = true;
	bool             shader_status = false;
	swsl::Rasterizer raster;
	Printer          p;

	p.SetColor(0, 255, 0);

	raster.CreateBuffers(video->w, video->h);
	raster.SetShader(&shader);

	while (!quit) {

		Uint32 frame_start = SDL_GetTicks();

		if (reload_shader) {
			reload_shader = false;
			shader_status = LoadShader("../swsl_samples/interactive.swsl", shader);
		}

		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_r) {
					reload_shader = true;
				}
				break;
			case SDL_QUIT: quit = true; break;
			}
		}

		Vertex<3> a, b, c;

		//mmlMatrix<2,2> rmat = mml2DRotationMatrix((float)SDL_GetTicks() / 1000.0f);
		mmlMatrix<2,2> rmat = mmlMatrix<2,2>::IdentityMatrix();
		mmlVector<2>   at   = a_pos * rmat;
		mmlVector<2>   bt   = b_pos * rmat;
		mmlVector<2>   ct   = c_pos * rmat;

		a.coord.x = round(at[0]) + video->w / 2;
		a.coord.y = round(at[1]) + video->h / 2;
		b.coord.x = round(bt[0]) + video->w / 2;
		b.coord.y = round(bt[1]) + video->h / 2;
		c.coord.x = round(ct[0]) + video->w / 2;
		c.coord.y = round(ct[1]) + video->h / 2;

		a.attributes[0] = 1.0f;
		a.attributes[1] = 0.0f;
		a.attributes[2] = 0.0f;
		b.attributes[0] = 0.0f;
		b.attributes[1] = 1.0f;
		b.attributes[2] = 0.0f;
		c.attributes[0] = 0.0f;
		c.attributes[1] = 0.0f;
		c.attributes[2] = 1.0f;

		//float rgb[] = { 1.0f, 1.0f, 1.0f };
		//raster.ClearBuffers(rgb);
		raster.ClearBuffers();

		Uint32 render_start = SDL_GetTicks();
		raster.FillTriangle(a.coord, b.coord, c.coord, a.attributes, b.attributes, c.attributes);
		Uint32 render_end = SDL_GetTicks();
		Uint32 render_time = render_end - render_start;

		raster.WriteColorBuffer((mtlByte*)video->pixels, video->format->BytesPerPixel, ByteOrder());

		if (!shader_status) {
			p.SetColor(255, 0, 0);
			p.Print("Shader execution failed");
			p.Newline();
		} else {
			p.SetColor(0, 255, 0);
		}
//.........这里部分代码省略.........
开发者ID:SirJonthe,项目名称:SWSL,代码行数:101,代码来源:main.cpp


注:本文中的Printer::SetColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。