示例#1
0
// Draw quad with repeated textures
void _Graphics::DrawTile(const glm::vec2 &Start, const glm::vec2 &End, float Z, const _Texture *Texture) {
	if(LastAttribLevel != 2)
		throw std::runtime_error(std::string(__FUNCTION__) + " - LastAttribLevel mismatch");

	SetTextureID(Texture->ID);
	SetColor(COLOR_WHITE);

	// Get textureID and properties
	float Width = End.x - Start.x;
	float Height = End.y - Start.y;

	glm::mat4 ModelTransform;
	ModelTransform = glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, Z));
	glUniformMatrix4fv(LastProgram->ModelTransformID, 1, GL_FALSE, glm::value_ptr(ModelTransform));

	// Vertex data for quad
	float Vertices[] = {
		Start.x, End.y,   0.0f,  Height,
		End.x,   End.y,   Width, Height,
		Start.x, Start.y, 0.0f,  0.0f,
		End.x,   Start.y, Width, 0.0f,
	};

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, &Vertices[0]);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, &Vertices[2]);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
示例#2
0
// Draw image in screen space
void _Graphics::DrawImage(const _Bounds &Bounds, const _Texture *Texture, bool Stretch) {
	SetTextureID(Texture->ID);

	// Get s and t
	float S, T;
	if(Stretch) {
		S = T = 1;
	}
	else {
		S = (Bounds.End.x - Bounds.Start.x) / (float)(Texture->Size.x);
		T = (Bounds.End.y - Bounds.Start.y) / (float)(Texture->Size.y);
	}

	// Vertex data for quad
	float Vertices[] = {
		Bounds.End.x,   Bounds.Start.y, S,    0.0f,
		Bounds.Start.x, Bounds.Start.y, 0.0f, 0.0f,
		Bounds.End.x,   Bounds.End.y,   S,    T,
		Bounds.Start.x, Bounds.End.y,   0.0f, T,
	};
	if(LastAttribLevel != 2)
		throw std::runtime_error("bad");

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, &Vertices[0]);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, &Vertices[2]);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
示例#3
0
//======================================================================
//======================================================================
NvUIGraphic::NvUIGraphic(uint32_t texId, bool alpha,
                            uint32_t srcw, uint32_t srch,
                            float dstw/*==0*/, float dsth/*==0*/)
{
    StaticInit();
    PrivateInit();
    SetTextureID(texId, alpha, srcw, srch);
    if (dstw!=0)
        SetDimensions(dstw, dsth);
}
示例#4
0
// Draw image from a texture atlas
void _Graphics::DrawAtlas(const _Bounds &Bounds, const _Texture *Texture, const glm::vec4 &TextureCoords) {
	SetTextureID(Texture->ID);

	// Vertex data for quad
	float Vertices[] = {
		Bounds.End.x,   Bounds.Start.y, TextureCoords[2], TextureCoords[1],
		Bounds.Start.x, Bounds.Start.y, TextureCoords[0], TextureCoords[1],
		Bounds.End.x,   Bounds.End.y,   TextureCoords[2], TextureCoords[3],
		Bounds.Start.x, Bounds.End.y,   TextureCoords[0], TextureCoords[3],
	};
	if(LastAttribLevel != 2)
		throw std::runtime_error("bad");

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, &Vertices[0]);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, &Vertices[2]);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
示例#5
0
// Draw 3d sprite
void _Graphics::DrawSprite(const glm::vec3 &Position, const _Texture *Texture, float Rotation, const glm::vec2 Scale) {
	if(LastAttribLevel != 2)
		throw std::runtime_error(std::string(__FUNCTION__) + " - LastAttribLevel mismatch");

	SetTextureID(Texture->ID);

	Rotation = glm::radians(Rotation);

	glm::mat4 ModelTransform;
	ModelTransform = glm::translate(glm::mat4(1.0f), Position);
	if(Rotation != 0.0f)
		ModelTransform = glm::rotate(ModelTransform, Rotation, glm::vec3(0, 0, 1));

	ModelTransform = glm::scale(ModelTransform, glm::vec3(Scale, 0.0f));

	glUniformMatrix4fv(LastProgram->ModelTransformID, 1, GL_FALSE, glm::value_ptr(ModelTransform));

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
示例#6
0
// Draw 3d wall
void _Graphics::DrawCube(const glm::vec3 &Start, const glm::vec3 &Scale, const _Texture *Texture) {
	if(LastAttribLevel != 3)
		throw std::runtime_error(std::string(__FUNCTION__) + " - LastAttribLevel mismatch");

	SetTextureID(Texture->ID);

	glm::mat4 ModelTransform;
	ModelTransform = glm::translate(glm::mat4(1.0f), Start);
	ModelTransform = glm::scale(ModelTransform, Scale);

	glUniformMatrix4fv(LastProgram->ModelTransformID, 1, GL_FALSE, glm::value_ptr(ModelTransform));

	// Change texture
	glMatrixMode(GL_TEXTURE);

	// Draw top
	glScalef(Scale.x, Scale.y, 1);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glLoadIdentity();

	// Draw front
	glScalef(Scale.x, Scale.z, 1);
	glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
	glLoadIdentity();

	// Draw left
	glScalef(Scale.y, Scale.z, 1);
	glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
	glLoadIdentity();

	// Draw back
	glScalef(Scale.x, Scale.z, 1);
	glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
	glLoadIdentity();

	// Draw right
	glScalef(Scale.y, Scale.z, 1);
	glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
	glLoadIdentity();

	glMatrixMode(GL_MODELVIEW);
}