Exemplo n.º 1
0
void World::draw()
{
	// Draw background 
	CL_Rect window_rect = window.get_viewport();
	gc.set_texture(0, background);
	CL_Draw::texture(gc, window_rect);	
	gc.reset_texture(0);

	// Draw all gameobjects
	std::list<GameObject *>::iterator it;
	for(it = objects.begin(); it != objects.end(); ++it)
		(*it)->draw();

	// Draw drag area
	if(dragging)
	{
		float s = (sinf(CL_System::get_time() / 200.0f) + 3.0f) / 4.0f;

		
		CL_Draw::box(gc,
			CL_Rectf(dragArea.left - 1, dragArea.top - 1, dragArea.right + 1, dragArea.bottom + 1), 
			CL_Colorf(0.0f, 1.0f, 0.0f, (100.0f * s)/256.0f));
		CL_Draw::box(gc,
			CL_Rectf(dragArea.left, dragArea.top, dragArea.right, dragArea.bottom), 
			CL_Colorf(0.0f, 1.0f, 0.0f, (200.0f * s)/256.0f));
		CL_Draw::box(gc,
			CL_Rectf(dragArea.left + 1, dragArea.top + 1, dragArea.right - 1, dragArea.bottom - 1), 
			CL_Colorf(0.0f, 1.0f, 0.0f, (100.0f * s)/256.0f));
	}
}
Exemplo n.º 2
0
void Object::Draw(CL_GraphicContext_GL1 &gc, CL_Texture &texture_image)
{
	CL_Material_GL1 material;
	material.set_specular(CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
	material.set_diffuse(CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
	material.set_shininess(0.5);

	gc.set_material(material);
	gc.set_color_material(cl_color_material_ambient_and_diffuse);

	ObjectPolygon *pptr = m_pPolygon;
	for (int poly_cnt=0; poly_cnt<m_NumPolygon; poly_cnt++, pptr++)
	{
		pptr->Draw(gc, texture_image);
	}
}
Exemplo n.º 3
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();
}
Exemplo n.º 4
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();
}
Exemplo n.º 5
0
void Game::draw()
{
    _kernel->getGraphicContext().clear(CL_Colorf(0.46f, 0.69f, 1.0f));

	_kernel->getSceneMenager()->draw();

    _kernel->getDisplayWindow().flip(1);
}
Exemplo n.º 6
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));
}
Exemplo n.º 7
0
void AreaScene::render()
{
	// render underlying scene:
	m_topScene->render();

	// render fading shadow:
	auto renderer = m_manager->getRenderer();
	CL_Draw::fill(renderer->getGC(), CL_Rectf(renderer->getGCSize()), CL_Colorf(0.0f, 0.0f, 0.0f, m_percent));
}
Exemplo n.º 8
0
bool GUI::run()
{
	static int total_time = 0, fps_count = 0, last_fps= 0;
	static int start_time = 0;

	if (start_time == 0)
	{
		start_time = CL_System::get_time();
	}

	CL_GraphicContext gc = app->get_window()->get_gc();

	gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left));

	CL_Draw::gradient_fill(gc, app->get_window()->get_viewport(), CL_Gradient(CL_Colorf(0.4f, 0.4f, 0.4f, 1.0f), CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f)));

	run_manager(gc);

	CL_String fps = cl_format("FPS: %1", last_fps);
	fps_font.draw_text(gc, gc.get_width() - 100 - 2, 24 - 2, fps, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
	fps_font.draw_text(gc, gc.get_width() - 100, 24, fps, CL_Colorf::white);

	fps_font.draw_text(gc, 24, gc.get_height() - 16, "Rendering GUI onto a CL_Texture, then onto the display window.", CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

	fps_count++;
	int time = CL_System::get_time();
	total_time += time - start_time;
	start_time = time;
	if(total_time >= 1000)
	{
		last_fps = fps_count;
		total_time -= 1000;
		fps_count = 0;
	}

	balls.Run(gc);

	CL_KeepAlive::process();
	app->get_window()->flip(0);

	return true;
}
Exemplo n.º 9
0
void
CLVisualSprite::debugDraw(VisualContext &vc, float x, float y, int delta,
                          float left, float top, float right, float bottom) {
  // Draw base visual
  draw(vc, x, y, delta);

  // For debugging: show a red outline
  CL_GraphicContext &gc = ((CLVisualContext &)vc).getGraphicContext();
  float cx = x + getWidth(vc) / 2;
  float cy = y + getHeight(vc) / 2;
  CL_Draw::box(gc, cx - left, cy - top, cx + right, cy + bottom,
               CL_Colorf(1.0f, 0.0f, 0.0f, 0.3f));
}
Exemplo n.º 10
0
/** Builds the screen.
*/
void
CASignUpScreen::buildScreen() 
{
    // Counter for cursor animation:
    static float cursorAnim = 0.0;

    // Backgroud:
    //
    CA_RES->menu_bg.draw ( *CA_APP->graphicContext, CL_Rect(0, 0, CA_APP->width, CA_APP->height) );

    // Title / help:
    //
    displayTitle();
    displayHelp();

    // Cursor:
    //
    CL_Draw::fill( *CA_APP->graphicContext, CL_Rectf(racePreview[cursor]->getLeft()-12, racePreview[cursor]->getTop()-12,
                           racePreview[cursor]->getRight()+12, racePreview[cursor]->getBottom()+12),
                           CL_Colorf (255, 216, 84, (int)((cursorAnim/2)*255) ));

    CA_RES->advanceAnimation( &cursorAnim, 1, 2.0, CAResources::Revolving );

    // Race previews:
    //
    for( int race=0; race<3; ++race )
    {
        if( racePreview[race] )
        {
            racePreview[race]->display();
            CA_RES->font_normal_14_white.draw_text( *CA_APP->graphicContext, racePreview[race]->getHCenter(),
                                                racePreview[race]->getTop()-22,
                                                (race==0 ? "Easy" : (race==1 ? "Medium" : "Hard")) );
        }
        if (m_selected == true)
        {
            for (unsigned int pl=0; pl<m_RacePlayer[race].size(); pl++)
            {
                CA_RES->font_normal_14_white.draw_text ( *CA_APP->graphicContext,racePreview[race]->getHCenter(),
                                                    racePreview[race]->getBottom()+22*(pl+1), m_StringRacePlayer[race][pl] );
            }
        }
    }

  
    //
    // UpgradesPanel
    UpgradesPanel uPanel(CA_APP->player[0], CA_RES->font_normal_14_white, CA_RES->font_lcd_13_green, racePreview[2]->getRight() + 32, racePreview[0]->getTop()-22);
    uPanel.display();
    
}
Exemplo n.º 11
0
void Info::draw(CL_GraphicContext &gc)
{
	CL_String text_to_draw = name;

	CL_Rect draw_rect = get_geometry();

	int draw_xpos = 0;
	int draw_ypos = 0;

	//CL_Draw::fill(gc, CL_Rect(draw_xpos, draw_ypos, CL_Size(get_width(), get_height())), CL_Colorf(CL_Colorf::red));

	CL_Font font = gui->get_font();

	CL_FontMetrics metrics = font.get_font_metrics(gc);
	draw_ypos += (int) metrics.get_ascent();

	CL_Colorf color;

	int time_diff = CL_System::get_time() - activated_time;
	float color_value = 1.0f - ( ( (float) time_diff ) / 1000.0f);
	if ( (color_value <= 1.0f) && (color_value > 0.0f) )
	{
		color = CL_Colorf(color_value, color_value/2.0f, color_value/2.0f, color_value);
		font.draw_text(gc, draw_xpos, draw_ypos, "#", color);
		color = CL_Colorf(color_value, color_value/2.0f, color_value/2.0f, 1.0f);
		text_to_draw = name + comment;

		set_constant_repaint(true);
	}
	else
	{
		color = CL_Colorf(0, 0, 0, 1.0f);
		set_constant_repaint(false);
	}

	//font.draw_text(gc, draw_xpos + 16, draw_ypos, text_to_draw, CL_Colorf::white);
	font.draw_text(gc, draw_xpos + 16-1, draw_ypos-1, text_to_draw, color);
}
Exemplo n.º 12
0
void DialogScene::updateLayout()
{
	// update phrase type:
	m_newtype = m_iter->first;
	m_percent = 0.0f;

	// update text layout:
	m_layout.clear();
	m_layout.set_position(m_rcText.get_top_left());
	m_layout.set_align(cl_justify);

	m_layout.add_text(m_iter->second, m_font, CL_Colorf(0,0,0,100));
	m_layout.layout(m_manager->getRenderer()->getGC(), (int)m_rcText.get_width());
}
Exemplo n.º 13
0
void ExampleText::draw_text(CL_GraphicContext &gc, CL_Texture &texture, CL_Angle angle)
{
	gc.set_texture(0, texture);

	gc.push_modelview();

	gc.mult_translate(gc.get_width()/2.0f, gc.get_height()/2.0f);
	gc.mult_rotate(angle, 0.0f, 0.0f, 1.0f);

	CL_Draw::texture(gc, CL_Rectf(-300.0f, -300.0f, 300.0f, 300.0f), CL_Colorf(1.0f, 1.0f, 1.0f, 0.7f));

	gc.pop_modelview();

	gc.reset_texture(0);
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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();
}
Exemplo n.º 16
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();
}
Exemplo n.º 17
0
void WorkerGC::worker_thread_loop()
{
	CL_DisplayWindowDescription desc;
	desc.set_title("ClanLib Worker Thread");
	desc.set_size(CL_Size(320, 320), true);
	//desc.set_visible(false);
	window = CL_DisplayWindow(desc);

	while (true)
	{
		int wakeup_reason = CL_Event::wait(event_start, event_stop);

		if (wakeup_reason != 0)
			break;

		event_start.reset();
	
		try
		{

			CL_GraphicContext gc = window.get_gc();

			// Test code 
			unsigned int time_ms = CL_System::get_time();
			while((CL_System::get_time() - time_ms) < 2000)
			{
				gc.clear(CL_Colorf(1.0f,0.0f,0.2f));
				CL_KeepAlive::process();
				window.flip(0);
			}
			window.set_visible(false, false);
			retrieved_sprite = CL_Sprite(gc, sprite_name);
			CL_OpenGL::set_active(gc);
			glFlush();
		}
		catch (CL_Exception &error)
		{
			exception_set = true;
			exception = error;
		}

		event_completed.set();
	}
	window = CL_DisplayWindow();
}
Exemplo n.º 18
0
/** Displays the player view in the panel area.
    \param defaultPos default position if rank is 0 (race startup)
*/
void
CAPlayerView::display( const int defaultPos ) {
    // Maybe we need to re-render the button sprite:
    //
    if( currentColor!=player->getColor() ) {
        renderButton();
    }

    int lap = (int)( floor( player->getPosition() )+1.0 );
    int rank = (player->getRaceRank()==0 ? defaultPos : player->getRaceRank());
    int y = (rank-1) * 55 + 110 + 38; // The turbo jauge + the ammo jauge

    if( lap>5 ) lap=5;

    std::ostringstream ossLap, ossRank, ossNumLap;
    ossLap << lap;
    ossRank << rank;
    ossNumLap << CA_NUMLAPS;

    // Display color button:
    //
    button.draw ( *CA_APP->graphicContext,0, y);
    CA_RES->panel_life.draw ( *CA_APP->graphicContext, (int)((float)player->getLife() / 100.0 * 120.0), y );

    // Display name:
    //
    CA_RES->font_normal_11_white.draw_text( *CA_APP->graphicContext, 3, y+2, player->getName() );

    // Display laps and rank:
    //
    CA_RES->panel_infoview.draw ( *CA_APP->graphicContext,0, y+20);
    CA_RES->font_lcd_13_green.draw_text( *CA_APP->graphicContext, 50, y+22, ossLap.str() );
    CA_RES->font_lcd_13_green.draw_text( *CA_APP->graphicContext, 70, y+31, ossNumLap.str() );
    CA_RES->font_normal_11_white.draw_text( *CA_APP->graphicContext, 99, y+30, ossRank.str() );

    // Display cross for death players:
    //
    if( player->getLife()<0.1 ) {
        CL_Draw::fill( *CA_APP->graphicContext, CL_Rectf(0, y, 120, y+55), CL_Colorf(0, 0, 0, 85) );
        CA_RES->panel_death.draw ( *CA_APP->graphicContext,0, y);
    }
}
Exemplo n.º 19
0
CL_ColorHSVf::operator CL_Colorf()
{
	float hue = cl_min(359.0f,cl_max(0.0f,h));
	float saturation = cl_min(1.0f,cl_max(0.0f,s));	
	float value = cl_min(1.0f,cl_max(0.0f,v));
	if (saturation == 0.0f)
	{
		return CL_Colorf(value, value, value, a);
	}

	int section = (int)(hue / 60);
	float f = (hue / 60.0f) - ((float) section);
	float p = value * (1.0f - saturation);
	float q = value * (1.0f - saturation * f);
	float t = value * (1.0f - saturation * (1.0f - f));
	if (section == 1)
	{
		return CL_Colorf(q, value, p, a);
	}
	if (section == 2)
	{
		return CL_Colorf(p, value, t, a);
	}
	if (section == 3)
	{
		return CL_Colorf(p, q, value, a);
	}
	if (section == 4)
	{
		return CL_Colorf(t, p, value, a);
	}
	if (section == 5)
	{
		return CL_Colorf(value, p, q, a);
	}
	return CL_Colorf(value, t, p, a);
}
Exemplo n.º 20
0
void Options::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect)
{
	CL_Rect rect = get_geometry();
	CL_Draw::fill(gc, update_rect, CL_Colorf(0.6f, 0.6f, 0.2f, 1.0f));
}
Exemplo n.º 21
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	// Set the window
	CL_DisplayWindowDescription desc;
	desc.set_title("ClanLib Worker GC Example");
	desc.set_size(CL_Size(640, 480), true);
	desc.set_allow_resize(true);

	CL_DisplayWindow window(desc);
	CL_OpenGL::set_active(NULL);	//  wglCreateContextAttribsARB will fail if the shared context is current in a different thread.
	WorkerGC worker_gc;
	CL_System::sleep(200);	// Fixme

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	worker_gc.Start("../../../Examples/Game/DiceWar/Resources/lobby_background1.png");

	CL_Sprite spr_logo;

	float sin_count = 0.0f;
	float ypos = 0.0f;
	float ydir = 0.3f;

	unsigned int last_time = CL_System::get_time();

	// Run until someone presses escape
	while (!quit)
	{
		unsigned int current_time = CL_System::get_time();
		float time_delta_ms = static_cast<float> (current_time - last_time);
		last_time = current_time;

		if (!spr_logo.is_null())
		{
			gc.clear(CL_Colorf(0.0f,0.0f,0.2f));
			spr_logo.draw(gc, 
				(float) gc.get_width()-spr_logo.get_width(),
				(float) gc.get_height()-spr_logo.get_height());
		}
		else
		{
			gc.clear(CL_Colorf(0.5f,0.0f,0.0f));
		}

		// Move the lines
		ypos += ydir * time_delta_ms;
		if (ydir > 0.0f)
		{
			if ((ypos+200.0f) >= gc.get_height())
			{
				ypos = (float) (gc.get_height() - 200);
				ydir *= -1.0f;
			}
		}
		else
		{
			if (ypos <= 0.0f)
			{
				ypos = 0.0f;
				ydir *= -1.0f;
			}
		}
			
		CL_Draw::fill(gc, 0, ypos-1.0f, (float) gc.get_width(), ypos-8.0f,CL_Colorf(1.0f, 1.0f, 1.0f));
		CL_Draw::fill(gc, 0, ypos+198.0f, (float) gc.get_width(), ypos+190.0f, CL_Colorf(1.0f, 1.0f, 1.0f));


		// Flip the display, showing on the screen what we have drawed
		// since last call to flip()
		window.flip(1);

		if (worker_gc.IsReady())
		{
				spr_logo = worker_gc.Get();
		}

		// This call processes user input and other events
		CL_KeepAlive::process(0);



	}

	return 0;
}
Exemplo n.º 22
0
int App::start(const std::vector<CL_String> &args)
{
	CL_OpenGLWindowDescription description;
	description.set_title("NightVision Shader");
	description.set_size(CL_Size(1024, 768), true);

	CL_DisplayWindow window(description);
	CL_InputDevice keyboard = window.get_ic().get_keyboard();
	CL_GraphicContext gc = window.get_gc();

	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	CL_Slot slot_window_close = window.sig_window_close().connect(this, &App::window_close);

	// Create offscreen texture
	CL_Texture texture_offscreen(gc, gc.get_width(), gc.get_height());
	texture_offscreen.set_min_filter(cl_filter_nearest);
	texture_offscreen.set_mag_filter(cl_filter_nearest);

	CL_Texture texture_mask(gc, gc.get_width(), gc.get_height());
	texture_mask.set_min_filter(cl_filter_nearest);
	texture_mask.set_mag_filter(cl_filter_nearest);

	// Create offscreen framebuffer
	CL_FrameBuffer framebuffer_offscreen(gc);
	framebuffer_offscreen.attach_color_buffer(0, texture_offscreen);

	CL_FrameBuffer framebuffer_mask(gc);
	framebuffer_mask.attach_color_buffer(0, texture_mask);

	CL_Image background(gc, "../PostProcessing/Resources/background.png");
	CL_Image ball(gc, "../PostProcessing/Resources/ball.png");
	ball.set_alignment(origin_center);
	CL_Texture noise_texture(gc, "Resources/noise_texture_0001.png");
	noise_texture.set_wrap_mode(cl_wrap_repeat, cl_wrap_repeat);

	// Load and link shaders
	CL_ProgramObject shader = CL_ProgramObject::load(gc, "Resources/vertex_shader.glsl", "Resources/fragment_shader.glsl");
	shader.bind_attribute_location(0, "Position");
	shader.bind_attribute_location(2, "TexCoord0");
	if (!shader.link())
		throw CL_Exception("Unable to link shader program: Error:" + shader.get_info_log());

	quit = false;

	float amount = 0.0f;
	float timer = 0.0f;

	float scale = 1.0f;

	CL_Font font(gc, "tahoma", 32);

	// Shader based on: http://www.geeks3d.com/20091009/shader-library-night-vision-post-processing-filter-glsl/

	elapsedTime = 0.0f; // seconds
	luminanceThreshold = 0.2f;
	colorAmplification = 4.0f;
	effectCoverage = 0.65f;

	// Render the mask
	gc.set_frame_buffer(framebuffer_mask);
	gc.clear();
	for (float offset=0.0f; offset<=1.0f; offset+=0.01f)
	{
		CL_Draw::circle(gc, gc.get_width() / 2.0f,  gc.get_height() / 2.0f, 400.0f - offset * 64.0f, CL_Colorf(offset, offset, offset, 1.0f));
	}
	gc.reset_frame_buffer();

	unsigned int startTime = CL_System::get_time();

	while (!quit)
	{
		timer = (CL_System::get_time() - startTime) / 1000.0f;

		elapsedTime = timer;

		// Render standard image to offscreen buffer
		gc.set_frame_buffer(framebuffer_offscreen);
		background.draw(gc, 0, 0);
		ball.draw(gc, gc.get_width() / 2 + 200 * sinf(timer / 2.0f), gc.get_height() / 2 + 200 * cosf(timer / 2.0f));
		gc.reset_frame_buffer();

		render_night_vision(gc, texture_offscreen, texture_mask, noise_texture, shader);

		const int gap = 32;
		font.draw_text(gc, 10, 64+gap*0, CL_String("luminanceThreshold : " + CL_StringHelp::float_to_text(luminanceThreshold) + " (Press Q,W)" ));
		font.draw_text(gc, 10, 64+gap*1, CL_String("colorAmplification : " + CL_StringHelp::float_to_text(colorAmplification) + " (Press A,S)" ));
		font.draw_text(gc, 10, 64+gap*2, CL_String("effectCoverage : " + CL_StringHelp::float_to_text(effectCoverage) + " (Press Z,X)" ));

		window.flip();

		CL_System::sleep(10);

		CL_KeepAlive::process();
	}

	return 0;
}
Exemplo n.º 23
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	try
	{

		CL_OpenGLWindowDescription desc;

		desc.set_title("ClanLib AnimCursor Test");
		desc.set_size(CL_Size(800, 600), true);
		CL_DisplayWindow window(desc);

		// Connect the Window close event
		CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

		// Connect a keyboard handler to on_key_up()
		CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

		// Get the graphic context
		CL_GraphicContext gc = window.get_gc();

		CL_Font font = CL_Font(gc, "Tahoma", 20);

		CL_PixelBuffer pacman("pacman.png");

		CL_SpriteDescription description;
		CL_Size size(22, 22);

		for (int frame_cnt=0; frame_cnt < 6; frame_cnt++)
		{
			CL_PixelBuffer frame(size.width, size.height, cl_rgba8);
			pacman.convert(frame, size, CL_Rect((frame_cnt * 28) + 4, 4, size));
			description.add_frame(frame);
			description.set_frame_delay(frame_cnt, 0.1);
		}

		CL_Point hotspot(0,0);
		CL_Cursor cursor(window, description, hotspot);
		window.set_cursor(cursor);

		// Run until someone presses escape
		while (!quit)
		{
			gc.clear(CL_Colorf(0.0f,0.0f,0.5f));

			font.draw_text(gc, 32, 32, "Observe the animated cursor");

			// Flip the display, showing on the screen what we have drawed
			// since last call to flip()
			window.flip(1);

			// This call processes user input and other events
			CL_KeepAlive::process();
		}
	}
	catch(CL_Exception& exception)
	{
		// Create a console window for text-output if not available
		CL_ConsoleWindow console("Console", 80, 200);

		CL_Console::write_line("Exception caught:");
		CL_Console::write_line(exception.message);

		// Display the stack trace (if available)
		std::vector<CL_String> stacktrace = exception.get_stack_trace();
		int size = stacktrace.size();
		if (size > 0)
		{
			CL_Console::write_line("Stack Trace:");
			for (int cnt=0; cnt < size; cnt++)
			{
				CL_Console::write_line(stacktrace[cnt]);
			}
		}

		console.display_close_message();

		return -1;
	}
	return 0;
}
Exemplo n.º 24
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	running_test = 0;

	// Create a console window for text-output if not available
	CL_ConsoleWindow console("Console", 80, 200);
	
	CL_Console::write_line("Press 1-5 for different tests! (Test 3 and 5 not applicable for ClanLib 0.8)");			

	try
	{
		// This opens a window, including the frame size
		// If you want more control over the window, pass CL_DisplayWindowDescription to CL_DisplayWindow
		// (This is useful to create a borderless window of a specific size)
		// If you require target specific control over the window, use the derived CL_OpenGLWindowDescription
		// (This contains the multisampling options)
		CL_DisplayWindow window("ClanLib SpriteSpeed Test", 1000, 1000);

		// Connect the Window close event
		CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

		// Connect a keyboard handler to on_key_up()
		CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

		// Get the graphic context
		CL_GraphicContext gc = window.get_gc();

		CL_ResourceManager resources("resources.xml");

		explosion1 = CL_Sprite(gc, "Explosion1", &resources);
		explosion2 = CL_Sprite(gc, "Explosion2", &resources);

		explosions_same_tex.reserve(10000);
		for(int i=0; i<10000; i++)
		{
			explosions_same_tex.push_back(CL_Sprite(explosion1));

			if(i % 2 == 0)
				explosions_diff_tex.push_back(CL_Sprite(explosion1));
			else
				explosions_diff_tex.push_back(CL_Sprite(explosion2));
		}

		// Run until someone presses escape
		while (!quit)
		{
			float delta_time = dump_fps() / 1000.0f;

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

			if(running_test == 0)
				CL_System::sleep(100);
			if(running_test == 1)
				draw_equal_tex_equal_sprites(gc, 10000, delta_time);
			if(running_test == 2)
				draw_equal_tex_diff_sprites(gc, 10000, delta_time);
			if(running_test == 3)
				draw_equal_tex_diff_sprites_batch(gc, 10000, delta_time);
			if(running_test == 4)
				draw_diff_tex_diff_sprites(gc, 10000, delta_time);
			if(running_test == 5)
				draw_diff_tex_diff_sprites_batch(gc, 10000, delta_time);

			// Flip the display, showing on the screen what we have drawed since last call to flip()
			window.flip();

			// This call processes user input and other events
			CL_KeepAlive::process();
		}

		explosions_same_tex.clear();
		explosions_diff_tex.clear();
		explosion1 = CL_Sprite();
		explosion2 = CL_Sprite();
	}
	catch(CL_Exception& exception)
	{
		CL_Console::write_line("Exception caught:");
		CL_Console::write_line(exception.message);

		// Display the stack trace (if available)
		std::vector<CL_String> stacktrace = exception.get_stack_trace();
		int size = stacktrace.size();
		if (size > 0)
		{
			CL_Console::write_line("Stack Trace:");
			for (int cnt=0; cnt < size; cnt++)
			{
				CL_Console::write_line(stacktrace[cnt]);
			}
		}

		console.display_close_message();

		return -1;
	}
	return 0;
}
Exemplo n.º 25
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	CL_OpenGLWindowDescription desc;
	desc.set_title("ClanLib Geometry Shader Example");
	desc.set_size(CL_Size(900, 700), true);
	desc.set_multisampling(0);
	desc.set_allow_resize(false);
	desc.set_depth_size(16);
	desc.set_version(3, 2, false);

	CL_DisplayWindow window(desc);

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	// Setup graphic store
	GraphicStore graphic_store(gc);
	scene.gs = &graphic_store;

	// Prepare the display
	gc.set_map_mode(cl_user_projection);

	CL_PolygonRasterizer polygon_rasterizer;
	polygon_rasterizer.set_culled(false);
	polygon_rasterizer.set_face_cull_mode(cl_cull_back);
	polygon_rasterizer.set_front_face(cl_face_side_clockwise);
	gc.set_polygon_rasterizer(polygon_rasterizer);

	create_scene(gc);

	camera_angle = 0.0f;

	CL_Font font(gc, "tahoma", 24);

	FramerateCounter framerate_counter;

	unsigned int time_last = CL_System::get_time();
	// Run until someone presses escape
	while (!quit)
	{
		framerate_counter.frame_shown();

		unsigned int time_now = CL_System::get_time();
		time_delta = time_now - time_last;
		time_last = time_now;

		control_camera();
		calculate_matricies(gc);

		gc.set_polygon_rasterizer(polygon_rasterizer);

		gc.clear_depth(1.0f);
		// ** If enabling below, change the graphic from alpha_ball2.png to alpha_ball.png in graphic_store.cpp
		//render_depth_buffer(gc);	// Render to depth buffer first, to fake sorting the particles
		render(gc);	// Render scene

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

		CL_String fps(cl_format("fps = %1", framerate_counter.get_framerate()));
		font.draw_text(gc, 16-2, gc.get_height()-16-2, fps, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
		font.draw_text(gc, 16, gc.get_height()-16-2, fps, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

		CL_String info(cl_format("Drawing %1 particles", ParticleObject::num_points));
		font.draw_text(gc, 16, 30, info);

		// Use flip(1) to lock the fps
		window.flip(0);

		// This call processes user input and other events
		CL_KeepAlive::process();
	}

	return 0;
}
Exemplo n.º 26
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	// Set the window
	CL_DisplayWindowDescription desc;
	desc.set_title("ClanLib App Example");
	desc.set_size(CL_Size(1200, 500), true);
	desc.set_allow_resize(true);

	CL_DisplayWindow window(desc);

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	// Load a sprite from a png-file
	tux = CL_PixelBuffer("Resources/tux.png");

	tux_original = CL_Image(gc, tux, tux.get_size());
	current_format = cl_rgba8;

	//current_format = cl_rgba8;
	//current_format = cl_rgb8;
	//current_format = cl_bgra8;
	//current_format = cl_bgr8;
	//current_format = cl_r8;
	//current_format = cl_r8_snorm;
	//current_format = cl_r16;
	//current_format = cl_r16_snorm;
	//current_format = cl_rg8;
	//current_format = cl_rg8_snorm;
	//current_format = cl_rg16;
	//current_format = cl_rg16_snorm;
	//current_format = cl_r3_g3_b2;
	//current_format = cl_rgb4;
	//current_format = cl_rgb5;
	//current_format = cl_rgb8_snorm;
	//current_format = cl_rgb10;
	//current_format = cl_rgb12;		// XX
	//current_format = cl_rgb16;
	//current_format = cl_rgb16_snorm;
	//current_format = cl_rgba2;		// XX
	//current_format = cl_rgba4;
	//current_format = cl_rgb5_a1;
	//current_format = cl_rgba8_snorm;
	//current_format = cl_rgb10_a2;
	//current_format = cl_rgba12;		// X
	//current_format = cl_rgba16;
	//current_format = cl_rgba16_snorm;
	//current_format = cl_srgb8;
	//current_format = cl_srgb8_alpha8;
	//current_format = cl_r16f;
	//current_format = cl_rg16f;
	//current_format = cl_rgb16f;
	//current_format = cl_rgba16f;
	//current_format = cl_r32f;
	current_format = cl_rg32f;
	//current_format = cl_rgb32f;
	//current_format = cl_rgba32f;
	//current_format = cl_r11f_g11f_b10f;	// X
	//current_format = cl_rgb9_e5;	// X
	//current_format = cl_r8i;
	//current_format = cl_r8ui;
	//current_format = cl_r16i;
	//current_format = cl_r16ui;
	//current_format = cl_r32i;
	//current_format = cl_r32ui;
	//current_format = cl_rg8i;
	//current_format = cl_rg8ui;
	//current_format = cl_rg16i;
	//current_format = cl_rg16ui;
	//current_format = cl_rg32i;
	//current_format = cl_rg32ui;
	//current_format = cl_rgb8i;
	//current_format = cl_rgb8ui;
	//current_format = cl_rgb16i;
	//current_format = cl_rgb16ui;
	//current_format = cl_rgb32i;
	//current_format = cl_rgb32ui;
	//current_format = cl_rgba8i;
	//current_format = cl_rgba8ui;
	//current_format = cl_rgba16i;
	//current_format = cl_rgba16ui;
	//current_format = cl_rgba32i;
	//current_format = cl_rgba32ui;
	//current_format = cl_depth_component16;
	//current_format = cl_depth_component24;
	//current_format = cl_depth_component32;
	//current_format = cl_depth_component32f;
	//current_format = cl_depth24_stencil8;
	//current_format = cl_depth32f_stencil8;
	//current_format = cl_compressed_red;
	//current_format = cl_compressed_rg;
	//current_format = cl_compressed_rgb;
	//current_format = cl_compressed_rgba;
	//current_format = cl_compressed_srgb;
	//current_format = cl_compressed_srgb_alpha;
	//current_format = cl_compressed_red_rgtc1;
	//current_format = cl_compressed_signed_red_rgtc1;
	//current_format = cl_compressed_rg_rgtc2;
	//current_format = cl_compressed_signed_rg_rgtc2;
	//current_format = cl_compressed_rgb_s3tc_dxt1;
	//current_format = cl_compressed_rgba_s3tc_dxt1;
	//current_format = cl_compressed_rgba_s3tc_dxt3;
	//current_format = cl_compressed_rgba_s3tc_dxt5;
	//current_format = cl_compressed_srgb_s3tc_dxt1;
	//current_format = cl_compressed_srgb_alpha_s3tc_dxt1;
	//current_format = cl_compressed_srgb_alpha_s3tc_dxt3;
	//current_format = cl_compressed_srgb_alpha_s3tc_dxt5;


	display_gc = &gc;
	update_images();

	CL_Font font(gc, "tahoma", 24);

	// Run until someone presses escape
	while (!quit)
	{

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

		tux_original.draw(gc, 0, 0);
		tux_convert.draw(gc, 400, 0);
		tux_unconvert.draw(gc, 800, 0);

		font.draw_text(gc, 10, 400, "cl_rgba8");

		if (gl_supported)
		{
			font.draw_text(gc, 410, 400, "converted");
		}
		else
		{
			font.draw_text(gc, 410, 400, "NOT SUPPORTED BY clanGL");
		}

		font.draw_text(gc, 810, 400, "converted back to cl_rgba8");

		window.flip(1);

		// This call processes user input and other events
		CL_KeepAlive::process(0);
	}

	return 0;
}
Exemplo n.º 27
0
void ContainerRenderer::render(CL_GraphicContext& gc) {
    renderQueue_->preRender();

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

    boost::shared_ptr<CL_ProgramObject> shader = ui::Manager::getShaderManager()->getGumpShader();
    gc.set_program_object(*shader, cl_program_matrix_modelview_projection);

    CL_Texture huesTexture = data::Manager::getHuesLoader()->getHuesTexture();
    gc.set_texture(0, huesTexture);
    // set texture unit 1 active to avoid overriding the hue texture with newly loaded object textures
    gc.set_texture(1, huesTexture);

    shader->set_uniform1i("HueTexture", 0);
    shader->set_uniform1i("ObjectTexture", 1);

    RenderQueue::const_iterator igIter = renderQueue_->begin();
    RenderQueue::const_iterator igEnd = renderQueue_->end();

    CL_Vec2f vertexCoords[6];

    bool renderingComplete = true;

    // draw background container texture
    boost::shared_ptr<ui::Texture> bgTex = containerView_->getBackgroundTexture();
    if (bgTex && bgTex->isReadComplete()) {
        CL_Vec3f hueInfo(0, 0, 1);

        CL_Rectf rect(0, 0, CL_Sizef(bgTex->getWidth(), bgTex->getHeight()));

        vertexCoords[0] = CL_Vec2f(rect.left, rect.top);
        vertexCoords[1] = CL_Vec2f(rect.right, rect.top);
        vertexCoords[2] = CL_Vec2f(rect.left, rect.bottom);
        vertexCoords[3] = CL_Vec2f(rect.right, rect.top);
        vertexCoords[4] = CL_Vec2f(rect.left, rect.bottom);
        vertexCoords[5] = CL_Vec2f(rect.right, rect.bottom);

        CL_Rectf texCoordHelper = bgTex->getNormalizedTextureCoords();

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

        CL_PrimitivesArray primarray(gc);
        primarray.set_attributes(0, vertexCoords);
        primarray.set_attributes(1, texCoords);

        primarray.set_attribute(2, hueInfo);

        gc.set_texture(1, bgTex->getTexture());
        gc.draw_primitives(cl_triangles, 6, primarray);
    } else {
        renderingComplete = false;
    }

    for (; igIter != igEnd; ++igIter) {
        boost::shared_ptr<world::IngameObject> curObj = *igIter;

        // just items in a container
        if (!curObj->isDynamicItem()) {
            continue;
        }

        // check if texture is ready to be drawn
        boost::shared_ptr<ui::Texture> tex = curObj->getIngameTexture();

        if (!tex) {
            continue;
        }

        if (!tex->isReadComplete()) {
            renderingComplete = false;
            continue;
        }

        CL_Rectf rect(curObj->getLocXDraw(), curObj->getLocYDraw(), CL_Sizef(tex->getWidth(), tex->getHeight()));

        vertexCoords[0] = CL_Vec2f(rect.left, rect.top);
        vertexCoords[1] = CL_Vec2f(rect.right, rect.top);
        vertexCoords[2] = CL_Vec2f(rect.left, rect.bottom);
        vertexCoords[3] = CL_Vec2f(rect.right, rect.top);
        vertexCoords[4] = CL_Vec2f(rect.left, rect.bottom);
        vertexCoords[5] = CL_Vec2f(rect.right, rect.bottom);

        CL_Rectf texCoordHelper = tex->getNormalizedTextureCoords();

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

        CL_PrimitivesArray primarray(gc);
        primarray.set_attributes(0, vertexCoords);
        primarray.set_attributes(1, texCoords);

        primarray.set_attribute(2, curObj->getHueInfo(false));

        gc.set_texture(1, tex->getTexture());
        gc.draw_primitives(cl_triangles, 6, primarray);
    }

    gc.reset_textures();
    gc.reset_program_object();

    renderQueue_->postRender(renderingComplete);

    if (!renderingComplete) {
        ui::Manager::getSingleton()->queueComponentRepaint(containerView_);
    }
}
Exemplo n.º 28
0
Options::Options(CL_GUIManager &gui, CL_Rect gui_position) : CL_GUIComponent(&gui, CL_GUITopLevelDescription("Options", gui_position, false))
{
	// Note, when changing these, remember to change the popup menu defaults
	selected_light = light_spot;
	max_color_value = 4.0f;
	max_angle_value = 360.0f;
	max_exponent_value = 5.0f;
	max_position_value = 100.0f;

	spot_light_position.x = max_position_value / 2.0f;
	spot_light_position.y = max_position_value / 2.0f;
	spot_light_position.z = max_position_value / 2.0f;
	spot_light_cutoff = 30.0f;
	spot_light_exponent = 0.5f;

	distant_specular_color = CL_Colorf(0.5f, 0.5f, 0.5f, 1.0f);
	distant_diffuse_color = CL_Colorf(0.5f, 0.5f, 0.5f, 1.0f);

	spot_specular_color = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f);
	spot_diffuse_color = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f);

	distant_direction_heading = CL_Angle(45.0f, cl_degrees);
	distant_direction_pitch = CL_Angle(35.0f, cl_degrees);
	distant_direction_bank = CL_Angle(0.0f, cl_degrees);

	spot_direction_heading = CL_Angle(129.6f, cl_degrees);
	spot_direction_pitch = CL_Angle(123.8f, cl_degrees);
	spot_direction_bank = CL_Angle(0.0f, cl_degrees);

	make_light_menu(combo_light_menu);
	combo_light = create_light_combo_box(8, 16, combo_light_menu, 1);
	label_light = create_combobox_label(combo_light, "Selected Light");

	int slider_xpos = 8;
	int slider_ypos = 48;
	int slider_gap = 24;
	slider_ypos += 8;
	slider_diffuse_red = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_diffuse_red->func_value_changed().set(this, &Options::slider_diffuse_red_changed);
	slider_diffuse_green = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_diffuse_green->func_value_changed().set(this, &Options::slider_diffuse_green_changed);
	slider_diffuse_blue = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_diffuse_blue->func_value_changed().set(this, &Options::slider_diffuse_blue_changed);
	label_diffuse_red = create_slider_label(slider_diffuse_red);
	label_diffuse_green = create_slider_label(slider_diffuse_green);
	label_diffuse_blue = create_slider_label(slider_diffuse_blue);
	slider_ypos += 8;
	slider_specular_red = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_specular_red->func_value_changed().set(this, &Options::slider_specular_red_changed);
	slider_specular_green = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_specular_green->func_value_changed().set(this, &Options::slider_specular_green_changed);
	slider_specular_blue = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_specular_blue->func_value_changed().set(this, &Options::slider_specular_blue_changed);
	label_specular_red = create_slider_label(slider_specular_red);
	label_specular_green = create_slider_label(slider_specular_green);
	label_specular_blue = create_slider_label(slider_specular_blue);
	slider_ypos += 8;
	slider_direction_heading = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_direction_heading->func_value_changed().set(this, &Options::slider_direction_heading_changed);
	slider_direction_pitch = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_direction_pitch->func_value_changed().set(this, &Options::slider_direction_pitch_changed);
	slider_direction_bank = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_direction_bank->func_value_changed().set(this, &Options::slider_direction_bank_changed);
	label_direction_heading = create_slider_label(slider_direction_heading);
	label_direction_pitch = create_slider_label(slider_direction_pitch);
	label_direction_bank = create_slider_label(slider_direction_bank);

	slider_ypos += 8;
	slider_light_xpos = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_light_xpos->func_value_changed().set(this, &Options::slider_light_xpos_changed);
	slider_light_ypos = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_light_ypos->func_value_changed().set(this, &Options::slider_light_ypos_changed);
	slider_light_zpos = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_light_zpos->func_value_changed().set(this, &Options::slider_light_zpos_changed);
	slider_cutoff = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_cutoff->func_value_changed().set(this, &Options::slider_cutoff_changed);
	slider_exponent = create_slider(slider_xpos, slider_ypos); slider_ypos += slider_gap;
	slider_exponent->func_value_changed().set(this, &Options::slider_exponent_changed);
	label_light_xpos = create_slider_label(slider_light_xpos);
	label_light_ypos = create_slider_label(slider_light_ypos);
	label_light_zpos = create_slider_label(slider_light_zpos);
	label_cutoff = create_slider_label(slider_cutoff);
	label_exponent = create_slider_label(slider_exponent);

	set_all_sliders();

	func_render().set(this, &Options::on_render);
}
Exemplo n.º 29
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	CL_OpenGLWindowDescription desc;
	desc.set_title("ClanLib Light Surface Example");
	desc.set_size(CL_Size(900, 700), true);
	desc.set_multisampling(4);
	desc.set_allow_resize(true);
	desc.set_depth_size(16);

	CL_DisplayWindow window(desc);

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Set up GUI
	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);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	// Deleted automatically by the GUI
	Options *options = new Options(gui, CL_Rect(8, 8, CL_Size(340, 600)));
	options->request_repaint();

	// Setup graphic store
	GraphicStore graphic_store(gc);
	scene.gs = &graphic_store;

	// Prepare the display
	gc.set_map_mode(cl_user_projection);

	CL_PolygonRasterizer polygon_rasterizer;
	polygon_rasterizer.set_culled(true);
	polygon_rasterizer.set_face_cull_mode(cl_cull_back);
	polygon_rasterizer.set_front_face(cl_face_side_clockwise);
	gc.set_polygon_rasterizer(polygon_rasterizer);

	create_scene(gc);

	CL_Font font(gc, "tahoma", 24);

	graphic_store.image_grid = CL_Image(gc, "../../Display_Render/Blend/Resources/grid.png");

	FramerateCounter framerate_counter;

	unsigned int time_last = CL_System::get_time();
	// Run until someone presses escape
	while (!quit)
	{
		framerate_counter.frame_shown();

		unsigned int time_now = CL_System::get_time();
		time_delta = time_now - time_last;
		time_last = time_now;

		// Copy direction options
		light_distant->rotation_y = options->light_direction_heading;
		light_distant->rotation_x = options->light_direction_pitch;

		// Set material options

		float shininess = options->material_shininess;

		// Convert shininess from a percentage, using Lightwave 3d's method
		shininess = shininess / 100.0f;
		shininess = pow(2, (10.0f * shininess) + 2);

		teapot->model.SetMaterial(
			shininess,		// material_shininess
			CL_Vec4f(options->material_emission_color.r, options->material_emission_color.g, options->material_emission_color.b, options->material_emission_color.a),	// material_emission
			CL_Vec4f(options->material_ambient_color.r, options->material_ambient_color.g, options->material_ambient_color.b, options->material_ambient_color.a),	// material_ambient
			CL_Vec4f(options->material_specular_color.r, options->material_specular_color.g, options->material_specular_color.b, options->material_specular_color.a)	//material_specular
			);

		rotate_teapot();

		calculate_matricies(gc);

		update_light(gc, options);

		polygon_rasterizer.set_culled(true);
		gc.set_polygon_rasterizer(polygon_rasterizer);
		render(gc);

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_map_mode(cl_map_2d_upper_left);
		polygon_rasterizer.set_culled(false);
		gc.set_polygon_rasterizer(polygon_rasterizer);

		CL_String fps(cl_format("%1 fps", framerate_counter.get_framerate()));
		font.draw_text(gc, 16-2, gc.get_height()-16-2, fps, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
		font.draw_text(gc, 16, gc.get_height()-16-2, fps, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

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

		// Use flip(1) to lock the fps
		window.flip(0);

		// This call processes user input and other events
		CL_KeepAlive::process();
	}

	return 0;
}
Exemplo n.º 30
0
	CL_LightModel_GL1_Impl()
	: lighting_enabled(false), local_viewer(false), two_sided_materials(false),
	  color_control(cl_color_control_single_color), flat_shading(false)
	{
		scene_ambient_light = CL_Colorf(0.2f, 0.2f, 0.2f, 1.0f);
	}