int CL_RenderBatch3D::set_batcher_active(CL_GraphicContext &gc)
{
	if (use_glyph_program != false)
	{
		gc.flush_batcher();
		use_glyph_program = false;
	}

	if (position == 0 || position+6 > max_vertices)
		gc.flush_batcher();
	gc.set_batcher(this);
	return 4;
}
int CL_RenderBatch3D::set_batcher_active(CL_GraphicContext &gc, const CL_Texture &texture, bool glyph_program, const CL_Colorf &new_constant_color)
{
	if (use_glyph_program != glyph_program || constant_color != new_constant_color)
	{
		gc.flush_batcher();
		use_glyph_program = glyph_program;
		constant_color = new_constant_color;
	}

	int texindex = -1;
	for (int i = 0; i < num_current_textures; i++)
	{
		if (current_textures[i] == texture)
		{
			texindex = i;
			break;
		}
	}
	if (texindex == -1 && num_current_textures < max_textures)
	{
		texindex = num_current_textures;
		current_textures[num_current_textures++] = texture;
		tex_sizes[texindex] = CL_Sizef((float)current_textures[texindex].get_width(), (float)current_textures[texindex].get_height());
	}

	if (position == 0 || position+6 > max_vertices || texindex == -1)
	{
		gc.flush_batcher();
		texindex = 0;
		current_textures[texindex] = texture;
		num_current_textures = 1;
		tex_sizes[texindex] = CL_Sizef((float)current_textures[texindex].get_width(), (float)current_textures[texindex].get_height());
	}
	gc.set_batcher(this);
	return texindex;
}
Exemple #3
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	CL_DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_title("MapMode Example");
	win_desc.set_size(CL_Size( 800, 480 ), false);

	CL_DisplayWindow window(win_desc);
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	CL_String theme;
	if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw CL_Exception("No themes found");

	CL_GUIWindowManagerTexture wm(window);
	CL_GUIManager gui(wm, theme);
	
	CL_GraphicContext gc = window.get_gc();

	// Deleted automatically by the GUI
	Options *options = new Options(gui, CL_Rect(0, 0, gc.get_size()));

	CL_Image image_grid(gc, "../Blend/Resources/grid.png");
	CL_Image image_ball(gc, "../Blend/Resources/ball.png");
	float grid_width = (float) image_grid.get_width();
	float grid_height = (float) image_grid.get_height();

	grid_space = (float) (image_grid.get_width() - image_ball.get_width());

	setup_balls();

	options->request_repaint();

	unsigned int time_last = CL_System::get_time();

	while (!quit)
	{
		unsigned int time_now = CL_System::get_time();
		float time_diff = (float) (time_now - time_last);
		time_last = time_now;

		wm.process();
		wm.draw_windows(gc);

		int num_balls = options->num_balls;
		if (num_balls > max_balls)
			num_balls = max_balls;

		if (options->is_moveballs_set)
			move_balls(time_diff, num_balls);

		gc.set_map_mode(options->current_mapmode);

		const float grid_xpos = 10.0f;
		const float grid_ypos = 10.0f;

		if (options->current_mapmode == cl_user_projection)
		{
			CL_Sizef area_size(grid_width + (grid_xpos * 2.0f), grid_height + (grid_ypos * 2.0f));
			set_user_projection(gc, area_size, options);
		}

		// Draw the grid
		image_grid.draw(gc, grid_xpos, grid_ypos);

		gc.flush_batcher();	// <--- Fix me, this should not be required for cl_user_projection

		for (int cnt=0; cnt<num_balls; cnt++)
		{
			image_ball.draw(gc, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos);
		}

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_projection(CL_Mat4f::identity());

		gc.set_map_mode(cl_map_2d_upper_left);

		window.flip(1);

		CL_KeepAlive::process();
	}
	return 0;
}