Esempio n. 1
0
Program RaytraceProg::make(void)
{
	Program prog;

	ResourceFile vs_source("glsl", "raytrace", ".vs.glsl");
	prog << VertexShader(GLSLSource::FromStream(vs_source));

	ResourceFile fs_rs_source("glsl", "raysample", ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(fs_rs_source));

	ResourceFile fs_rt_source("glsl", "raytrace", ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(fs_rt_source));

	ResourceFile fs_pk_source("glsl", "pack", ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(fs_pk_source));

	ResourceFile fs_en_source("glsl", "encode", ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(fs_en_source));

	prog.Link().Use();

	return std::move(prog);
}
Esempio n. 2
0
Program RenderProg::make(const AppData& app_data)
{
	Program prog;

	ResourceFile vs_source("glsl", "render", ".vs.glsl");
	prog << VertexShader(GLSLSource::FromStream(vs_source));

	ResourceFile pk_source("glsl", "pack", ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(pk_source));

	ResourceFile dc_source("glsl", "decode", ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(dc_source));

	std::string fs_name("render-");
	fs_name.append(app_data.finish_shader);
	ResourceFile fs_source("glsl", fs_name, ".fs.glsl");
	prog << FragmentShader(GLSLSource::FromStream(fs_source));

	prog.Link().Use();

	Optional<Uniform<GLfloat>>(prog, "Near").TrySet(app_data.cam_near);
	Optional<Uniform<GLfloat>>(prog, "Far").TrySet(app_data.cam_far);

	Optional<Uniform<Vec3f>>(prog, "LightPos").TrySet(Vec3f(
		app_data.light_x,
		app_data.light_y,
		app_data.light_z
	));
	Optional<Uniform<GLfloat>>(prog, "HighLight").TrySet(app_data.high_light);
	Optional<Uniform<GLfloat>>(prog, "AmbiLight").TrySet(app_data.ambi_light);

	Optional<Uniform<GLfloat>>(prog, "PlanetRadius").TrySet(app_data.planet_radius);
	Optional<Uniform<GLfloat>>(prog, "AtmThickness").TrySet(app_data.atm_thickness);

	return std::move(prog);
}
Esempio n. 3
0
	RectangleExample(void)
	 : vs(ShaderType::Vertex)
	 , fs(ShaderType::Fragment)
	{
		// this could be any istream
		std::stringstream vs_source(
			"#version 120\n"
			"attribute vec2 Position;"
			"attribute vec3 Color;"
			"varying vec3 vertColor;"
			"void main(void)"
			"{"
			"	vertColor = Color;"
			"	gl_Position = vec4(Position, 0.0, 1.0);"
			"}"
		);
		// set the vertex shader source
		vs.Source(GLSLSource::FromStream(vs_source));
		// compile it
		vs.Compile();

		std::stringstream fs_source(
			"#version 120\n"
			"varying vec3 vertColor;"
			"void main(void)"
			"{"
			"	gl_FragColor = vec4(vertColor, 1.0);"
			"}"
		);
		// set the fragment shader source
		fs.Source(GLSLSource::FromStream(fs_source));
		// compile it
		fs.Compile();

		// attach the shaders to the program
		prog.AttachShader(vs);
		prog.AttachShader(fs);
		// link it
		prog.Link();

		// and use it
		gl.Program.Bind(prog);
		// bind the VAO for the rectangle
		gl.VertexArray.Bind(rectangle);

		// bind the VBO for the rectangle vertices
		if(auto x = gl.Buffer.Array.Push(verts))
		{
			GLfloat rectangle_verts[8] = {
				-1.0f, -1.0f,
				-1.0f,  1.0f,
				 1.0f, -1.0f,
				 1.0f,  1.0f
			};
			// upload the data
			gl.Buffer.Array.Data(8, rectangle_verts);
			// setup the vertex attribs array for the vertices
			VertexArrayAttrib vert_attr(prog, "Position");
			vert_attr.Setup<Vec2f>().Enable();
		}
		// bind the VBO for the rectangle colors
		if(auto x = gl.Buffer.Array.Push(colors))
		{
			GLfloat rectangle_colors[12] = {
				1.0f, 1.0f, 1.0f,
				1.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f,
				0.0f, 0.0f, 1.0f,
			};
			// upload the data
			gl.Buffer.Array.Data(12, rectangle_colors);
			// setup the vertex attribs array for the vertices
			VertexArrayAttrib color_attr(prog, "Color");
			color_attr.Setup<Vec3f>().Enable();
		}
		gl.Caps.DepthTest.Disable();
	}
Esempio n. 4
0
	RectangleExample(void)
	 : vs(ShaderType::Vertex)
	 , fs(ShaderType::Fragment)
	{
		// this could be any istream
		std::stringstream vs_source(
			"#version 330\n"
			"in vec2 Position;"
			"in vec3 Color;"
			"out vec3 vertColor;"
			"void main(void)"
			"{"
			"	vertColor = Color;"
			"	gl_Position = vec4(Position, 0.0, 1.0);"
			"}"
		);
		// set the vertex shader source
		vs.Source(GLSLSource::FromStream(vs_source));
		// compile it
		vs.Compile();

		std::stringstream fs_source(
			"#version 330\n"
			"in vec3 vertColor;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	fragColor = vec4(vertColor, 1.0);"
			"}"
		);
		// set the fragment shader source
		fs.Source(GLSLSource::FromStream(fs_source));
		// compile it
		fs.Compile();

		// attach the shaders to the program
		prog.AttachShader(vs);
		prog.AttachShader(fs);
		// link and use it
		prog.Link();
		prog.Use();

		// bind the VAO for the rectangle
		rectangle.Bind();

		GLfloat rectangle_verts[8] = {
			-1.0f, -1.0f,
			-1.0f,  1.0f,
			 1.0f, -1.0f,
			 1.0f,  1.0f
		};
		// bind the VBO for the rectangle vertices
		verts.Bind(Buffer::Target::Array);
		// upload the data
		Buffer::Data(Buffer::Target::Array, 8, rectangle_verts);
		// setup the vertex attribs array for the vertices
		VertexAttribArray vert_attr(prog, "Position");
		vert_attr.Setup<Vec2f>().Enable();

		GLfloat rectangle_colors[12] = {
			1.0f, 1.0f, 1.0f,
			1.0f, 0.0f, 0.0f,
			0.0f, 1.0f, 0.0f,
			0.0f, 0.0f, 1.0f,
		};
		// bind the VBO for the rectangle colors
		colors.Bind(Buffer::Target::Array);
		// upload the data
		Buffer::Data(Buffer::Target::Array, 12, rectangle_colors);
		// setup the vertex attribs array for the vertices
		VertexAttribArray color_attr(prog, "Color");
		color_attr.Setup<Vec3f>().Enable();
		//
		gl.Disable(Capability::DepthTest);
	}