GLXContext CL_OpenGLWindowProvider_GLX::create_context_glx_1_3_helper(GLXContext shared_context, int major_version, int minor_version, const CL_OpenGLWindowDescription &gldesc, ptr_glXCreateContextAttribs glXCreateContextAttribs)
{
	std::vector<int> int_attributes;

	int_attributes.push_back(0x2091);	// GLX_CONTEXT_MAJOR_VERSION_ARB
	int_attributes.push_back(major_version);
	int_attributes.push_back(0x2092);	// GLX_CONTEXT_MINOR_VERSION_ARB
	int_attributes.push_back(minor_version);

	// Layer plane does not exist on GLX - http://www.opengl.org/registry/specs/ARB/glx_create_context.txt
	//int_attributes.push_back(0x2093);	// GLX_CONTEXT_LAYER_PLANE_ARB
	//int_attributes.push_back(gldesc.get_layer_plane());

	int_attributes.push_back(0x2094);	// GLX_CONTEXT_FLAGS_ARB
	int flags = 0;
	if (gldesc.get_debug())
		flags |= 0x1;	// GLX_CONTEXT_DEBUG_BIT_ARB
	if (gldesc.get_forward_compatible())	// GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
		flags |= 0x2;	
	int_attributes.push_back(flags);

	int_attributes.push_back(0x9126);	// GLX_CONTEXT_PROFILE_MASK_ARB
	flags = 0;
	if (gldesc.get_core_profile())
		flags |= 0x1;	// GLX_CONTEXT_CORE_PROFILE_BIT_ARB
	if (gldesc.get_compatibility_profile())	// GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
		flags |= 0x2;	
	int_attributes.push_back(flags);

	int_attributes.push_back(None);
	
	cl_ctxErrorOccurred = false;

	GLXContext context_gl3 = glXCreateContextAttribs(x11_window.get_display(), fbconfig, shared_context, True, &int_attributes[0]);

	if (cl_ctxErrorOccurred)
	{
		if (context_gl3)
		{
			glx.glXDestroyContext(x11_window.get_display(), context_gl3);
			context_gl3 = 0;
		}
	}
	return context_gl3;
}
GLXContext CL_OpenGLWindowProvider_GLX::create_context_glx_1_2(const CL_OpenGLWindowDescription &gl_desc, GLXContext shared_context)
{
	if (gl_desc.get_allow_lower_versions() == false)
		throw CL_Exception("GLX 1.2 does not support opengl version selection.");

	GLXContext context;
	context = glx.glXCreateContext(x11_window.get_display(), opengl_visual_info, shared_context, GL_TRUE);
	if(context == NULL)
		throw CL_Exception("glXCreateContext failed");

	return context;
}
예제 #3
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;
}
예제 #4
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;
}
예제 #5
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;
}
예제 #6
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;
}
GLXContext CL_OpenGLWindowProvider_GLX::create_context_glx_1_3(const CL_OpenGLWindowDescription &gl_desc, GLXContext shared_context)
{
	GLXContext context;

	context = glx.glXCreateNewContext(x11_window.get_display(), fbconfig, GLX_RGBA_TYPE, shared_context, True);
	if(context == NULL)
		throw CL_Exception("glXCreateContext failed");
	
	ptr_glXCreateContextAttribs glXCreateContextAttribs = NULL;

	if (is_glx_extension_supported("GLX_ARB_create_context"))
	{
		if (glx.glXGetProcAddressARB)
			glXCreateContextAttribs = (ptr_glXCreateContextAttribs) glx.glXGetProcAddressARB((GLubyte*) "glXCreateContextAttribsARB");
		if (glx.glXGetProcAddress)
			glXCreateContextAttribs = (ptr_glXCreateContextAttribs) glx.glXGetProcAddress((GLubyte*) "glXCreateContextAttribsARB");
	}


	if (glXCreateContextAttribs)
	{
		// Install an X error handler so the application won't exit if GL 3.0 context allocation fails.
		//
		// Note this error handler is global.  All display connections in all threads
		// of a process use the same error handler, so be sure to guard against other
		// threads issuing X commands while this code is running.
		int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&cl_ctxErrorHandler);
	  
		GLXContext context_gl3 = 0;

		int gl_major = gl_desc.get_version_major();
		int gl_minor = gl_desc.get_version_minor();
		if (gl_desc.get_allow_lower_versions() == false)
		{
			context_gl3 = create_context_glx_1_3_helper(shared_context, gl_major, gl_minor, gl_desc, glXCreateContextAttribs);
	
			if (!context_gl3)
				throw CL_Exception(cl_format("This application requires OpenGL %1.%2 or above. Try updating your drivers, or upgrade to a newer graphics card.",  gl_major, gl_minor));
		}
		else
		{
			static const char opengl_version_list[] = 
			{
				// Clanlib supported version pairs
				4,1,
				4,0,
				3,3,
				3,2,
				3,1,
				3,0,
				0,0,	// End of list
			};

			const char *opengl_version_list_ptr = opengl_version_list;
			do
			{
				int major = *(opengl_version_list_ptr++);
				if (major == 0)
					break;
					
				int minor = *(opengl_version_list_ptr++);

				// Find the appropriate version in the list
				if (major > gl_major)
					continue;

				if (major == gl_major)
				{
					if (minor > gl_minor)
						continue;	
				}

				context_gl3 = create_context_glx_1_3_helper(shared_context, gl_major, gl_minor, gl_desc, glXCreateContextAttribs);

			}while(!context_gl3);
		}
		
		// Restore the original error handler
		XSetErrorHandler( oldHandler );		
		
		if (context_gl3)
		{
			glx.glXDestroyContext(x11_window.get_display(), context);
			context = context_gl3;
		}
	}
	return context;
}
예제 #8
0
int App::start(const std::vector<CL_String> &args)
{
	CL_OpenGLWindowDescription description;
	description.set_title("Guassian Blur 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_offscreen2(gc, gc.get_width(), gc.get_height());
	texture_offscreen2.set_min_filter(cl_filter_nearest);
	texture_offscreen2.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_offscreen2(gc);
	framebuffer_offscreen2.attach_color_buffer(0, texture_offscreen2);

	CL_Image background(gc, "../PostProcessing/Resources/background.png");
	CL_Image ball(gc, "../PostProcessing/Resources/ball.png");
	ball.set_alignment(origin_center);

	// 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);

	blur = 1.0f;
	unsigned int startTime = CL_System::get_time();

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

		// 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();

		gc.set_frame_buffer(framebuffer_offscreen2);
		render_gaussian_blur(gc, blur, texture_offscreen, shader, 1.0f / texture_offscreen2.get_width(), 0.0f);
		gc.reset_frame_buffer();

		render_gaussian_blur(gc, blur, texture_offscreen2, shader, 0.0f, 1.0f / texture_offscreen2.get_height());

		CL_String text( "Press 1 to 9 to control blur amount. Currently it is :" + CL_StringHelp::float_to_text(blur) );
		font.draw_text(gc, 10, 64, text);

		window.flip();

		CL_System::sleep(10);

		CL_KeepAlive::process();
	}

	return 0;
}
예제 #9
0
int App::start(const std::vector<CL_String> &args)
{
	CL_OpenGLWindowDescription description;
	description.set_title("GLSL Test");
	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_window_close = window.sig_window_close().connect(this, &App::window_close);

	// 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");
	if (!shader.link())
		throw CL_Exception("Unable to link shader program: Error:" + shader.get_info_log());

	quit = false;

	while (!keyboard.get_keycode(CL_KEY_ESCAPE) && !quit )
	{
		gc.clear();
		gc.set_program_object(shader, cl_program_matrix_modelview_projection);
		//shader.set_uniform1i("SourceTexture", 0);

		int xpos = 0;
		int size = 16;
		int gap = size + 2;

		//-------- Test 1
		CL_Mat2f matrix2_a = CL_Mat2f(3, 1, 2, 4);
		CL_Mat2f matrix2_b = CL_Mat2f(-3, 7, 2, 5);
		CL_Mat2f matrix2_result = CL_Mat2f::multiply(matrix2_a, matrix2_b);

		CL_Mat2f matrix2_a_temp = matrix2_a;
		if (CL_Mat2i(matrix2_result) != CL_Mat2i(matrix2_a * matrix2_b))
			throw CL_Exception("Failure");

		shader.set_uniform1i("test_id", 1);
		shader.set_uniform_matrix("matrix2_a", matrix2_a);
		shader.set_uniform_matrix("matrix2_b", matrix2_b);
		shader.set_uniform_matrix("matrix2_result", matrix2_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 2
		CL_Mat3f matrix3_a = CL_Mat3f(3, 1, 2, 4, 5 ,6, 4, 2, 1);
		CL_Mat3f matrix3_b = CL_Mat3f(4, 7, 2, 5, 3, 5, 2, 9, 3);
		CL_Mat3f matrix3_result = CL_Mat3f::multiply(matrix3_a, matrix3_b);

		CL_Mat3f matrix3_a_temp = matrix3_a;
		if (CL_Mat3i(matrix3_result) != CL_Mat3i(matrix3_a * matrix3_b))
			throw CL_Exception("Failure");

		shader.set_uniform1i("test_id", 2);
		shader.set_uniform_matrix("matrix3_a", matrix3_a);
		shader.set_uniform_matrix("matrix3_b", matrix3_b);
		shader.set_uniform_matrix("matrix3_result", matrix3_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 3
		static float test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2};
		static float test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2};

		CL_Mat4f matrix4_a = CL_Mat4f(test_a_values);
		CL_Mat4f matrix4_b = CL_Mat4f(test_b_values);
		CL_Mat4f matrix4_result = CL_Mat4f::multiply(matrix4_a, matrix4_b);

		CL_Mat4f matrix4_a_temp = matrix4_a;
		if (CL_Mat4i(matrix4_result) != CL_Mat4i(matrix4_a * matrix4_b))
			throw CL_Exception("Failure");

		shader.set_uniform1i("test_id", 3);
		shader.set_uniform_matrix("matrix4_a", matrix4_a);
		shader.set_uniform_matrix("matrix4_b", matrix4_b);
		shader.set_uniform_matrix("matrix4_result", matrix4_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 4
		matrix2_result = CL_Mat2f::subtract(matrix2_a, matrix2_b);

		matrix2_a_temp = matrix2_a;
		if (CL_Mat2i(matrix2_result) != CL_Mat2i(matrix2_a - matrix2_b))
			throw CL_Exception("Failure");

		shader.set_uniform1i("test_id", 4);
		shader.set_uniform_matrix("matrix2_a", matrix2_a);
		shader.set_uniform_matrix("matrix2_b", matrix2_b);
		shader.set_uniform_matrix("matrix2_result", matrix2_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 5
		matrix3_result = CL_Mat3f::subtract(matrix3_a, matrix3_b);

		matrix3_a_temp = matrix3_a;
		if (CL_Mat3i(matrix3_result) != CL_Mat3i(matrix3_a - matrix3_b))
			throw CL_Exception("Failure");

		shader.set_uniform1i("test_id", 5);
		shader.set_uniform_matrix("matrix3_a", matrix3_a);
		shader.set_uniform_matrix("matrix3_b", matrix3_b);
		shader.set_uniform_matrix("matrix3_result", matrix3_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 6

		matrix4_result = CL_Mat4f::subtract(matrix4_a, matrix4_b);

		matrix4_a_temp = matrix4_a;
		if (CL_Mat4i(matrix4_result) != CL_Mat4i(matrix4_a - matrix4_b))
			throw CL_Exception("Failure");

		shader.set_uniform1i("test_id", 6);
		shader.set_uniform_matrix("matrix4_a", matrix4_a);
		shader.set_uniform_matrix("matrix4_b", matrix4_b);
		shader.set_uniform_matrix("matrix4_result", matrix4_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 7
		CL_Vec2f vector2_a(2,3);
		CL_Vec2f vector2_result = vector2_a * matrix2_a;

		shader.set_uniform1i("test_id", 7);
		shader.set_uniform_matrix("matrix2_a", matrix2_a);
		shader.set_uniform2f("vector2_a", vector2_a);
		shader.set_uniform2f("vector2_result", vector2_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 8
		vector2_result = matrix2_a * vector2_a;

		shader.set_uniform1i("test_id", 8);
		shader.set_uniform_matrix("matrix2_a", matrix2_a);
		shader.set_uniform2f("vector2_a", vector2_a);
		shader.set_uniform2f("vector2_result", vector2_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;


		//-------- Test 9
		CL_Vec3f vector3_a(3,5,6);
		CL_Vec3f vector3_result = vector3_a * matrix3_a;

		shader.set_uniform1i("test_id", 9);
		shader.set_uniform_matrix("matrix3_a", matrix3_a);
		shader.set_uniform3f("vector3_a", vector3_a);
		shader.set_uniform3f("vector3_result", vector3_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 10
		vector3_result = matrix3_a * vector3_a;

		shader.set_uniform1i("test_id", 10);
		shader.set_uniform_matrix("matrix3_a", matrix3_a);
		shader.set_uniform3f("vector3_a", vector3_a);
		shader.set_uniform3f("vector3_result", vector3_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;
		//-------- Test 11
		CL_Vec4f vector4_a(4,3,5,6);
		CL_Vec4f vector4_result = vector4_a * matrix4_a;

		shader.set_uniform1i("test_id", 11);
		shader.set_uniform_matrix("matrix4_a", matrix4_a);
		shader.set_uniform4f("vector4_a", vector4_a);
		shader.set_uniform4f("vector4_result", vector4_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;

		//-------- Test 12
		vector4_result = matrix4_a * vector4_a;

		shader.set_uniform1i("test_id", 12);
		shader.set_uniform_matrix("matrix4_a", matrix4_a);
		shader.set_uniform4f("vector4_a", vector4_a);
		shader.set_uniform4f("vector4_result", vector4_result);
		draw(gc, CL_Rect(xpos, 0, CL_Size(size, size)));
		xpos+=gap;


		gc.reset_program_object();
		window.flip();

		CL_System::sleep(10);

		CL_KeepAlive::process();
	}

	return 0;
}
예제 #10
0
파일: clangl.cpp 프로젝트: sim82/shooter2
	void mainloop() {
		CL_OpenGLWindowDescription desc;
		desc.set_size( CL_Size( 1024, 768 ), true );

		CL_DisplayWindow wnd(desc);

		CL_GraphicContext gc = wnd.get_gc();





		glMatrixMode(GL_PROJECTION);						//hello
		//		gluPerspective(45, //view angle
		//					1.0,	//aspect ratio
		//					10.0, //near clip
		//					200.0);//far clip

		GLfloat matrix[16];
		glhPerspectivef2(matrix, 45, 1.0, 10.0, 200.0 );

		glLoadMatrixf( matrix );

		glMatrixMode(GL_MODELVIEW);




		cube c;
		float rotateBy;

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


		GUI gui(&wnd);

		while( true ) {



			rotateBy += 1;
			glEnable(GL_CULL_FACE);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


			glPushMatrix();


			glTranslatef(0,0,-50);
			glRotatef(rotateBy,1,1,0);

			glBegin(GL_QUADS);

			c.redraw();

			glEnd();
			glPopMatrix();


			glDisable( GL_CULL_FACE );
			CL_Draw::line(gc, 0, 0, 100, 100, CL_Colorf( 1.0f ,1.0f ,1.0f ));
			font.draw_text( gc, 100, 100, "bla bla bla", CL_Colorf( 1.0f, 1.0f, 1.0f ));

			gui.run(&wnd);
			wnd.flip();

			CL_System::sleep( 10 );
			CL_KeepAlive::process();
		}

	}
예제 #11
0
파일: ortho.cpp 프로젝트: sim82/shooter2
    ortho() :
      pump_factor_(4) 
    {

//         glVertexPointer(4, GL_FLOAT, 0, ptr);
        //glEnableClientState( GL_VERTEX_ARRAY );
//         glColorPointer(

        //std::ifstream is( "cryistal-castle-hidden-ramp.txt" );
//         std::ifstream is( "house1.txt" );
        //std::ifstream is( "cryistal-castle-tree-wave.txt" );

//         assert( is.good() );
//         height_fields_ = crystal_bits::load_crystal(is, pump_factor_);
//         std::cout << "hf: " << height_fields_.size() << "\n";
//         
//         
//         
//         scene_static_.init_solid(height_fields_);
//         
        
//         scene_static_.init_solid_from_crystal(is, pump_factor_);
        

//         scene_static_.init_planes();

//         uint64_t scene_hash = scene_static_.hash();
//         
//         try {
//             std::ifstream is( "ff.bin" );
//             
//             
//             light_static_ = light_static( is, scene_hash );
//         } catch( std::runtime_error x ) {
//             
//             std::cerr << "load failed. recreating. error:\n" << x.what() << std::endl;
//             
//             light_static_ = setup_formfactors(scene_static_.planes(), scene_static_.solid());    
//         }
//         
//         if( !false ) {
//             std::ofstream os( "ff.bin" );
//             light_static_.write(os, scene_hash);
//         }
//         
//         
//         light_dynamic_ = light_dynamic(scene_static_.planes().size() );
        
        CL_OpenGLWindowDescription desc;
        desc.set_size( CL_Size( 1024, 768 ), true );

        desc.set_depth_size(16);
        //std::cout << "depth: " << desc.get_depth_size();
        
        wnd_ = CL_DisplayWindow(desc);

        CL_GraphicContext_GL gc = wnd_.get_gc();
//      //CL_Mat4f proj = CL_Mat4f::ortho( 0, 1024, 0, 768, 100, -100 );


        gc.set_active();
#ifdef TEST_OPENCL
        try {
            init_opencl();
        } catch( cl::Error x ) {
            
//             std::array<void*, 256> bt;
//             //void *bt[256];
//             
//             size_t size = backtrace( bt.data(), bt.size() );
//             char **strings = backtrace_symbols( bt.data(), size );
//             std::cout << "backtrace: " << size << "\n";
//             for( size_t i = 0; i < size; ++i ) {
//                 std::cout << i << " " << strings[i] << "\n";
//             }
//             free( strings );
            
            std::cerr << "opencl initialization failed\ncall: " << x.what() << "\nerror code: " << cl_str_error( x.err() ) << "\n";            
            throw;
        }
#endif
      //  throw 0;
        
        glMatrixMode(GL_PROJECTION);                        //hello

        
        

        CL_Mat4f proj = CL_Mat4f::perspective( 60, 1.5, 2, 200 );
//      CL_Mat4f proj = CL_Mat4f::ortho( -20.0 * pump_factor_, 20.0 * pump_factor_, -15.0 * pump_factor_, 15.0 * pump_factor_, 0, 200 );
        //CL_Mat4f proj = CL_Mat4f::ortho( -40, 40, -30, 30, 0, 200 );


        glLoadMatrixf( proj.matrix );


        //CL_Texture tex(gc, 64, 64 );


        struct texel {
            GLubyte col[3];
            GLubyte alpha;

            texel() {
                col[0] = 128;
                col[1] = 128;
                col[2] = 128;
                alpha = 255;

            }
        };

        std::array<texel,64 * 64> tex_data;

        glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0);
//      glGenTextures(1, &texName);
//      glBindTexture(GL_TEXTURE_2D, texName);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data.data());


//      gc.set_map_mode(cl_user_projection);
//      gc.set_projection(proj);
//
//      gc.flush_batcher();
//      glMatrixMode(GL_PROJECTION);


        glMatrixMode(GL_MODELVIEW);


        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);
        glDepthFunc(GL_LESS);
        
        glEnable(GL_TEXTURE_2D);
        glShadeModel(GL_FLAT);
    }
예제 #12
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	CL_OpenGLWindowDescription desc;
	desc.set_title("ClanLib Shadow Example");
	desc.set_size(CL_Size(640, 640), true);
	desc.set_multisampling(4);
	desc.set_depth_size(16);

	CL_DisplayWindow window(desc);

#ifdef _DEBUG
	//struct aiLogStream stream;
	//stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	//aiAttachLogStream(&stream);
	//stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	//aiAttachLogStream(&stream);
#endif
	aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,89.53f);

	// 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();

	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_FrameBuffer framebuffer(gc);

	CL_Texture new_depth_texture(gc, CL_Size(1024, 1024), cl_depth_component);
	new_depth_texture.set_wrap_mode(cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge);
	framebuffer.attach_depth_buffer(new_depth_texture);

	scene.gs->texture_shadow = new_depth_texture;

	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;

		rotate_teapot();
		control_camera();
		update_light(gc);

		calculate_matricies(gc);

		render_from_lightsource(gc, framebuffer);
		render_from_camera(gc, framebuffer);

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

		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));

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

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