Пример #1
0
void LabelImpl::draw(CL_GraphicContext &p_gc)
{
	G_ASSERT(m_parent->isLoaded());

	float ax, ay;
	const CL_Size s = m_parent->size(p_gc);

	calculateAttachPoint(s.width, s.height, ax, ay);

	CL_Pointf position;
	position.x = m_pos.x - ax;
	position.y = m_pos.y - ay - m_fontMetrics.get_descent();

	if (m_shadowVisible) {
		drawShadow(p_gc, position);
	}

	m_clFont->draw_text(p_gc, position.x, position.y, m_text, m_color);

#if !defined(NDEBUG) && defined(DRAW_LABEL_BOUNDS)
	// draw label frame debug code
	CL_Pen newPen;
	newPen.set_line_width(1.0f);

	const CL_Pen oldPen = p_gc.get_pen();
	p_gc.set_pen(newPen);

	const float y2 = y + m_fontMetrics.get_descent();
	CL_Draw::box(p_gc, x, y2 - s.height, x + s.width, y2, CL_Colorf::red);

	p_gc.set_pen(oldPen);
#endif // !NDEBUG && DRAW_LABEL_BOUNDS
}
Пример #2
0
void TireTrack::draw(CL_GraphicContext &p_gc)
{
	CL_Pen pen;
	pen.set_line_width(3);
	p_gc.set_pen(pen);

	// TODO: how to make blend?
	CL_Draw::line(p_gc, m_fromPoint, m_toPoint, CL_Colorf(0.0f, 0.0f, 0.0f, m_fromAlpha));
}
Пример #3
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	CL_OpenGLWindowDescription win_desc;
	//win_desc.set_version(3, 2, false);
	win_desc.set_allow_resize(true);
	win_desc.set_title("Point Sprite 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_Texture texture_particle(gc, "Resources/particle.png");
	float grid_width = (float) image_grid.get_width();
	float grid_height = (float) image_grid.get_height();

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

	setup_particles();

	CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, text_shader_vertex);
	if(!vertex_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log()));
	}

	CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, text_shader_fragment);
	if(!fragment_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log()));
	}

	CL_ProgramObject program_object(gc);
	program_object.attach(vertex_shader);
	program_object.attach(fragment_shader);
	program_object.bind_attribute_location(0, "InPosition");
	program_object.bind_attribute_location(1, "InColor");
	if (!program_object.link())
	{
		throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log()));
	}

	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_particles = options->num_particles;
		if (num_particles > max_particles)
			num_particles = max_particles;

		move_particles(time_diff, num_particles);

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

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

		if (num_particles > 0)
		{
			std::vector<CL_Vec2f> positions;
			std::vector<CL_Vec4f> colors;
			positions.resize(num_particles);
			colors.resize(num_particles);

			for (int cnt=0; cnt<num_particles; cnt++)
			{
				positions[cnt] = CL_Vec2f(grid_xpos + particles[cnt].xpos, grid_ypos + particles[cnt].ypos);
				switch (cnt % 3)
				{
					case 0:
						colors[cnt] = CL_Vec4f(1.0f, 0.0f, 0.0f, 1.0f);
						break;
					case 1:
						colors[cnt] = CL_Vec4f(0.0f, 1.0f, 0.0f, 1.0f);
						break;
					case 2:
						colors[cnt] = CL_Vec4f(0.0f, 0.0f, 1.0f, 1.0f);
						break;
				}
			};

			CL_BlendMode blend;
			blend.enable_blending(true);
			blend.set_blend_function(cl_blend_src_alpha, cl_blend_one, cl_blend_src_alpha, cl_blend_one);
			gc.set_blend_mode(blend);
			CL_Pen pen;
			pen.enable_point_sprite(true);
			pen.set_point_size(options->point_size);
			pen.set_point_sprite_origin(cl_point_sprite_origin_upper_left);
			gc.set_pen(pen);

			program_object.set_uniform1i("Texture0", 0);

			gc.set_texture(0, texture_particle);
			CL_PrimitivesArray prim_array(gc);
			prim_array.set_attributes(0, &positions[0]);
			prim_array.set_attributes(1, &colors[0]);
			gc.set_program_object(program_object);
			gc.draw_primitives(cl_points, num_particles, prim_array);
			gc.reset_program_object();
			gc.reset_texture(0);
			gc.reset_blend_mode();

			gc.reset_pen();
		}

		window.flip(1);

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