Example #1
0
void why::Application::draw_game_over(clan::Canvas &c)
{
	using namespace boost;
	using namespace std;
	using namespace clan;

	static const string go("GAME OVER");
	static const string go2("Press Any Key To Continue");
	
	static Font fbig = m_rc_manager->get_font(80);
	float x = static_cast<float>(
		((c.get_width() / 2.0f) - (fbig.get_text_size(c, go).width / 2.0f))
		);
	float y = c.get_height() / 2.0f;
	
	draw_info_box(c);
	fbig.draw_text(c, x, y, go);

	static Font fsmall = m_rc_manager->get_font();
	
	y += fbig.get_font_metrics().get_height();
	x = static_cast<float>(
		((c.get_width() / 2.0f) - (fsmall.get_text_size(c, go2).width / 2.0f))
		);

	fsmall.draw_text(c, x, y, go2);
}
Example #2
0
void Timing::set_stars(clan::Canvas &canvas, int star_cnt)
{
	stars.clear();
	stars.resize(star_cnt);
	unsigned int random = 1231;
	int gc_width = canvas.get_width();
	int gc_height = canvas.get_height();

	for (int cnt=0; cnt < star_cnt; cnt++)
	{
		stars[cnt].xpos = (float) (random % gc_width);
		random+= 143222321;
		stars[cnt].ypos = (float) (random % gc_height);
		random+= 89079086;
		stars[cnt].speed = (((float) (random % 256)) ) + 10.0f;
		random*= 595443965;
		stars[cnt].color.r = (((float) (random % 256)) / 256.0f);
		random*= 196243625;
		stars[cnt].color.b = (((float) (random % 256)) / 256.0f);
		random*= 14365;
		stars[cnt].color.g = (((float) (random % 256)) / 256.0f);
		stars[cnt].color.a = 1.0f;

	}

}
Example #3
0
void App::render_bloom_combine(clan::Canvas &canvas, clan::Texture2D &tex_base, clan::Texture2D &tex_bloom, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, tex_base);
	gc.set_texture(1, tex_bloom);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("BaseTexture"), 0);
	program_object.set_uniform1f(("BaseIntensity"), base_intensity);
	program_object.set_uniform1f(("BaseSaturation"), base_saturation);

	program_object.set_uniform1i(("BloomTexture"), 1);
	program_object.set_uniform1f(("BloomIntensity"), bloom_intensity);
	program_object.set_uniform1f(("BloomSaturation"), bloom_saturation);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
	gc.reset_texture(1);

}
Example #4
0
clan::Image App::get_stencil(clan::Canvas &canvas, clan::Rect rect)
{
	canvas.flush();

	// For an unknown reason, stencil reads should be a multiple of 32
	rect.left =  32 * ((rect.left + 31) / 32);
	rect.top =  32 * ((rect.top + 31) / 32);
	rect.right =  32 * ((rect.right + 31) / 32);
	rect.bottom =  32 * ((rect.bottom + 31) / 32);

	int rect_width = rect.get_width();
	int rect_height  = rect.get_height();

	std::vector<unsigned char> buffer;
	buffer.resize(rect_width * rect_height);


	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glPixelStorei(GL_PACK_ROW_LENGTH, rect_width);
	glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
	glPixelStorei(GL_PACK_SKIP_ROWS, 0);
	glReadBuffer(GL_BACK);
	if (glClampColor)
	{
#ifdef GL_CLAMP_READ_COLOR
		glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE);
#else
		glClampColor(clan::GL_CLAMP_READ_COLOR, GL_FALSE);
#endif
	}

	glReadPixels(rect.left, canvas.get_height()- rect.bottom, rect_width, rect_height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &buffer[0]);
	clan::PixelBuffer pbuf(rect_width, rect_height, clan::tf_rgba8);
	unsigned int *pdata = (unsigned int *) pbuf.get_data();
	unsigned char *rdata = &buffer[0];
	for (int ycnt=0; ycnt < rect_height; ycnt++)
	{
		for (int xcnt=0; xcnt < rect_width; xcnt++)
		{
			int value = *(rdata++);
			if (value == 0)
			{
				*(pdata++) = 0xFF005500;
			}
			else
			{
				value = value * 16;
				value = 0xFF000000 | value | (value << 8) | (value << 16);
				*(pdata++) = value;
			}
		}
	}
	pbuf.flip_vertical();
	return clan::Image(canvas, pbuf, pbuf.get_size());
}
Example #5
0
void ColorWheel::on_render(clan::Canvas &canvas, const clan::Rect &update_rect)
{
    get_options();

    clan::Pointf center( (float) canvas.get_width()/2.0f, (float) canvas.get_height()/2.0f);
    float radius = 200.0f;
    create_colorwheel(center, radius);

    canvas.fill_triangles(colorwheel_positions, colorwheel_colors, colorwheel_segments * 3);

    draw_labels(canvas);
}
Example #6
0
void why::Application::draw_main_menu(clan::Canvas &c)
{
	using namespace clan;
	m_main_menu->draw(c);

	const std::string ver (std::string(INERTIA_VERSION) + "v");
	Font f = m_rc_manager->get_font();

	Pointf vpos;
	vpos.x = c.get_width() - (ver.length() * f.get_font_metrics().get_average_character_width() + 10.0f);
	vpos.y = c.get_height() - 10.0f;

	f.draw_text(c, vpos, ver);
}
Example #7
0
bool App::update()
{
	game_time.update();

	canvas.clear(clan::Colorf(0.0f,0.0f,0.0f, 0.0f));
	rock.set_color(clan::Colorf(1.0f, 1.0f, 1.0f, 0.8f));
	rock.draw(canvas, 0.0f, 0.0f);

	// Rotate tux
	rotation += game_time.get_time_elapsed() * 100.0f;
	clan::Angle angle;
	angle.set_degrees(rotation);
	tux.set_angle(angle);

	// Caculate tux position
	clan::Pointf circle_center(  (float) (canvas.get_width()/2), (float) (canvas.get_height()/2) );
	const float radius = 210.0f;
	int tux_circle = 12;
	tux_position.x = -(radius - tux_radius - tux_circle)  * cos( angle.to_radians() / 2.0f );
	tux_position.y = (radius - tux_radius - tux_circle) * sin( angle.to_radians()/ 2.0f );
	tux_position += circle_center;
	tux_position.x -= tux.get_width()/2;
	tux_position.y -= tux.get_height()/2;

	// Give tux circle blue outer outline, because it looks nice
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Make see through border
	canvas.set_blend_state(blend_state_off);
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle-2, clan::Colorf(0.0f, 0.0f, 0.0f, 0.0f));
	canvas.reset_blend_state();

	// Give tux circle blue outline, to mask the alpha channel
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+2, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Draw tux
	tux.draw(canvas, tux_position.x, tux_position.y);

	// Draw text
	font_large.draw_text(canvas, 10-2, 50-2, "ClanLib Layered Window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_large.draw_text(canvas, 10, 50, "ClanLib Layered Window", clan::Colorf::green);
	font_small.draw_text(canvas, 60-2, 80-2, "Click mouse on the penguin to exit", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 60, 80, "Click mouse on the penguin to exit", clan::Colorf::green);
	font_small.draw_text(canvas, 110-2, 110-2, "Drag rock to move window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 110, 110, "Drag rock to move window", clan::Colorf::green);

	window.flip(1);

	return !quit;
}
Example #8
0
void SineScroll::draw_demo(clan::Canvas &canvas, int delta_ms)
{
	clan::Rectf rect(0.0f, 0.0f, clan::Sizef(300.0f, 300.0f));
	clan::Rectf texture_unit1_coords(0.0f, 0.0f, 1.0f, 1.0f);

	std::vector<clan::Vec2f> dest_position;
	std::vector<clan::Vec2f> texture_position;

	int dest_width = canvas.get_width();
	if (dest_width <=0)
		return;

	int dest_xoffset = 0;

	int gc_height = canvas.get_height();

	int dest_height = 128;
	int dest_start_y = (gc_height - dest_height)  / 2;

	float texture_y_start = 0.15f;	// Set to 0.0f for start and 1.0f for end to use the entire texture
	float texture_y_end = 0.5f;

	dest_position.reserve(dest_width * 2);
	texture_position.reserve(dest_width * 2);

	float sin_amplitude = (  (float) gc_height / 4.0f);

	if (delta_ms > 1000)	// Limit to 1 second to frame
		delta_ms = 1000;

	sin_offset += ((float) delta_ms / 1000.0f);
	if (sin_offset > (2.0f * clan::PI))
		sin_offset -= clan::PI * 2.0f;

	for (int cnt=0; cnt < dest_width; cnt++)
	{
		float y_offset = sin_amplitude * sin( sin_offset + (float) cnt / 100.0f ) ;

		dest_position.push_back( clan::Vec2f( cnt, dest_start_y + y_offset ) );
		dest_position.push_back( clan::Vec2f( cnt, dest_start_y + dest_height + y_offset) );

		texture_position.push_back( clan::Vec2f( (float) cnt / dest_width, texture_y_start ) );
		texture_position.push_back( clan::Vec2f( (float) cnt / dest_width, texture_y_end ) );

	}

	canvas.draw_lines(&dest_position[0], &texture_position[0], dest_position.size(), texture);

}
Example #9
0
void App::render_gaussian_blur(clan::Canvas &canvas, float blur_amount, clan::Texture2D &source_texture, clan::ProgramObject &program_object, float dx, float dy)
{
    uniforms.sample[0].weight = compute_gaussian(0, blur_amount);
    uniforms.sample[0].offset_x = 0.0f;
    uniforms.sample[0].offset_y = 0.0f;

    float totalWeights = uniforms.sample[0].weight;

    for (int i = 0; i < sampleCount / 2; i++)
    {
        float weight = compute_gaussian(i + 1.0f, blur_amount);

        uniforms.sample[i * 2 + 1].weight = weight;
        uniforms.sample[i * 2 + 2].weight = weight;

        totalWeights += weight * 2;

        float sampleOffset = i * 2 + 1.5f;

        clan::Vec2f delta(dx * sampleOffset, dy * sampleOffset);

        uniforms.sample[i * 2 + 1].offset_x = delta.x;
        uniforms.sample[i * 2 + 1].offset_y = delta.y;
        uniforms.sample[i * 2 + 2].offset_x = -delta.x;
        uniforms.sample[i * 2 + 2].offset_y = -delta.y;
    }

    for (int i = 0; i < sampleCount; i++)
    {
        uniforms.sample[i].weight /= totalWeights;
    }

    canvas.flush();
    clan::GraphicContext gc = canvas.get_gc();

    gc.set_texture(0, source_texture);
    gc.set_program_object(program_object);

    uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_transform();
    gpu_uniforms.upload_data(gc, &uniforms, 1);
    gc.set_uniform_buffer(0, gpu_uniforms);

    draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

    gc.reset_program_object();
    gc.reset_texture(0);

}
Example #10
0
void App::render_shockwave(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);
	gc.set_program_object(program_object);

	uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_modelview();
	gpu_uniforms.upload_data(gc, &uniforms, 1);
	gc.set_uniform_buffer(0, gpu_uniforms);

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
}
Example #11
0
void App::render_extract_highlights(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("SourceTexture"), 0);
	program_object.set_uniform1f(("Threshold"), highlight_threshold);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);

}
Example #12
0
void why::Application::draw_background(clan::Canvas &c, bool tile)
{
	using namespace clan;

	Sprite *bg = nullptr;
	if (GameState::is_active(GameStateValue::Menu))
	{
		bg = &m_menu_bg_sprite;
	}
	else
	{
		bg = &m_game_bg_sprite;
	}

	const float screen_width(static_cast<float>(c.get_width()));
	const float screen_height(static_cast<float>(c.get_height()));

	const float sprite_width(static_cast<float>(bg->get_width()));
	const float sprite_height(static_cast<float>(bg->get_height()));

	if (tile)
	{
		float x = 0, y = 0;

		while (y < screen_height + sprite_height)
		{
			bg->draw(c, x, y);
			x += sprite_width;
			if (x > screen_width + sprite_width)
			{
				y += sprite_height;
				x = 0.0f;
			}
		}
	}
	else
	{
		bg->draw(c, Rectf(0.0f, 0.0f, sprite_width, sprite_height),
			Rectf(0.0f, 0.0f, screen_width, screen_height));
	}
}
Example #13
0
void TextExplosion2D::render(clan::Canvas &canvas)
{
	if (!letter_positions.empty())
	{
		bool still_visible = false;
		timer.update();
		float time_elapsed = timer.get_time_elapsed();
		for (size_t i = 0; i < letter_positions.size(); i++)
		{
			font.draw_text(canvas, (int)letter_positions[i].x, (int)letter_positions[i].y, text.substr(i, 1), color);

			letter_positions[i] += letter_deltas[i] * time_elapsed * 5.0f;
			letter_deltas[i].y += time_elapsed * 20.0f;
			if (letter_deltas[i].y < canvas.get_height())
				still_visible = true;
		}
		if (!still_visible)
		{
			letter_positions.clear();
			letter_deltas.clear();
		}
	}
}