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


C++ Matrix3f::asArray方法代码示例

本文整理汇总了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);
//.........这里部分代码省略.........
开发者ID:BarstoolStudios,项目名称:Settlement,代码行数:101,代码来源:Text.cpp


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