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


C++ CL_GraphicContext类代码示例

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


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

示例1: set_user_projection

void App::set_user_projection(CL_GraphicContext &gc, CL_Sizef &area_size, Options *options)
{
	gc.set_viewport(CL_Rectf(0, 0, area_size));

	float lens_zoom = 3.2f;
	float lens_near = 0.1f;
	float lens_far = 10000.0f;
	float lens_aspect = 1.0f;

	float fov = 2.0f * atan2(1.0f, lens_zoom);
	float aspect = 1.0f;

	aspect = ( area_size.width * lens_aspect) / area_size.height;

	fov = (fov * 180.0f) / CL_PI;
	CL_Mat4f projection_matrix = CL_Mat4f::perspective( fov, aspect, lens_near, lens_far);
	gc.set_projection(projection_matrix);

	CL_Mat4f modelview_matrix = CL_Mat4f::identity();

	modelview_matrix.scale_self(1.0f, 1.0f, -1.0f);	// So positive Z goes into the screen
	modelview_matrix.translate_self(-1.0f, 1.0, lens_zoom);
	modelview_matrix = modelview_matrix.multiply(CL_Mat4f::rotate(CL_Angle((float) -options->grid_angle, cl_degrees), 1.0f, 0.0f, 0.0f, false));
	modelview_matrix.scale_self(2.0f / area_size.width, -2.0f / area_size.height, 1.0f);
	modelview_matrix.translate_self(cl_pixelcenter_constant,cl_pixelcenter_constant, 0.0f);

	gc.set_modelview(modelview_matrix);
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:28,代码来源:app.cpp

示例2: draw

void CL_CollisionOutline::draw(
	float x,
	float y,
	const CL_Colorf &color,
	CL_GraphicContext &gc)
{
	// Draw collision outline (Contours are assumed as closed polygons, hence we use line-loop)
	for(unsigned int i = 0; i < impl->contours.size(); i++)
	{
		// Draw the contour
		unsigned int numpoints = impl->contours[i].get_points().size();
		for(unsigned int s = 0; s < numpoints; s++)
		{
			const CL_Pointf &p1 = impl->contours[i].get_points()[s];
			const CL_Pointf &p2 = impl->contours[i].get_points()[(s+1) % numpoints];
			CL_Draw::line(gc, x + p1.x + 0.5f, y + p1.y + 0.5f, x + p2.x + 0.5f, y + p2.y + 0.5f, color);
		}

		// Add points (as opposite color)
		CL_Colorf colorinv(1.0f-color.get_red(),1.0f-color.get_green(),1.0f-color.get_blue());

		CL_Pen pen;
		pen.set_point_size(2.0);
		gc.set_pen(pen);

		for(unsigned int s1 = 0; s1 < numpoints; s1++)
		{
			const CL_Pointf &p1 = impl->contours[i].get_points()[s1];
			CL_Draw::point(gc, x + p1.x + 0.5f, y + p1.y + 0.5f, colorinv);
		}

		gc.reset_pen();
	}
}
开发者ID:animehunter,项目名称:clanlib-2.3,代码行数:34,代码来源:collision_outline.cpp

示例3: prepareGC

void Viewport::prepareGC(CL_GraphicContext &p_gc) {
	p_gc.push_modelview();

	if (m_impl->m_attachPoint != NULL) {
		// calculate world clip rect
		const int stageWidth = Gfx::Stage::getWidth();
		const int stageHeight = Gfx::Stage::getHeight();

		m_impl->m_worldClipRect.left =
				m_impl->m_attachPoint->x - stageWidth / 2 / m_impl->m_scale;
		m_impl->m_worldClipRect.top =
				m_impl->m_attachPoint->y - stageHeight / 2 / m_impl->m_scale;
		m_impl->m_worldClipRect.right =
				m_impl->m_worldClipRect.left + stageWidth / m_impl->m_scale;
		m_impl->m_worldClipRect.bottom =
				m_impl->m_worldClipRect.top + stageHeight / m_impl->m_scale;
	}

	// apply new scale
	const float horizScale = p_gc.get_width() / m_impl->m_worldClipRect.get_width();
	const float vertScale = p_gc.get_height() / m_impl->m_worldClipRect.get_height();

	p_gc.mult_scale(horizScale, vertScale);

	// apply translations
	p_gc.mult_translate(-m_impl->m_worldClipRect.left, -m_impl->m_worldClipRect.top);
}
开发者ID:bercik,项目名称:gear,代码行数:27,代码来源:Viewport.cpp

示例4: set_cur_x

void TileMap::set_cur_x(CL_GraphicContext& gc, int x) {
    if (x < 0)
        x = 0;
    else if (get_width() - x < gc.get_width())
        x = get_width() - gc.get_width();
    cur_map_x = x;
}
开发者ID:zeroshade,项目名称:ClanRPG,代码行数:7,代码来源:TileMap.cpp

示例5: draw

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
}
开发者ID:genail,项目名称:gear,代码行数:33,代码来源:Label.cpp

示例6: set_cur_y

