本文整理汇总了C++中SpriteSheet::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ SpriteSheet::Bind方法的具体用法?C++ SpriteSheet::Bind怎么用?C++ SpriteSheet::Bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpriteSheet
的用法示例。
在下文中一共展示了SpriteSheet::Bind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawSprite
void AnimatedSpriteRenderer::DrawSprite(SpriteSheet &sheet, glm::vec2 position, glm::vec2 size, GLfloat rotate, glm::vec3 color, int frame)
{
// 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);
GLuint VBO;
GLfloat vertices[] = {
// Pos // Tex
0.0f, 1.0f, sheet.minu[frame], sheet.maxv[frame],
1.0f, 0.0f, sheet.maxu[frame], sheet.minv[frame],
0.0f, 0.0f, sheet.minu[frame], sheet.minv[frame],
0.0f, 1.0f, sheet.minu[frame], sheet.maxv[frame],
1.0f, 1.0f, sheet.maxu[frame], sheet.maxv[frame],
1.0f, 0.0f, sheet.maxu[frame], sheet.minv[frame]
};
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
sheet.Bind();
glBindVertexArray(this->quadVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)0);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}