void TinyGLRenderer::drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft, const Math::Vector3d &topRight, const Math::Vector3d &bottomRight, Texture *texture) { TinyGLTexture *glTexture = static_cast<TinyGLTexture *>(texture); const float w = glTexture->width / (float)glTexture->internalWidth; const float h = glTexture->height / (float)glTexture->internalHeight; tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA); tglEnable(TGL_BLEND); tglDepthMask(TGL_FALSE); tglBindTexture(TGL_TEXTURE_2D, glTexture->id); tglBegin(TGL_TRIANGLE_STRIP); tglTexCoord2f(0, 0); tglVertex3f(-topLeft.x(), topLeft.y(), topLeft.z()); tglTexCoord2f(0, h); tglVertex3f(-bottomLeft.x(), bottomLeft.y(), bottomLeft.z()); tglTexCoord2f(w, 0); tglVertex3f(-topRight.x(), topRight.y(), topRight.z()); tglTexCoord2f(w, h); tglVertex3f(-bottomRight.x(), bottomRight.y(), bottomRight.z()); tglEnd(); tglDisable(TGL_BLEND); tglDepthMask(TGL_TRUE); }
void TinyGLRenderer::drawFace(uint face, Texture *texture) { TinyGLTexture *glTexture = static_cast<TinyGLTexture *>(texture); tglBindTexture(TGL_TEXTURE_2D, glTexture->id); tglBegin(TGL_TRIANGLE_STRIP); for (uint i = 0; i < 4; i++) { tglTexCoord2f(cubeVertices[5 * (4 * face + i) + 0], cubeVertices[5 * (4 * face + i) + 1]); tglVertex3f(cubeVertices[5 * (4 * face + i) + 2], cubeVertices[5 * (4 * face + i) + 3], cubeVertices[5 * (4 * face + i) + 4]); } tglEnd(); }
void GfxTinyGL::drawSprite(const Sprite *sprite) { tglMatrixMode(TGL_TEXTURE); tglLoadIdentity(); tglMatrixMode(TGL_MODELVIEW); tglPushMatrix(); tglTranslatef(sprite->_pos.x(), sprite->_pos.y(), sprite->_pos.z()); TGLfloat modelview[16]; tglGetFloatv(TGL_MODELVIEW_MATRIX, modelview); // We want screen-aligned sprites so reset the rotation part of the matrix. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { modelview[i * 4 + j] = 1.0f; } else { modelview[i * 4 + j] = 0.0f; } } } tglLoadMatrixf(modelview); tglDisable(TGL_LIGHTING); tglBegin(TGL_POLYGON); tglTexCoord2f(0.0f, 0.0f); tglVertex3f(sprite->_width / 2, sprite->_height, 0.0f); tglTexCoord2f(0.0f, 1.0f); tglVertex3f(sprite->_width / 2, 0.0f, 0.0f); tglTexCoord2f(1.0f, 1.0f); tglVertex3f(-sprite->_width / 2, 0.0f, 0.0f); tglTexCoord2f(1.0f, 0.0f); tglVertex3f(-sprite->_width / 2, sprite->_height, 0.0f); tglEnd(); tglEnable(TGL_LIGHTING); tglPopMatrix(); }
void TinyGLRenderer::drawFace(uint face, Texture *texture) { TinyGLTexture *glTexture = static_cast<TinyGLTexture *>(texture); // Used fragment of the texture const float w = glTexture->width / (float)glTexture->internalWidth; const float h = glTexture->height / (float)glTexture->internalHeight; tglBindTexture(TGL_TEXTURE_2D, glTexture->id); tglBegin(TGL_TRIANGLE_STRIP); for (uint i = 0; i < 4; i++) { tglTexCoord2f(w * faceTextureCoords[2 * i + 0], h * faceTextureCoords[2 * i + 1]); tglVertex3f(cubeFacesVertices[face][3 * i + 0], cubeFacesVertices[face][3 * i + 1], cubeFacesVertices[face][3 * i + 2]); } tglEnd(); }