void TileMap::set_cur_y(CL_GraphicContext& gc, int y) {
    if (y < 0)
        y = 0;
    else if (get_height() - y < gc.get_height())
        y = get_height() - gc.get_height();
    cur_map_y = y;
}
开发者ID:zeroshade,项目名称:ClanRPG,代码行数:7,代码来源:TileMap.cpp

示例7: Draw

void Model_Impl::Draw(CL_GraphicContext &gc, GraphicStore *gs, const CL_Mat4f &modelview_matrix)
{
	gc.set_modelview(modelview_matrix);

	CL_PrimitivesArray prim_array(gc);

	prim_array.set_attributes(0, vbo_positions, 3, cl_type_float, (void *) 0);
	prim_array.set_attributes(1, vbo_normals, 3, cl_type_float, (void *) 0);

	if (!vbo_texcoords.is_null())
	{
		prim_array.set_attributes(2, vbo_texcoords, 2, cl_type_float, (void *) 0);
		gc.set_texture(0, gs->texture_underwater);
		gc.set_texture(1, gs->texture_background);
		gs->shader_texture.SetMaterial(material_shininess, material_emission, material_ambient, material_specular);
		gs->shader_texture.Use(gc);
	}
	else
	{
		throw CL_Exception("What! no texure coordinates?");
	}

	gc.draw_primitives(cl_triangles, vbo_size, prim_array);

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

}
开发者ID:Zenol,项目名称:clanlib-2.4,代码行数:28,代码来源:model.cpp

示例8: gradient_fill

void CL_Draw::gradient_fill(CL_GraphicContext &gc, float x1, float y1, float x2, float y2, const CL_Gradient &gradient)
{
	CL_Vec2f positions[6] =
	{
		CL_Vec2f(x1, y1),
		CL_Vec2f(x2, y1),
		CL_Vec2f(x1, y2),
		CL_Vec2f(x2, y1),
		CL_Vec2f(x1, y2),
		CL_Vec2f(x2, y2)
	};

	#define cl_color_to_color4d(c) c.get_red(), c.get_green(), c.get_blue(), c.get_alpha()

	CL_Vec4f colors[6] =
	{
		CL_Vec4f(cl_color_to_color4d(gradient.top_left)),
		CL_Vec4f(cl_color_to_color4d(gradient.top_right)),
		CL_Vec4f(cl_color_to_color4d(gradient.bottom_left)),
		CL_Vec4f(cl_color_to_color4d(gradient.top_right)),
		CL_Vec4f(cl_color_to_color4d(gradient.bottom_left)),
		CL_Vec4f(cl_color_to_color4d(gradient.bottom_right))
	};

	CL_PrimitivesArray prim_array(gc);
	prim_array.set_attributes(0, positions);
	prim_array.set_attributes(1, colors);
	gc.set_program_object(cl_program_color_only);
	gc.draw_primitives(cl_triangles, 6, prim_array);
	gc.reset_program_object();
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:31,代码来源:draw.cpp

示例9: drawPoint

	void EditorPoint::drawPoint(int p_index, bool &p_isSelected, bool &p_isLight, CL_GraphicContext &p_gc)
	{
		CL_Colorf color = (p_isSelected || p_isLight) ? m_impl->m_selectedPointColor : m_impl->m_pointColor;

		if (p_isSelected)
		{
			if (isFirstKey(CL_KEY_SHIFT) && m_impl->m_selectedIndex != -1)
			{
				CL_Pen pen;

				pen.set_line_width(PAINT_LINE_WIDTH);
				p_gc.set_pen(pen);

				int x1, y1, x2, y2;
				getShiftRect(p_index, &x1, &y1, &x2, &y2);

				CL_Draw::line(p_gc, x1, y1, x2, y2, m_impl->m_shiftLineColor);

				pen.set_line_width(1.0f);
				p_gc.set_pen(pen);

				CL_Draw::fill(p_gc, getPointRect(m_impl->m_minShiftPoint), m_impl->m_minAndMaxShiftRectColor);
				CL_Draw::fill(p_gc, getPointRect(m_impl->m_maxShiftPoint), m_impl->m_minAndMaxShiftRectColor);
			}
		}

		CL_Draw::fill(p_gc, getPointRect(p_index), color);

		if (p_isSelected)
		{
			CL_Draw::box(p_gc, getPointRect(p_index), m_impl->m_selectedPointFrameColor);
		}
	}
开发者ID:bercik,项目名称:gear,代码行数:33,代码来源:EditorPoint.cpp

示例10: texture

void CL_Draw::texture(
	CL_GraphicContext &gc,
	const CL_Rectf &rect,
	const CL_Colorf &color,
	const CL_Rectf &texture_unit1_coords)
{
	CL_Vec2f positions[6] =
	{
		CL_Vec2f(rect.left, rect.top),
		CL_Vec2f(rect.right, rect.top),
		CL_Vec2f(rect.left, rect.bottom),
		CL_Vec2f(rect.right, rect.top),
		CL_Vec2f(rect.left, rect.bottom),
		CL_Vec2f(rect.right, rect.bottom)
	};

	CL_Vec2f tex1_coords[6] =
	{
		CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.top),
		CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top),
		CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom),
		CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top),
		CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom),
		CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.bottom)
	};

	CL_PrimitivesArray prim_array(gc);
	prim_array.set_attributes(0, positions);
	prim_array.set_attribute(1, color);
	prim_array.set_attributes(2, tex1_coords);
	gc.set_program_object(cl_program_single_texture);
	gc.draw_primitives(cl_triangles, 6, prim_array);
	gc.reset_program_object();
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:34,代码来源:draw.cpp

