本文整理汇总了C++中Texture2D::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ Texture2D::Bind方法的具体用法?C++ Texture2D::Bind怎么用?C++ Texture2D::Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D::Bind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawSprite
void SpriteRenderer::DrawSprite(Texture2D &texture, glm::vec2 position, glm::vec2 size, GLfloat rotate, glm::vec3 color)
{
// Prepare transformations
this->shader.Use();
glm::mat4 model;
model = glm::translate(model, glm::vec3(position, 0.0f)); // First translate (transformations are: scale happens first, then rotation and then finall translation happens; reversed order)
model = glm::translate(model, glm::vec3(0.5f * size.x, 0.5f * size.y, 0.0f)); // Move origin of rotation to center of quad
model = glm::rotate(model, rotate, glm::vec3(0.0f, 0.0f, 1.0f)); // Then rotate
model = glm::translate(model, glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f)); // Move origin back
model = glm::scale(model, glm::vec3(size, 1.0f)); // Last scale
this->shader.SetMatrix4("model", model);
// Render textured quad
this->shader.SetVector3f("spriteColor", color);
glActiveTexture(GL_TEXTURE0);
texture.Bind();
glBindVertexArray(this->quadVAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Ibo);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (GLvoid*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
示例2: Draw
//--------------------------------------------------------------------------
void PostProcessor::Draw( const Texture2D& _colorTex,
float _toneExposure,
const RenderTarget& _renderTarget)
{
glUseProgram(toneMapping.program.id);
glProgramUniform1f(toneMapping.program.id, toneMapping.exposureVar, _toneExposure);
_colorTex.Bind(toneMapping.colorTexUnit);
_renderTarget.Draw();
}
示例3: DrawSprite
void SpriteRenderer::DrawSprite(Texture2D& texture, glm::vec2 position, glm::vec2 size /*= glm::vec2(10, 10)*/, GLfloat rotate /*= 0.0f*/, glm::vec3 color /*= glm::vec3(1.0f)*/)
{
this->shader.Use();
glm::mat4 model;
model = glm::translate(model, glm::vec3(position, 0.0f));
model = glm::translate(model, glm::vec3(0.5f * size.x, 0.5f * size.y, 0.0f));
model = glm::rotate(model, rotate, glm::vec3(0.0f, 0.0f, 1.0f));
model = glm::translate(model, glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f));
model = glm::scale(model, glm::vec3(size, 1.0f));
this->shader.SetMatrix4("model", model);
this->shader.SetVector3f("spriteColor", color);
glActiveTexture(GL_TEXTURE0);
texture.Bind();
glBindVertexArray(this->quadVAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}
示例4: draw
void SpriteRenderer::draw(
glm::vec2 position,
glm::vec2 size,
const Texture2D& texture,
const Camera& camera
) const
{
ResourceManager::GetShader("sprite_texture")->use();
glm::mat4 model;
// При расстановке объектов сдвигаем начало координат в центр экрана. Чтоб герой всегда был по центру.
model = glm::translate(model, glm::vec3(position.x + screenWidth_ / 2, position.y + screenHeight_ / 2, 0.0f));
model = glm::scale(model, glm::vec3(size, 1.0f));
glm::mat4 view;
camera.getView(view);
ResourceManager::GetShader("sprite_texture")->setUniform("view", view);
ResourceManager::GetShader("sprite_texture")->setUniform("model", model);
glBindVertexArray(VAO_);
texture.Bind();
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}