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


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

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


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

示例1: drawCube

void drawCube(GLint program, VertexArray &VAO, VertexBuffer &VBO, const glm::vec3 & cubePosition)
{
	GLint locationModel = glGetUniformLocation(program, "model");

	// model input
	glm::mat4 model;
	model = glm::translate(model, glm::vec3(cubePosition));
	glUniformMatrix4fv(locationModel, 1, GL_FALSE, glm::value_ptr(model));

	VAO.bind();

	VBO.renderBuffer(GL_TRIANGLES, 0, 36);

	VAO.unbind();
}
开发者ID:nguyenchiemminhvu,项目名称:GLFW-projects,代码行数:15,代码来源:main.cpp

示例2: init

void init(Renderer &gfx, Context &ctx)
{
	// Create the vertex buffer that will be updated with vertices during runtime
	vbo.create(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW);
	vbo.bind();
	vbo.bufferData(sizeof(float) * 6 * 7, NULL);
	vbo.unbind();

	// Create VAO to hold attribute bindings
	vao.create();
	vao.bind();
	vbo.bind();
	shader.setAttributefv("position", 3, 7, 0);
	shader.setAttributefv("color", 4, 7, 3);
	vbo.unbind();
	vao.unbind();
}
开发者ID:lightbits,项目名称:glterrain,代码行数:17,代码来源:app.cpp

示例3: main

