当前位置: 首页>>代码示例>>C++>>正文


C++ VertexArray::Bind方法代码示例

本文整理汇总了C++中VertexArray::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexArray::Bind方法的具体用法?C++ VertexArray::Bind怎么用?C++ VertexArray::Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexArray的用法示例。


在下文中一共展示了VertexArray::Bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Render

	void Render(double time)
	{
		namespace se = oglplus::smart_enums;
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();
		// make the camera matrix orbiting around the origin
		// at radius of 3.5 with elevation between 15 and 90 degrees
		Mat4f camera = CamMatrixf::Orbiting(
			Vec3f(),
			6.5,
			Degrees(time * 135),
			Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75)
		);
		ModelMatrixf model = ModelMatrixf::Translation(0.0f, 1.5f, 0.0);
		ModelMatrixf identity;
		//
		SetProgramUniform(prog_norm, "CameraMatrix", camera);
		SetProgramUniform(prog_refl, "CameraMatrix", camera);
		// draw the plane into the stencil buffer
		prog_norm.Use();

		gl.Disable(se::Blend());
		gl.Disable(se::DepthTest());
		gl.Enable(se::StencilTest());
		gl.ColorMask(false, false, false, false);
		gl.StencilFunc(se::Always(), 1, 1);
		gl.StencilOp(se::Keep(), se::Keep(), se::Replace());

		Uniform<Mat4f> model_matrix_norm(prog_norm, "ModelMatrix");
		model_matrix_norm.Set(identity);
		plane.Bind();
		gl.DrawArrays(se::TriangleStrip(), 0, 4);

		gl.ColorMask(true, true, true, true);
		gl.Enable(se::DepthTest());
		gl.StencilFunc(se::Equal(), 1, 1);
		gl.StencilOp(se::Keep(), se::Keep(), se::Keep());

		// draw the torus using the reflection program
		prog_refl.Use();
		Uniform<Mat4f>(prog_refl, "ModelMatrix").Set(model);
		torus.Bind();
		torus_instr.Draw(torus_indices);

		gl.Disable(se::StencilTest());

		prog_norm.Use();
		// draw the torus using the normal object program
		model_matrix_norm.Set(model);
		torus_instr.Draw(torus_indices);

		// blend-in the plane
		gl.Enable(se::Blend());
		gl.BlendEquation(se::Max());
		model_matrix_norm.Set(identity);
		plane.Bind();
		gl.DrawArrays(se::TriangleStrip(), 0, 4);
	}
开发者ID:,项目名称:,代码行数:57,代码来源:

示例2: Render

	void Render(double time)
	{
		auto camera =
			CamMatrixf::Roll(Degrees(SineWave(time / 11.0)*7+SineWave(time/13.0)*5))*
			CamMatrixf::Orbiting(
				Vec3f(),
				40.0f,
				Degrees(SineWave(time / 11.0)*10+CosineWave(time/19.0)*10-90),
				Degrees(SineWave(time / 17.0)*10+SineWave(time/13.0)*10)
			);

		auto mm_identity = ModelMatrixf();
		auto mm_rotation = ModelMatrixf::RotationZ(FullCircles(time / 7.0));

		Uniform<Mat4f>* model_matrix = nullptr;

		GLuint drawing_fan = fan_index;
		auto drawing_driver =
			[
				&model_matrix,
				&mm_identity,
				&mm_rotation,
				&drawing_fan
			](GLuint phase) -> bool
			{
				if(phase == drawing_fan)
					model_matrix->Set(mm_rotation);
				else model_matrix->Set(mm_identity);
				return true;
			};

		// render the light mask
		light_fbo.Bind(Framebuffer::Target::Draw);

		gl.Clear().ColorBuffer().DepthBuffer();

		mask_vao.Bind();
		mask_prog.Use();
		mask_prog.camera_matrix.Set(camera);
		model_matrix = &mask_prog.model_matrix;

		meshes.Draw(drawing_driver);

		// render the final image
		DefaultFramebuffer().Bind(Framebuffer::Target::Draw);

		gl.Clear().ColorBuffer().DepthBuffer();

		draw_vao.Bind();
		draw_prog.Use();
		Vec4f lsp = projection * camera * Vec4f(light_position, 1.0);
		draw_prog.light_screen_pos = lsp.xyz()/lsp.w();
		draw_prog.camera_matrix.Set(camera);
		model_matrix = &draw_prog.model_matrix;

		meshes.Draw(drawing_driver);
	}
开发者ID:AdamSimpson,项目名称:oglplus,代码行数:57,代码来源:030_light_rays.cpp

示例3: Draw

		void Renderer::Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const
		{
			shader.Bind();
			ib.Bind();
			va.Bind();
			GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, 0));
		}
开发者ID:adamk33n3r,项目名称:Icarus,代码行数:7,代码来源:Renderer.cpp

