Beispiel #1
0
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);
}
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();
	}
}
Beispiel #3
0
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);
}
Beispiel #4
0
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;
}
Beispiel #5
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
}
Beispiel #6
0
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;
}
Beispiel #7
0
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);

}
Beispiel #8
0
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();
}
Beispiel #9
0
	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);
		}
	}
Beispiel #10
0
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();
}
Beispiel #11
0
/**
 * 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();

	}

}
Beispiel #12
0
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
}
Beispiel #13
0
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;
}
Beispiel #14
0
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();
}
Beispiel #15
0
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();
}
Beispiel #16
0
//Fonction à appeller à chaque changement de résolution
void Game::resizeGLScene()
{
	CL_GraphicContext *gc = CL_Display::get_current_window()->get_gc();
	glViewport(0, 0, (GLsizei) gc->get_width(), (GLsizei) gc->get_height());
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, (GLfloat) gc->get_width() / (GLfloat) gc->get_height(), 0.1f, 500.f);
	glMatrixMode(GL_MODELVIEW);
}
Beispiel #17
0
void App::render(CL_GraphicContext &gc)
{
	gc.clear(CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));

	scene.gs->image_grid.draw(gc, 420.0f, 120.0f);	// Draw a grid in the backgound

	gc.set_map_mode(cl_user_projection);
	CL_Rect viewport_rect(0, 0, CL_Size(gc.get_width(), gc.get_height()));
	gc.set_viewport(viewport_rect);

	gc.set_projection(scene.gs->camera_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(true);
	gc.set_buffer_control(buffer_control);

	gc.clear_depth(1.0f);

	CL_Mat4f modelview_matrix = scene.gs->camera_modelview;
	scene.Draw(modelview_matrix, gc);
	gc.reset_program_object();
}
void CL_GUIComponent::render(CL_GraphicContext &gc, const CL_Rect &clip_rect, bool include_children)
{
	if (!impl->visible)
		return;

	if (!impl->css_layout.is_null())
	{
		impl->css_layout.layout(gc, get_size());
		impl->css_layout.render(gc, this);
	}

	if (impl->func_render.is_null() == false)
	{
		impl->func_render.invoke(gc, clip_rect);
	}
	else
	{
		CL_GUIThemePart part(this);
		CL_Rect geometry = get_size();
		part.render_box(gc, CL_RectPS(0, 0, geometry.get_width(), geometry.get_height()), clip_rect);
	}

	if (include_children)
	{
		if (impl->clip_children)
		{
			push_cliprect(gc, impl->clip_children_rect);
		}

		CL_GUIComponent *cur = impl->first_child;
		while (cur)
		{
			CL_Rect cur_geometry = cur->get_geometry();

			CL_Rect update_rect = component_to_window_coords(clip_rect);
			update_rect.overlap(component_to_window_coords(cur_geometry));
			if (update_rect.get_width() > 0 && update_rect.get_height() > 0)
			{
				CL_Rect child_dirty_rect = cur->window_to_component_coords(update_rect);

				gc.push_translate((float)cur_geometry.left, (float)cur_geometry.top);
				cur->render(gc, child_dirty_rect, true);
				gc.pop_modelview();
			}
			cur = cur->impl->next_sibling;
		}

		if (impl->clip_children)
		{
			pop_cliprect(gc);
		}
	}
}
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;
}
Beispiel #20
0
GSLobby::GSLobby(CL_GraphicContext& gc, CL_ResourceManager& resources)
: m_gsgame(new GSGame(gc, resources)){
	CL_FontDescription desc;
	desc.set_typeface_name("tahoma");
	desc.set_height(32);
	m_font.reset(new CL_Font_System(gc, desc));
	m_xpos = gc.get_width()/2-100;
	m_ypos = gc.get_height()/4;
	m_playbtn.initialize(gc, resources, "game_lobby/play_btn",
						 CL_Vec2<float>(m_xpos, m_ypos+100));
	m_backbtn.initialize(gc, resources, "game_lobby/back_btn",
						 CL_Vec2<float>(m_xpos, m_ypos+200));
}
Beispiel #21
0
	static int main(const std::vector<CL_String> &args)
	{
		try
		{
			CL_SetupCore setup_core; 
			CL_SetupDisplay setup_disp;
			CL_SetupGL setup_gl;

			CL_DisplayWindow window("Viewport Grid Test", 640, 480, false, true);
			CL_GraphicContext gc = window.get_gc();
			
			CL_BlendMode blend_mode1;
			blend_mode1.enable_blending(true);
			gc.set_blend_mode(blend_mode1);

			gc.set_map_mode(cl_map_2d_upper_left);

			while(!window.get_ic().get_keyboard().get_keycode(CL_KEY_ESCAPE))
			{
				gc.clear(CL_Colorf::white);
				CL_Rect viewport = window.get_viewport();
				for (int y = viewport.top; y < viewport.bottom; y+=2)
				{
					CL_Draw::line(gc, viewport.left, y, viewport.right, y, CL_Colorf::black);
				}
				for (int x = viewport.left; x < viewport.right; x+=2)
				{
					CL_Draw::line(gc, x, viewport.top, x, viewport.bottom, CL_Colorf::black);
				}

				window.flip(1);
				CL_KeepAlive::process();

				CL_System::sleep(10);
			}

			return 0;
		}
		catch(CL_Exception error)
		{
			CL_ConsoleWindow console("Console");
			CL_Console::write_line("Exception caught:");
			CL_Console::write_line(error.message);
			console.display_close_message();

			return -1;
		}

		return 0;
	}
Beispiel #22
0
CL_Texture ContainerRenderer::getTexture(CL_GraphicContext& gc) {
    if (renderQueue_->requireWorldRepaint() || texture_.is_null()) {
        checkTextureSize(gc);
        CL_FrameBuffer origBuffer = gc.get_write_frame_buffer();

        gc.set_frame_buffer(frameBuffer_);

        render(gc);

        gc.set_frame_buffer(origBuffer);
    }

    return texture_;
}
Beispiel #23
0
void CL_Draw::point(CL_GraphicContext &gc, float x1, float y1, const CL_Colorf &color)
{
	CL_Vec2f positions[1] =
	{
		CL_Vec2f(x1, y1)
	};

	CL_PrimitivesArray prim_array(gc);
	prim_array.set_attributes(0, positions);
	prim_array.set_attribute(1, color);
	gc.set_program_object(cl_program_color_only);
	gc.draw_primitives(cl_points, 1, prim_array);
	gc.reset_program_object();
}
Beispiel #24
0
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);

	gs->shader_color.SetMaterial(material_shininess, material_emission, material_ambient, material_specular);

	gs->shader_color.Use(gc);

	gc.draw_primitives(cl_triangles, vbo_size, prim_array);
}
Beispiel #25
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("ColorWheel Example");
	win_desc.set_size(CL_Size( 800, 600 ), 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
	new ColorWheel(gc, gui, CL_Rect(32, 32, CL_Size(512, 512)));


	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;

		gc.clear(CL_Colorf(0.0f,0.0f,0.0f));

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

		window.flip(1);

		CL_KeepAlive::process();
	}

	return 0;
}
Beispiel #26
0
void ObjectPolygon::Draw(CL_GraphicContext &gc, CL_Texture &texture_image)
{
	ObjectVertex *vptr = m_pVertex;
	CL_Vec3f positions[6];
	CL_Vec3f texture_positions[6];
	CL_Vec3f normals[6];

	// We convert quads into triangles. This is silly, and this entire example should be rewritten to just use triangles

	if (m_NumVertex!=4) throw CL_Exception("Ooops");

	positions[0] = m_pVertex[0].m_Point;
	texture_positions[0] = m_pVertex[0].m_TexturePoint;
	normals[0] = m_Normal;
	positions[1] = m_pVertex[1].m_Point;
	texture_positions[1] = m_pVertex[1].m_TexturePoint;
	normals[1] = m_Normal;
	positions[2] = m_pVertex[2].m_Point;
	texture_positions[2] = m_pVertex[2].m_TexturePoint;
	normals[2] = m_Normal;

	positions[3] = m_pVertex[2].m_Point;
	texture_positions[3] = m_pVertex[2].m_TexturePoint;
	normals[3] = m_Normal;
	positions[4] = m_pVertex[3].m_Point;
	texture_positions[4] = m_pVertex[3].m_TexturePoint;
	normals[4] = m_Normal;
	positions[5] = m_pVertex[0].m_Point;
	texture_positions[5] = m_pVertex[0].m_TexturePoint;
	normals[5] = m_Normal;


	CL_PrimitivesArray prim_array(gc);

	gc.set_texture(0, texture_image);

	prim_array.set_attributes(cl_attrib_position, positions);
	prim_array.set_attribute(cl_attrib_color, CL_Colorf(1.0f,1.0f,1.0f, 1.0f));
	prim_array.set_attributes(cl_attrib_texture_position, texture_positions);
	prim_array.set_attributes(cl_attrib_normal, normals);
	gc.set_primitives_array(prim_array);

	gc.draw_primitives_array(cl_triangles, 6);

	gc.reset_texture(0);

	gc.reset_primitives_array();
}
Beispiel #27
0
void CL_Draw::triangle(CL_GraphicContext &gc, const CL_Pointf &a, const CL_Pointf &b, const CL_Pointf &c, const CL_Colorf &color)
{
	CL_Vec2f positions[3] =
	{
		CL_Vec2f(a.x, a.y),
		CL_Vec2f(b.x, b.y),
		CL_Vec2f(c.x, c.y)
	};

	CL_PrimitivesArray prim_array(gc);
	prim_array.set_attributes(0, positions);
	prim_array.set_attribute(1, color);
	gc.set_program_object(cl_program_color_only);
	gc.draw_primitives(cl_triangles, 3, prim_array);
	gc.reset_program_object();
}
CL_ShaderObject::CL_ShaderObject(CL_GraphicContext &gc, CL_ShaderType type, const std::vector<CL_StringRef> &sources)
: impl(new CL_ShaderObject_Impl)
{
	CL_GraphicContextProvider *gc_provider = gc.get_provider();
	impl->provider = gc_provider->alloc_shader_object();
	impl->provider->create(type, sources);
}
void ShaderBumpMap::Use(CL_GraphicContext &gc)
{
	if (!material_updated)
	{
		material_updated = true;
		program_object.set_uniform1f("MaterialShininess", material_shininess);
		program_object.set_uniform4f("MaterialEmission", material_emission);
		program_object.set_uniform4f("MaterialSpecular", material_specular);
		program_object.set_uniform4f("MaterialAmbient", material_ambient);
	}

	if (!light_updated)
	{
		light_updated = true;
		program_object.set_uniform4f("LightVector", light_vector);
		CL_Vec4f light_halfvector(0.0f, 0.0f, 1.0f, 0.0f);
		light_halfvector += light_vector;
		light_halfvector.normalize3();
		program_object.set_uniform4f("LightHalfVector", light_halfvector);
		program_object.set_uniform4f("LightSpecular", light_specular);
		program_object.set_uniform4f("LightDiffuse", light_diffuse);
		program_object.set_uniform4f("LightAmbient", light_ambient);
	}

	gc.set_program_object(program_object);
}
Beispiel #30
0
void ExampleText::update_text(CL_GraphicContext &gc, CL_FrameBuffer &fb_text, CL_Font &font, std::vector<CL_SpanLayout> &layout)
{
	gc.set_frame_buffer(fb_text);

	CL_Draw::fill(gc, 0.0f, 0.0f, (float)text_window_size, (float)text_window_size, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));

	CL_String text(cl_format("Frames per second = %1", last_fps));
	font.draw_text(gc, 20, 20, text, CL_Colorf::white);

	for (unsigned int line_count = 0; line_count < layout.size(); line_count++)
	{
		layout[line_count].draw_layout(gc);
	}

	gc.reset_frame_buffer();
}