int main() {
	Graphics::Window window("title", Vector2<int>(1800, 960));

	FileSystem fs;
   
	this_thread::sleep_for(std::chrono::seconds(1));
 	auto cube = MeshLoader::loadOBJ(&fs.getFile("scene/monkey.obj"));
  
	Transformation camera;
	Projection projection(0.01f, 1000.0f, 45, window.getAspect());
	Transformation model;
	Transformation light_t;
	   
	camera.setPosition({0 , 0 , .7f});

	GLenum err;
	// TEST 
	// cbuffer is deleted after being passed as rvalue
	auto tex = TextureLoader::loadTexture(fs.getFile("textures/box.bmp"));

	if (tex == nullptr || cube == nullptr) {
		return 1;
	}

	GLuint vbo = 0; 
	GLuint sampler = 0; 

	cube->bind(); 

	Shader vert(fs.getFile("shaders/shader.vert"), GL_VERTEX_SHADER);
	Shader frag(fs.getFile("shaders/shader.frag"), GL_FRAGMENT_SHADER);
	if ((err = glGetError()) != GL_NO_ERROR)
		return err;
	Program program;
	program.attachShader(vert);
	program.attachShader(frag);
	program.link();
	program.use();

	VertexArray vao;
	vao.bind(); 

	vao.setVertexAttribute(program, "in_normal", cube->getObjects().at(0).normalSize(), GL_FLOAT, GL_FALSE, cube->getObjects().at(0).stride(), cube->getObjects().at(0).normalOffset());
	vao.setVertexAttribute(program, "position", cube->getObjects().at(0).vertexSize(), GL_FLOAT, GL_FALSE, cube->getObjects().at(0).stride(), cube->getObjects().at(0).vertexOffset());
	vao.setVertexAttribute(program, "in_tex", cube->getObjects().at(0).texCoordSize(), GL_FLOAT, GL_FALSE, cube->getObjects().at(0).stride(), cube->getObjects().at(0).texCoordOffset());

	vao.unbind(); 

	program.setUniform("world_pos", Vector3<float>(.5, 0, 0));

	glActiveTexture(GL_TEXTURE0);
	tex->bind();
	  
	LightPoint point;
	point.position = { 2, 0, 0 };
	point.color = { 1, 1, 1 };
	point.intensity = 0.4f;
	point.attenuation = 10;

	light_t.setPosition(Vector3<float>(2, 1, 0));

	Lighting lights;

	LightPoint& light = lights.attachLight(point);

	lights.setAmbient(Vector3<float>(1.0f, 1.0f, 1.0f));

	float pos = 0;
	Vector3<float> rotation(0);

	while (false) {
		window.startFrame(); 
		vao.bind();
		//camera.rotate({ 0, 0, 0.01f }); 

		//window.getMouse().getMousePosition<float>(&light.position.x, &light.position.y); 
		light_t.setPosition(light.position);  
		model.setScale({ 0.1f, 0.1f, 0.1f });
		model.setPosition({ 0, -0.5f, 0 });
		std::this_thread::sleep_for(std::chrono::milliseconds(16));
		program.setUniform("model", model.getMatrix());
		program.setUniform("view", camera.getMatrix()); 
		program.setUniform("projection", projection.getPerspective());
		lights.bindLights(program);
		program.setUniform("normal_matrix", model.getNormalMatrix());
		cube->bind();
		 

		for (const auto& obj : cube->getObjects()){
			program.setUniform("has_normal", obj.hasNormals());
			program.setUniform("has_tex_coord", obj.hasTexCoord());
			glDrawElements(obj.getMode(), obj.size, GL_UNSIGNED_INT, obj.p_start); 
		}

		vao.unbind();

		if (window.getKeyboard().isKeyDown(KEY::KEY_W) != KEY_PRESSED::RELEASED)
			rotation.x += 0.1f;
		if (window.getKeyboard().isKeyDown(KEY::KEY_D) != KEY_PRESSED::RELEASED)
			rotation.y += 0.1f;
//.........这里部分代码省略.........
开发者ID:wackoisgod,项目名称:Protheus,代码行数:101,代码来源:LearnOGL.cpp

示例4: main

int main() {
	Graphics::Window window("scene", { 800, 600 });
	
	Util::FileSystem fs; 
	fs.setRootDir("");

	auto scene = MeshLoader::loadOBJ(&fs.getFile("scene/scene.obj"));
	auto tex = TextureLoader::loadTexture(&fs.getFile("scene/Wall.bmp"));

	Shader vert(fs.getFile("shaders/shader.vert"), GL_VERTEX_SHADER);
	Shader frag(fs.getFile("shaders/shader.frag"), GL_FRAGMENT_SHADER);

	GLuint err = 0;
	if ((err = glGetError()) != GL_NO_ERROR)
		return err;
	Program program;

	program.attachShader(vert);
	program.attachShader(frag);
	program.link();
	program.use();

	// Get a good error if this hasn't been bound.
	scene->bind();

	VertexArray vao;
	vao.bind();

	vao.setVertexAttribute(program, "in_normal", scene->normalSize(), GL_FLOAT, GL_FALSE, scene->stride(), scene->normalOffset());
	vao.setVertexAttribute(program, "position", scene->vertexSize(), GL_FLOAT, GL_FALSE, scene->stride(), scene->vertexOffset());
	vao.setVertexAttribute(program, "in_tex", scene->texCoordSize(), GL_FLOAT, GL_FALSE, scene->stride(), scene->texCoordOffset());

	vao.unbind();

	program.setUniform("has_normal", scene->hasNormals());
	program.setUniform("has_tex_coord", scene->hasTexCoord());
	program.setUniform("world_pos", Vector3<float>(.5, 0, 0));

	
	glActiveTexture(GL_TEXTURE0);
	tex->bind();

	LightPoint point;
	point.position = { 2, 0, 0 };
	point.color = { 1, 1, 1 };
	point.intensity = 10;
	point.attenuation = 10;
	  
	Lighting lights;

	LightPoint& light = lights.attachLight(point); 
	lights.setAmbient(Vector3<float>(1.0f, 1.0f, 1.0f));


	while (true /*window.isExitRequested()*/) {
		window.startFrame();

		for (const auto& obj : scene->getObjects()) {
			glDrawElements(scene->getMode(), obj.size, GL_UNSIGNED_INT, obj.p_start);
		}

		window.endFrame();
	}
	 
}
开发者ID:Allowed,项目名称:Protheus,代码行数:65,代码来源:scenetestcpp.cpp


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