示例4: Render

	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.0 - SineWave(time / 6.0) * 2.0,
				FullCircles(time * 0.4),
				Degrees(SineWave(time / 30.0) * 90)
			)
		);

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationZ(FullCircles(time * 0.1))
		);

		cube.Bind();
		gl.CullFace(Face::Front);
		cube_instr.Draw(cube_indices);
		gl.CullFace(Face::Back);
		cube_instr.Draw(cube_indices);
	}
开发者ID:xdray,项目名称:oglplus,代码行数:25,代码来源:019_honeycomb_cube.cpp

示例5: VAOForProgram

	VertexArray VAOForProgram(const ProgramOps& prog) const
	{
		VertexArray vao;
		vao.Bind();
		prog.Use();
		size_t i=0, n = _names.size();
		while(i != n)
		{
			if(_npvs[i] != 0)
			{
				try
				{
					_vbos[i].Bind(Buffer::Target::Array);
					VertexAttribArray attr(prog, _names[i]);
					attr.Setup(_npvs[i], DataType::Float);
					attr.Enable();
				}
				catch(Error&){ }
			}
			++i;
		}
		assert((i+1) == _npvs.size());
		if(_npvs[i] != 0)
		{
			assert((i+1) == _vbos.size());
			_vbos[i].Bind(Buffer::Target::ElementArray);
		}
		return std::move(vao);
	}
开发者ID:detunized,项目名称:oglplus,代码行数:29,代码来源:wrapper.hpp

示例6: attr

    Shape(const Program& prog, const ShapeBuilder& builder)
      : make_shape(builder)
      , shape_instr(make_shape.Instructions())
      , shape_indices(make_shape.Indices())
      , vbos(4) {
        // bind the VAO for the shape
        vao.Bind();

        typename ShapeBuilder::VertexAttribs vert_attr_info;
        const GLchar* vert_attr_name[] = {
          "Position", "Normal", "Tangent", "TexCoord"};
        for(int va = 0; va != 4; ++va) {
            const GLchar* name = vert_attr_name[va];
            std::vector<GLfloat> data;
            auto getter = vert_attr_info.VertexAttribGetter(data, name);
            if(getter != nullptr)
                try {
                    // bind the VBO for the vertex attribute
                    vbos[va].Bind(Buffer::Target::Array);
                    GLuint npv = getter(make_shape, data);
                    // upload the data
                    Buffer::Data(Buffer::Target::Array, data);
                    // setup the vertex attribs array
                    VertexArrayAttrib attr(prog, name);
                    attr.Setup<GLfloat>(npv);
                    attr.Enable();
                } catch(Error&) {
                }
        }
    }
开发者ID:matus-chochlik,项目名称:oglplus,代码行数:30,代码来源:029_flares.cpp

示例7: Update

	void Update(void)
	{
		gl.Viewport(size, size);

		fbo.Bind(Framebuffer::Target::Draw);
		Framebuffer::AttachColorTexture(
			Framebuffer::Target::Draw,
			1,
			holder.CurrentHeightMap(),
			0
		);
		Context::ColorBuffer draw_buffs[2] = {
			FramebufferColorAttachment::_0,
			FramebufferColorAttachment::_1
		};
		gl.DrawBuffers(draw_buffs);

		prog.Use();
		prog.tex_1.Set(holder.TexUnit1());
		prog.tex_2.Set(holder.TexUnit2());
		prog.new_drop.Set(std::rand()%size, std::rand()%size);

		vao.Bind();
		gl.DrawArrays(PrimitiveType::Points, 0, 1);

		holder.Swap();
	}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例8: Render

	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		Uniform<Mat4f>(prog, "cameraMatrix").Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.0 + std::sin(time)*1.5,
				FullCircles(time * 0.5),
				Degrees(std::sin(time * 0.5) * 70)
			)
		);

		Uniform<Mat4f>(prog, "modelMatrix").Set(
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time * 0.4)
			)
		);
		Uniform<Vec3f>(prog, "lightPos").Set(Vec3f(1.0f, 2.0f, 3.0f*std::sin(time * 2.9)));

		vao.Bind();
		// This is not very effective
		shape.Instructions().Draw(shape.Indices());
	}
开发者ID:detunized,项目名称:oglplus,代码行数:25,代码来源:test03.cpp

示例9: attr

	Grid(const Program& prog, float quality)
	 : make_grid(1.0, 16 + quality*quality*64)
	 , grid_instr(make_grid.Instructions())
	 , grid_indices(make_grid.Indices())
	{
		// bind the VAO for the shape
		vao.Bind();

		std::vector<GLfloat> data;
		// bind the VBO for the positions
		positions.Bind(Buffer::Target::Array);
		GLuint n_per_vertex = make_grid.Positions(data);
		// upload the data
		Buffer::Data(Buffer::Target::Array, data);
		// setup the vertex attribs array
		VertexArrayAttrib attr(prog, "Position");
		attr.Setup<GLfloat>(n_per_vertex);
		attr.Enable();

		// bind the VBO for the indices
		indices.Bind(Buffer::Target::ElementArray);
		// upload them
		Buffer::Data(Buffer::Target::ElementArray, grid_indices);
		// clear the indexs buffer
		grid_indices.clear();
	}