示例11: draw

/**
 * Draws the polygon on the graphics context.
 *
 * @param gc Graphics context to draw the polygon on.
 */
void Polygon::draw(CL_GraphicContext gc)
{

	//Only draw if more than one point exists.
	if(_points.size() > 1)
	{

		//CL_Vec4f green_color(1.0f, 1.0f, 1.0f, 1.0f);
		CL_Vec2i points_array[_points.size()];

		std::list<CL_Pointf>::iterator it_point;
		int n = 0;
		for(it_point = _points.begin(); it_point != _points.end(); ++it_point)
		{
			points_array[n] = static_cast<CL_Vec2i>(*(it_point));
			n++;
		}

		CL_PrimitivesArray poly(gc);
		poly.set_attributes(0, points_array);
		poly.set_attribute(1, _line_color);

		//scene->get_world()->get_gc()->get_polygon_rasterizer().set_face_fill_mode_front(cl_fill_polygon);

		gc.set_program_object(cl_program_color_only);
		gc.draw_primitives(cl_line_loop,n,poly);
		gc.reset_program_object();

	}

}
开发者ID:aggronerd,项目名称:Mystery-Game,代码行数:36,代码来源:Polygon.cpp

示例12: draw

void Label::draw(CL_GraphicContext &p_gc)
{
	assert(isLoaded());

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

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

	const float x = m_pos.x - ax;
	const float y = m_pos.y - ay - m_fontMetrics.get_descent();

	m_clFont->draw_text(p_gc, x, 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
}
开发者ID:bercik,项目名称:gear,代码行数:28,代码来源:Label.cpp

示例13: begin

void ShaderImpl::begin(CL_GraphicContext &p_gc)
{
	G_ASSERT(m_initialized);
	G_ASSERT(!m_began);

	// new texture
	m_drawRect = m_parent->getDrawRect(m_boundRect);
	m_texture = CL_Texture(p_gc, m_drawRect.get_width(), m_drawRect.get_height());

	// attach frame buffer
	m_frameBuffer.attach_color_buffer(0, m_texture);
	p_gc.set_frame_buffer(m_frameBuffer);

	// clear to transparent
	p_gc.clear(CL_Colorf::transparent);

	// set proper matrix
	p_gc.push_modelview();

	// get scaling in count
	const CL_Mat4f &matrix = p_gc.get_modelview();
	const float scaleX = matrix[0];
	const float scaleY = matrix[5];

	p_gc.mult_translate(-m_drawRect.left / scaleX, -m_drawRect.top / scaleY);

	m_began = true;
}
开发者ID:genail,项目名称:gear,代码行数:28,代码来源:Shader.cpp

示例14: render_from_lightsource

void App::render_from_lightsource(CL_GraphicContext &gc, CL_FrameBuffer &framebuffer)
{
	CL_PrimitivesArray prim_array(gc);

	gc.set_frame_buffer(framebuffer);

	gc.set_map_mode(cl_user_projection);

	CL_Rect viewport_rect2(0, 0, CL_Size(scene.gs->texture_shadow.get_width(), scene.gs->texture_shadow.get_height()));
	gc.set_viewport(viewport_rect2);

	CL_Mat4f perp = CL_Mat4f::perspective(67.0f, 1.0f, 0.1f, 1000.0f);
	gc.set_projection(scene.gs->light_projection);

	CL_BufferControl buffer_control;
	buffer_control.set_depth_compare_function(cl_comparefunc_lequal);

	buffer_control.enable_depth_write(true);
	buffer_control.enable_depth_test(true);
	buffer_control.enable_stencil_test(false);
	buffer_control.enable_color_write(false);
	gc.set_buffer_control(buffer_control);

	gc.clear_depth(1.0f);

	CL_Mat4f modelview_matrix = scene.gs->light_modelview;
	scene.Draw(modelview_matrix, gc, true);

	gc.reset_program_object();

	gc.set_modelview(CL_Mat4f::identity());
	gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left));

	gc.reset_frame_buffer();
}
开发者ID:animehunter,项目名称:clanlib-2.3,代码行数:35,代码来源:example.cpp

示例15: on_render

void Options::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect)
{
	CL_BlendMode blendmode;
	blendmode.enable_blending(false);
	gc.set_blend_mode(blendmode);
	CL_Draw::fill(gc, update_rect, CL_Colorf(0.4f, 0.4f, 0.6f, 0.0f));
	gc.reset_blend_mode();
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:8,代码来源:options.cpp


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