// Zoom into the cube inline void scene1(float scene_time) { tglClear(TGL_COLOR_BUFFER_BIT); float min_zoom = -10; float max_zoom = -2.5; float zoom = min_zoom + (max_zoom-min_zoom) * (float)scene_time/timeline[scene]; tglMatrixMode(TGL_MODELVIEW); tglLoadIdentity(); tglTranslatef(0, 0, zoom); tglBegin(TGL_LINES); for(int p=0; p<8; ++p) { tglVertex3fv(cube[cubestrip1[p]]); } tglEnd(); tglBegin(TGL_LINES); for(int p=0; p<8; ++p) { tglVertex3fv(cube[cubestrip2[p]]); } tglEnd(); tglSwap(); delay(50); }
// Spinning Cube! inline void scene2(float scene_time) { int i = scene_time / 25; tglClear(TGL_COLOR_BUFFER_BIT); float zoom = 0; if(scene_time > 5000) zoom = 0.5*sin((float)(i-20)/10.0); float rot_speed = 1.0; if(scene_time > 12000) rot_speed += (float)(scene_time - 12000) / 1500.0; tglMatrixMode(TGL_MODELVIEW); tglLoadIdentity(); tglTranslatef(0, 0, -2.5+zoom); tglRotatef((float)(i % 360) * rot_speed, 0, 1, 0); tglRotatef((float)(i % 360) * rot_speed, 1, 1, 0); tglBegin(TGL_LINES); for(int p=0; p<8; ++p) { tglVertex3fv(cube[cubestrip1[p]]); } tglEnd(); tglBegin(TGL_LINES); for(int p=0; p<8; ++p) { tglVertex3fv(cube[cubestrip2[p]]); } tglEnd(); tglSwap(); }
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::drawModelFace(const MeshFace *face, float *vertices, float *vertNormals, float *textureVerts) { tglNormal3fv(const_cast<float *>(face->_normal._coords)); tglBegin(TGL_POLYGON); for (int i = 0; i < face->_numVertices; i++) { tglNormal3fv(vertNormals + 3 * face->_vertices[i]); if (face->_texVertices) tglTexCoord2fv(textureVerts + 2 * face->_texVertices[i]); tglVertex3fv(vertices + 3 * face->_vertices[i]); } tglEnd(); }
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(); }
void TinyGLRenderer::drawRect2D(const Common::Rect &rect, uint32 color) { uint8 a, r, g, b; Graphics::colorToARGB< Graphics::ColorMasks<8888> >(color, a, r, g, b); tglDisable(TGL_TEXTURE_2D); tglColor4f(r / 255.0, g / 255.0, b / 255.0, a / 255.0); if (a != 255) { tglEnable(TGL_BLEND); tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA); } tglBegin(TGL_TRIANGLE_STRIP); tglVertex3f(rect.left, rect.bottom, 0.0f); tglVertex3f(rect.right, rect.bottom, 0.0f); tglVertex3f(rect.left, rect.top, 0.0f); tglVertex3f(rect.right, rect.top, 0.0f); tglEnd(); tglDisable(TGL_BLEND); }
void GfxTinyGL::drawShadowPlanes() { tglEnable(TGL_SHADOW_MASK_MODE); if (!_currentShadowArray->shadowMask) { _currentShadowArray->shadowMask = new byte[_screenWidth * _screenHeight]; _currentShadowArray->shadowMaskSize = _screenWidth * _screenHeight; } memset(_currentShadowArray->shadowMask, 0, _screenWidth * _screenHeight); tglSetShadowMaskBuf(_currentShadowArray->shadowMask); _currentShadowArray->planeList.begin(); for (SectorListType::iterator i = _currentShadowArray->planeList.begin(); i != _currentShadowArray->planeList.end(); ++i) { Sector *shadowSector = i->sector; tglBegin(TGL_POLYGON); for (int k = 0; k < shadowSector->getNumVertices(); k++) { tglVertex3f(shadowSector->getVertices()[k].x(), shadowSector->getVertices()[k].y(), shadowSector->getVertices()[k].z()); } tglEnd(); } tglSetShadowMaskBuf(NULL); tglDisable(TGL_SHADOW_MASK_MODE); }
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(); }