コード例 #1
0
	void render(const example_state_view& state)
	override
	{
		rad += radians_(0.5f*state.frame_duration().value());

		current_buf = (current_buf+1)%2;

		gl.uniform(
			prog.light_pos,
			vec3(cos(rad)*4, sin(rad)*4, 8)
		);

		gl.uniform(
			prog.modelview,
			matrix_rotation_x(rad*1)*
			matrix_rotation_y(rad*2)*
			matrix_rotation_z(rad*3)
		);

		// draw into the texture
		gl.bind(GL.draw_framebuffer, rnd_tex.fbos[current_buf]);
		gl.viewport(tex_side, tex_side);

		GLfloat s = 0.5f;

		gl.uniform(
			prog.projection,
			oglplus::matrix_perspective(-s,+s, -s,+s, 1.0f, 5)*
			oglplus::matrix_translation(0,0,-2)
		);

		gl.clear(GL.color_buffer_bit|GL.depth_buffer_bit);
		gl.draw_arrays(GL.triangles, 0, 6 * 2 * 3);

		// draw on screen
		gl.bind(GL.draw_framebuffer, default_framebuffer);
		gl.viewport(state.width(), state.height());

		gl.uniform(prog.cube_tex, GLint(current_buf));

		GLfloat h = 0.55f;
		GLfloat w = h*state.aspect();

		gl.uniform(
			prog.projection,
			oglplus::matrix_perspective(-w,+w, -h,+h, 1, 3)*
			oglplus::matrix_translation(0,0,-2)
		);

		gl.clear(GL.color_buffer_bit|GL.depth_buffer_bit);
		gl.draw_arrays(GL.triangles, 0, 6 * 2 * 3);

	}
コード例 #2
0
ファイル: 008_texgen.cpp プロジェクト: matus-chochlik/oglplu2
	example_texgen(void)
	 : scale(1.0f)
	 , aspect(1.0f)
	{
		gl.uniform(erg.scale_loc, scale, scale);
		gl.disable(GL.depth_test);
	}
コード例 #3
0
	void user_idle(const example_state_view& state)
	override
	{
		if(state.user_idle_time() > seconds_(1))
		{
			const float t = value(state.frame_duration())*60;

			scale *= std::pow(1.f+0.05f*t, scale_dir);
			if(scale < min_scale)
			{
				scale_dir *= -1.f;
				ofs_x_dir *= -1.f;
				ofs_y_dir *= ofs_x_dir;
				scale = min_scale;
			}
			if(scale > max_scale)
			{
				scale_dir *= -1.f;
				ofs_y_dir *= -1.f;
				ofs_x_dir *= ofs_y_dir;
				scale = max_scale;
			}

			offset_x += ofs_x_dir*t*scale/30;
			offset_y += ofs_y_dir*t*scale/30;

			gl.uniform(prog.offset_loc, offset_x, offset_y);
			gl.uniform(prog.scale_loc, scale*aspect, scale);
		}
	}
コード例 #4
0
	void resize(const example_state_view& state)
	override
	{
		gl.viewport(state.width(), state.height());

		aspect = state.aspect();
		gl.uniform(prog.scale_loc, scale*aspect, scale);
	}
コード例 #5
0
ファイル: 008_texgen.cpp プロジェクト: matus-chochlik/oglplu2
	void pointer_scrolling(const example_state_view& state)
	override
	{
		scale *= float(std::pow(2,-state.norm_delta_pointer_z()));
		if(scale < min_scale) scale = min_scale;
		if(scale > max_scale) scale = max_scale;

		gl.uniform(erg.scale_loc, scale*aspect, scale);
	}
コード例 #6
0
	void set_projection(const example_state_view& state)
	{
		auto projection = 
			matrix_perspective::y(
				right_angle_(),
				state.aspect(),
				0.5f, 50.f
			)*matrix_orbiting_y_up(
				vec3(),
				smooth_lerp(1.5f, 5.0f, cam_orbit),
				turns_(cam_turns),
				smooth_oscillate(radians_(1.5f), cam_pitch)
			);

		gl.use(light_prog);
		gl.uniform(light_prog.projection, projection);
		gl.use(erase_prog);
		gl.uniform(erase_prog.projection, projection);
	}
コード例 #7
0
	void pointer_motion(const example_state_view& state)
	override
	{
		if(state.pointer_dragging())
		{
			offset_x -= 2*state.norm_delta_pointer_x()*scale;
			offset_y -= 2*state.norm_delta_pointer_y()*scale;

			gl.uniform(prog.offset_loc, offset_x, offset_y);
		}
	}
コード例 #8
0
ファイル: 008_texgen.cpp プロジェクト: matus-chochlik/oglplu2
	void user_idle(const example_state_view& state)
	override
	{
		if(state.user_idle_time() > seconds_(1))
		{
			using namespace eagine::math;
			float new_sc = float(smooth_lerp(
				min_scale,
				max_scale,
				value(state.exec_time())*0.4f
			));

			scale = interpolate_linear(new_sc, scale, 0.9f);

			gl.uniform(erg.scale_loc, scale, scale);
		}
	}
