本文整理汇总了C++中Matrix3f::asArray方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3f::asArray方法的具体用法?C++ Matrix3f::asArray怎么用?C++ Matrix3f::asArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix3f
的用法示例。
在下文中一共展示了Matrix3f::asArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
//==============================================================================
// Draws Text On Screen Where startPos is Top-Left Corner of First Letter
//==============================================================================
void Text::draw(std::string text, Vector2f startPos, float width, Matrix3f transform) {
if(text.size() == 0)
return;
float height = width * 1.5f;
Vector2f curr(startPos);
Vector2f v1, v2, v3, v4;
Vector2f t1, t2, t3, t4;
std::vector<GLfloat> positions;
std::vector<GLfloat> texCoords;
for(int i = 0; i < text.size(); i++) {
int iChar = (int) text[i];
if(iChar > 32 && iChar < 127) {
Vector2i letterCoord = getLetterCoords(iChar);
v1 = Vector2f(curr.x, curr.y);
t1 = Vector2f(letterCoord.x * letterWidth / textureWidth, letterCoord.y * letterHeight / textureHeight);
v2 = Vector2f(curr.x, curr.y + height);
t2 = Vector2f(letterCoord.x * letterWidth / textureWidth, (letterCoord.y + 1) * letterHeight / textureHeight);
v3 = Vector2f(curr.x + width, curr.y + height);
t3 = Vector2f((letterCoord.x + 1) * letterWidth / textureWidth, (letterCoord.y + 1) * letterHeight / textureHeight);
v4 = Vector2f(curr.x + width, curr.y);
t4 = Vector2f((letterCoord.x + 1) * letterWidth / textureWidth, letterCoord.y * letterHeight / textureHeight);
v1.pushOn(&positions);
t1.pushOn(&texCoords);
v2.pushOn(&positions);
t2.pushOn(&texCoords);
v3.pushOn(&positions);
t3.pushOn(&texCoords);
v1.pushOn(&positions);
t1.pushOn(&texCoords);
v3.pushOn(&positions);
t3.pushOn(&texCoords);
v4.pushOn(&positions);
t4.pushOn(&texCoords);
curr.x += width;
} else if(iChar == 32) {
// SPACE
curr.x += width;
} else if(iChar == 9) {
// TAB
curr.x += (width * 4);
} else if(iChar == 10) {
// NEW LINE
curr.x = startPos.x;
curr.y += height;
} else {
Utility::printToOutput("Error -- Unsupported Character.");
exit(-1);
}
}
GLfloat arrTransform[9];
transform.asArray(arrTransform);
glBindVertexArray(VAO);
glUseProgram(shaderProgram);
glBindTexture(GL_TEXTURE_2D, textureHandle);
glUniform1i(sTextureHandle, 0);
glUniformMatrix3fv(sTransformHandle, 1, GL_TRUE, arrTransform);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, positions.size() * sizeof(GLfloat), &(positions[0]), GL_STATIC_DRAW);
glEnableVertexAttribArray(sPositionHandle);
glVertexAttribPointer(sPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, vboTexCoordHandle);
glBufferData(GL_ARRAY_BUFFER, texCoords.size() * sizeof(GLfloat), &(texCoords[0]), GL_STATIC_DRAW);
glEnableVertexAttribArray(sTexCoordHandle);
glVertexAttribPointer(sTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawArrays(GL_TRIANGLES, 0, (int)positions.size() / 2);
glUseProgram(0);
glBindVertexArray(0);
//.........这里部分代码省略.........