开发者ID:JanChou,项目名称:oglplus,代码行数:26,代码来源:028_ripples.cpp

示例10: Render

	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.5,
				Degrees(time * 35),
				Degrees(SineWave(time / 20.0) * 60)
			)
		);
		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationX(FullCircles(time * 0.25))
		);

		torus.Bind();
		gl.PolygonMode(PolygonMode::Line);
		gl.CullFace(Face::Front);
		torus_instr.Draw(torus_indices);
		//
		gl.PolygonMode(PolygonMode::Fill);
		gl.CullFace(Face::Back);
		torus_instr.Draw(torus_indices);
	}
开发者ID:BrainlessLabsInc,项目名称:oglplus,代码行数:27,代码来源:016_noise_torus.cpp

示例11: Render

	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.5 - SineWave(time / 16.0) * 2.0,
				FullCircles(time / 12.0),
				Degrees(SineWave(time / 30.0) * 90)
			)
		);

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time / 10.0)
			)
		);

		shape.Bind();
		shape_instr.Draw(shape_indices);
	}
开发者ID:BrainlessLabsInc,项目名称:oglplus,代码行数:25,代码来源:020_icosphere.cpp

示例12: vert_attr

	RectangleExample(void)
	{
		prog <<	"#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);"
			"}"_glsl_vs;

		prog <<	"#version 330\n"
			"in vec3 vertColor;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	fragColor = vec4(vertColor, 1.0);"
			"}"_glsl_fs;

		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(2, DataType::Float);
		vert_attr.Enable();

		GLfloat rectangle_colors[12] = {
			0.0f, 1.0f, 1.0f,
			1.0f, 0.0f, 1.0f,
			1.0f, 1.0f, 0.0f,
			0.0f, 0.0f, 0.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(3, DataType::Float);
		color_attr.Enable();
		//

		gl.ClearDepth(1.0f);
	}
开发者ID:detunized,项目名称:oglplus,代码行数:59,代码来源:002_shader_lit.cpp

示例13: Draw

	void Draw(double time, double fade)
	{
		// Shadow map
		shadows_fbo.Bind(FramebufferTarget::Draw);
		gl.Viewport(shadow_size, shadow_size);
		gl.Clear().DepthBuffer();

		auto light = CamMatrixf::Orbiting(
			Vec3f(0, side*0.25, 0),
			side*1.5,
			Degrees(-time * 27),
			Degrees(SineWave(time / 19.0)*25  + 45)
		);

		shadow_prog.fade.Set(fade);
		shadow_prog.camera_matrix.Set(light);

		shadow_prog.Use();
		shadow_vao.Bind();
		gl.Enable(Capability::PolygonOffsetFill);
		cube.Draw(side*side);
		gl.Disable(Capability::PolygonOffsetFill);
		gl.Finish();

		// On-screen
		default_fb.Bind(Framebuffer::Target::Draw);
		gl.Viewport(width, height);
		gl.Clear().ColorBuffer().DepthBuffer();

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			side*1.1,
			Degrees(time * 19),
			Degrees(SineWave(time / 20.0) * 39 + 50)
		);

		display_prog.fade.Set(fade);
		display_prog.light_pos.Set(light.Position());
		display_prog.camera_pos.Set(camera.Position());
		display_prog.light_matrix.Set(light);
		display_prog.camera_matrix.Set(camera);

		display_prog.Use();
		display_vao.Bind();
		cube.Draw(side*side);
	}
开发者ID:Extrunder,项目名称:oglplus,代码行数:46,代码来源:030_pin_display.cpp

示例14: Render

	void Render(double /*time*/)
	{
		gl.Clear().ColorBuffer();
		// draw the lines between control points
		color = Vec3f(0.9f, 0.9f, 0.2f);
		control.Bind();
		gl.DrawArrays(PrimitiveType::LineStrip, 0, ctrl_n);
		// draw the curve
		color = Vec3f(0.1f, 0.1f, 0.1f);
		curve.Bind();
		gl.DrawArrays(PrimitiveType::LineStrip, 0, curve_n);
		// draw the control points
		color = Vec3f(0.9f, 0.0f, 0.0f);
		control.Bind();
		gl.PointSize(8.0);
		gl.DrawArrays(PrimitiveType::Points, 0, ctrl_n);
		gl.PointSize(1.0);
	}
开发者ID:BrainlessLabsInc,项目名称:oglplus,代码行数:18,代码来源:007_cubic_bezier.cpp

示例15: Render

	void Render(const Mat4f& model)
	{
		prog.Use();
		model_matrix.Set(model);
		// bind the VAO
		sphere.Bind();
		// use the instructions to draw the sphere
		// (this basically calls glDrawArrays* or glDrawElements*)
		sphere_instr.Draw(sphere_indices);
	}
开发者ID:xubingyue,项目名称:oglplus,代码行数:10,代码来源:019_helium.cpp


注:本文中的VertexArray::Bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。