コード例 #9
0
ファイル: 011_mandelbrot.cpp プロジェクト: deranen/oglplu2
	void user_idle(const example_state_view& state)
	override
	{
		if(state.user_idle_time() > seconds_(1))
		{
			const float s = value(state.frame_duration())*60;
			const float dest_offset_x = -0.525929f;
			const float dest_offset_y = -0.668547f;
			const float c = 0.02f * s;

			offset_x = c*dest_offset_x + (1-c)*offset_x;
			offset_y = c*dest_offset_y + (1-c)*offset_y; 

			scale *= (1-0.01f*s);
			if(scale < min_scale) scale = min_scale;

			gl.uniform(offset_loc, offset_x, offset_y);
			gl.uniform(scale_loc, scale*aspect, scale);
		}
	}
コード例 #10
0
	void render(const example_state_view& state)
	override
	{
		gl.use(erase_prog);
		gl.disable(GL.depth_test);
		background.use();
		background.draw();

		shp_turns += 0.1f*state.frame_duration().value();

		gl.use(light_prog);
		gl.uniform(
			light_prog.modelview,
			matrix_rotation_x(turns_(shp_turns)/1)*
			matrix_rotation_y(turns_(shp_turns)/2)*
			matrix_rotation_z(turns_(shp_turns)/3)
		);

		gl.clear(GL.depth_buffer_bit);
		gl.enable(GL.depth_test);
		shape.use();
		shape.draw();
	}
コード例 #11
0
ファイル: 011_mandelbrot.cpp プロジェクト: deranen/oglplu2
	example_mandelbrot(void)
	 : offset_x(-0.5f)
	 , offset_y(0.0f)
	 , scale(1.0f)
	 , aspect(1.0f)
	{
		shader vs(GL.vertex_shader);
		vs.source(glsl_literal(
			"#version 130\n"
			"uniform vec2 Offset;\n"
			"uniform vec2 Scale;\n"
			"in vec2 Position;\n"
			"in vec2 Coord;\n"
			"out vec2 vertCoord;\n"
			"void main(void)\n"
			"{\n"
			"	vertCoord = Coord*Scale+Offset;\n"
			"	gl_Position = vec4(Position, 0.0, 1.0);\n"
			"}\n"
		));
		vs.compile();

		shader fs(GL.fragment_shader);
		fs.source(glsl_literal(
		"#version 130\n"
		"uniform sampler1D gradient;\n"
		"in vec2 vertCoord;\n"
		"out vec4 fragColor;\n"
		"void main(void)\n"
		"{\n"
		"	vec2 z = vec2(0.0, 0.0);\n"
		"	vec2 c = vertCoord;\n"
		"	int i = 0, max = 256;\n"
		"	while((i != max) && (distance(z, c) < 2.0))\n"
		"	{\n"
		"		vec2 zn = vec2(\n"
		"			z.x * z.x - z.y * z.y + c.x,\n"
		"			2.0 * z.x * z.y + c.y\n"
		"		);\n"
		"		z = zn;\n"
		"		++i;\n"
		"	}\n"
		"	float a = float(i)/float(max);\n"
		"	fragColor = texture(gradient, a+sqrt(length(c))*0.1);\n"
		"} \n"
		));
		fs.compile();

		prog.attach(vs);
		prog.attach(fs);
		prog.link();

		gl.use(prog);

		gl.query_location(offset_loc, prog, "Offset");
		gl.query_location(scale_loc, prog, "Scale");
		gl.uniform(offset_loc, offset_x, offset_y);


		gl.bind(vao);

		GLfloat position_data[4*2] = {
			-1.0f, -1.0f,
			-1.0f,  1.0f,
			 1.0f, -1.0f,
			 1.0f,  1.0f
		};

		gl.bind(GL.array_buffer, positions);
		gl.buffer_data(GL.array_buffer, position_data, GL.static_draw);

		vertex_attrib_location va_p;
		gl.query_location(va_p, prog, "Position");
		gl.vertex_array_attrib_pointer(
			va_p,
			2, GL.float_,
			false, 0, nullptr
		);
		gl.enable_vertex_array_attrib(va_p);


		GLfloat coord_data[4*2] = {
			-1.0f, -1.0f,
			-1.0f,  1.0f,
			 1.0f, -1.0f,
			 1.0f,  1.0f
		};

		gl.bind(GL.array_buffer, coords);
		gl.buffer_data(GL.array_buffer, coord_data, GL.static_draw);

		vertex_attrib_location va_c;
		gl.query_location(va_c, prog, "Coord");
		gl.vertex_array_attrib_pointer(
			va_c,
			2, GL.float_,
			false, 0, nullptr
		);
		gl.enable_vertex_array_attrib(va_c);

		GLfloat gradient_data[8*3];

		for(int i=0; i<8*3; ++i)
		{
			gradient_data[i] = (std::rand() % 10000) / 10000.f;
		}

		gl.bind(GL.texture_1d, gradient);
		gl.texture_min_filter(GL.texture_1d, GL.linear);
		gl.texture_mag_filter(GL.texture_1d, GL.linear);
		gl.texture_wrap(
			GL.texture_1d,
			GL.texture_wrap_s,
			GL.repeat
		);
		gl.texture_image_1d(
			GL.texture_1d,
			0, GL.rgb,
			8,
			0, GL.rgb,
			GL.float_,
			const_memory_block{gradient_data}
		);

		gl.disable(GL.depth_test);
	}