//----------------------------------------------------------------------------------- void Path::Render() const { MeshBuilder builder; builder.Begin(); const float TILE_SIZE = 25.0f; for (PathNode* node : m_openList) { Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE; builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x0000FF7F)); Renderer::instance->DrawText2D(bottomLeft, std::to_string(node->f).substr(0, 4), 0.5f, RGBA::WHITE, false, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); } for (PathNode* node : m_closedList) { Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE; builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0xFF00007F)); Renderer::instance->DrawText2D(bottomLeft, std::to_string(node->f).substr(0, 4), 0.5f, RGBA::WHITE, false, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); } for (PathNode* node : m_resultantPath) { Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE; builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x00FF007F)); } Vector2 bottomLeft = (Vector2(m_currentGoal) * TILE_SIZE); builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x00FF007F)); builder.End(); Mesh* mesh = new Mesh(); builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO); MeshRenderer* renderer = new MeshRenderer(mesh, Renderer::instance->m_defaultMaterial); renderer->Render(); delete mesh; }
//----------------------------------------------------------------------------------------------- const AABB2 AABB2::CalcLargestCenteredInteriorAABB2OfGivenAspectRatio( float aspectRatio ) const { const float containerAspect = CalcAspect(); if( aspectRatio == 0.f ) { const float centerX = 0.5f * (maxs.x + mins.x); return AABB2( centerX, mins.y, centerX, maxs.y ); } else if( aspectRatio < 0.f ) { aspectRatio *= -1.f; } if( aspectRatio >= containerAspect ) { // Contained rect is wider-aspected than us, so we would "letterbox" it within (padded on top and bottom) const float width = maxs.x - mins.x; const float height = width / aspectRatio; const float centerY = 0.5f * (maxs.y + mins.y); return AABB2( mins.x, centerY - (0.5f * height), maxs.x, centerY + (0.5f * height) ); } else { // Contained rect is taller-aspected than us, so we would "pillarbox" it within (padded on left and right) const float height = maxs.y - mins.y; const float width = height * aspectRatio; const float centerX = 0.5f * (maxs.x + mins.x); return AABB2( centerX - (0.5f * width), mins.y, centerX + (0.5f * width), maxs.y ); } }
//----------------------------------------------------------------------------------- void Renderer::DrawText2D(const Vector2& position, const std::string& asciiText, float scale, const RGBA& tint /*= RGBA::WHITE*/, bool drawShadow /*= false*/, const BitmapFont* font /*= nullptr*/, const Vector2& right /*= Vector3::UNIT_X*/, const Vector2& up /*= Vector3::UNIT_Z*/) { //To be used when I expand this method to 3D text UNUSED(up); UNUSED(right); if (asciiText.empty()) { return; } if (font == nullptr) { font = m_defaultFont; } int stringLength = asciiText.size(); Vector2 cursorPosition = position + (Vector2::UNIT_Y * (float)font->m_maxHeight * scale); const Glyph* previousGlyph = nullptr; MeshBuilder builder; builder.Begin(); for (int i = 0; i < stringLength; i++) { unsigned char currentCharacter = asciiText[i]; const Glyph* glyph = font->GetGlyph(currentCharacter); float glyphWidth = static_cast<float>(glyph->width) * scale; float glyphHeight = static_cast<float>(glyph->height) * scale; if (previousGlyph) { const Vector2 kerning = font->GetKerning(*previousGlyph, *glyph); cursorPosition += (kerning * scale); } Vector2 offset = Vector2(glyph->xOffset * scale, -glyph->yOffset * scale); Vector2 topRight = cursorPosition + offset + Vector2(glyphWidth, 0.0f); Vector2 bottomLeft = cursorPosition + offset - Vector2(0.0f, glyphHeight); AABB2 quadBounds = AABB2(bottomLeft, topRight); AABB2 glyphBounds = font->GetTexCoordsForGlyph(*glyph); if (drawShadow) { float shadowWidthOffset = glyphWidth / 10.0f; float shadowHeightOffset = glyphHeight / -10.0f; Vector2 shadowOffset = Vector2(shadowWidthOffset, shadowHeightOffset); AABB2 shadowBounds = AABB2(bottomLeft + shadowOffset, topRight + shadowOffset); builder.AddTexturedAABB(shadowBounds, glyphBounds.mins, glyphBounds.maxs, RGBA::BLACK); } builder.AddTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, tint); cursorPosition.x += glyph->xAdvance * scale; previousGlyph = glyph; } builder.End(); Mesh* mesh = new Mesh(); builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO); mesh->m_drawMode = DrawMode::TRIANGLES; MeshRenderer* thingToRender = new MeshRenderer(mesh, font->GetMaterial()); m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop()); GL_CHECK_ERROR(); thingToRender->Render(); delete mesh; delete thingToRender; }
void FallbackFontRenderer::Draw(uint32_t unicode, spades::Vector2 offset, float size, spades::Vector4 color) { renderer->SetColorAlphaPremultiplied(color); float x = offset.x; float y = offset.y; auto glyph = FindGlyph(unicode); if(glyph.img == nullptr) { // no glyph found! draw box in the last resort IImage *img = whiteImage; renderer->DrawImage(img, AABB2(x, y, size, 1.f)); renderer->DrawImage(img, AABB2(x, y + size - 1.f, size, 1.f)); renderer->DrawImage(img, AABB2(x, y + 1.f, 1.f, size - 2.f)); renderer->DrawImage(img, AABB2(x + size - 1.f, y + 1.f, 1.f, size - 2.f)); return; } if(glyph.w == 0) { // null glyph. return; } float scale = size * glyph.sizeInverse; if(roundSize || scale < 1.f) { float newScale = std::max(1.f, floorf(scale)); // vertical-align: baseline offset.y += (scale - newScale) * glyph.size; scale = newScale; } AABB2 inRect(glyph.x, glyph.y, glyph.w, glyph.h); AABB2 outRect(glyph.offX, glyph.offY, glyph.w, glyph.h); // margin to make the border completely transparent // (considering the OpenGL's linear interpolation) if(!roundSize){ inRect.min.x -= 0.5f; inRect.min.y -= 0.5f; outRect.min.x -= 0.5f; outRect.min.y -= 0.5f; inRect.max.x += 0.5f; inRect.max.y += 0.5f; outRect.max.x += 0.5f; outRect.max.y += 0.5f; } outRect.min *= scale; outRect.max *= scale; outRect.min += offset; outRect.max += offset; renderer->DrawImage(glyph.img, outRect, inRect); }
void AsyncRenderer::DrawImage(client::IImage *image, const spades::Vector2 &outTopLeft) { SPADES_MARK_FUNCTION(); DrawImage(image, AABB2(outTopLeft.x, outTopLeft.y, image->GetWidth(), image->GetHeight()), AABB2(0, 0, image->GetWidth(), image->GetHeight())); }
void PaletteView::Draw() { Handle<IImage> img = renderer->RegisterImage("Gfx/Palette.png"); int sel = GetSelectedIndex(); float scrW = renderer->ScreenWidth(); float scrH = renderer->ScreenHeight(); for(size_t phase = 0; phase < 2; phase++){ for(size_t i = 0; i < colors.size(); i++){ if((sel == i) != (phase == 1)) continue; int row = i / 8; int col = i % 8; bool selected = sel == i; // draw color IntVector3 icol = colors[i]; Vector4 cl; cl.x = icol.x / 255.f; cl.y = icol.y / 255.f; cl.z = icol.z / 255.f; cl.w = 1.f; float x = scrW - 100.f + 10.f * col; float y = scrH - 96.f + 10.f * row - 40.f; renderer->SetColorAlphaPremultiplied(cl); if(selected){ renderer->DrawImage(img, MakeVector2(x, y), AABB2(0, 16, 16, 16)); }else{ renderer->DrawImage(img, MakeVector2(x, y), AABB2(0, 0, 16, 16)); } renderer->SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1)); if(selected){ renderer->DrawImage(img, MakeVector2(x, y), AABB2(16, 16, 16, 16)); }else{ renderer->DrawImage(img, MakeVector2(x, y), AABB2(16, 0, 16, 16)); } } } }
//----------------------------------------------------------------------------------- void Renderer::DrawText2D ( const Vector2& startBottomLeft , const std::string& asciiText , float cellWidth , float cellHeight , const RGBA& tint /*= RGBA::WHITE*/ , bool drawShadow /*= false*/ , const BitmapFont* font /*= nullptr*/) { const float SHADOW_WIDTH_OFFSET = cellWidth / 10.0f; const float SHADOW_HEIGHT_OFFSET = cellHeight / -10.0f; const Vector2 SHADOW_OFFSET = Vector2(SHADOW_WIDTH_OFFSET, SHADOW_HEIGHT_OFFSET); if (asciiText.empty()) { return; } MeshBuilder builder; builder.Begin(); if (font == nullptr) { font = m_defaultFont; } int stringLength = asciiText.size(); Vector2 currentPosition = startBottomLeft; for (int i = 0; i < stringLength; i++) { unsigned char currentCharacter = asciiText[i]; Vector2 topRight = currentPosition + Vector2(cellWidth, cellHeight); AABB2 quadBounds = AABB2(currentPosition, topRight); AABB2 glyphBounds = font->GetTexCoordsForGlyph(currentCharacter); if (drawShadow) { AABB2 shadowBounds = AABB2(currentPosition + SHADOW_OFFSET, topRight + SHADOW_OFFSET); builder.AddTexturedAABB(shadowBounds, glyphBounds.mins, glyphBounds.maxs, RGBA::BLACK); } builder.AddTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, tint); currentPosition.x += cellWidth; } builder.End(); Mesh* mesh = new Mesh(); builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO); mesh->m_drawMode = DrawMode::TRIANGLES; MeshRenderer* thingToRender = new MeshRenderer(mesh, font->GetMaterial()); m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop()); GL_CHECK_ERROR(); thingToRender->Render(); delete mesh; delete thingToRender; }
//----------------------------------------------------------------------------------- void Console::Render() const { if (m_isActive) { Renderer::instance->BeginOrtho(Vector2(0.0f, 0.0f), Vector2(1600, 900)); Renderer::instance->EnableDepthTest(false); Renderer::instance->DrawAABB(AABB2(Vector2(0, 0), Vector2(1600, 900)), RGBA(0x00000088)); Vector2 currentBaseline = Vector2::ONE * 10.0f; Renderer::instance->DrawText2D(currentBaseline, std::string(m_currentLine), 1.0f, RGBA::WHITE, true, m_font); unsigned int index = m_consoleHistory.size() - 1; unsigned int numberOfLinesPrinted = 0; for (auto reverseIterator = m_consoleHistory.rbegin(); reverseIterator != m_consoleHistory.rend(); ++reverseIterator, --index) { currentBaseline += Vector2(0.0f, (float)m_font->m_maxHeight); Renderer::instance->DrawText2D(currentBaseline, m_consoleHistory[index].text, 1.0f, m_consoleHistory[index].color, true, m_font); numberOfLinesPrinted++; if (numberOfLinesPrinted > MAX_CONSOLE_LINES) { return; } } Renderer::instance->EndOrtho(); } }
void Tile::Render() const { TheRenderer::instance->PushMatrix(); TheRenderer::instance->Translate(GetWorldCoordsFromTileMin()); AABB2 TextureCoords = m_definition->GetTextureCoordinates(); TheRenderer::instance->DrawTexturedAABB(AABB2(Vector2(0.0f, 0.0f), Vector2(TILE_SIZE, TILE_SIZE)), TextureCoords.mins, TextureCoords.maxs, *m_definition->GetTexture(), m_definition->GetColor()); TheRenderer::instance->PopMatrix(); }
void AsyncRenderer::DrawImage(client::IImage *image, const spades::AABB2 &outRect) { SPADES_MARK_FUNCTION(); DrawImage(image, outRect, AABB2(0, 0, image->GetWidth(), image->GetHeight())); }
AABB2 ClientUI::GetTextInputRect() { SPADES_MARK_FUNCTION(); if(!ui){ return AABB2(); } static ScriptFunction func("ClientUI", "AABB2 GetTextInputRect()"); ScriptContextHandle c = func.Prepare(); c->SetObject(&*ui); c.ExecuteChecked(); return *reinterpret_cast<AABB2*>(c->GetReturnObject()); }
void TheGame::Render() const { m_map->Render(); if (m_isPaused) { Vector2 screenMins = Vector2(0.f, 0.f); Vector2 screenMaxs = Vector2(TheApp::instance->GetWindowWidth(), TheApp::instance->GetWindowHeight()); Vector2 gameMaxs = Vector2(16.f, 9.f); Vector2 pauseGraphicMins = Vector2(TheApp::instance->GetWindowWidth() / 8.f, TheApp::instance->GetWindowHeight() / 8.f); Vector2 pauseGraphicMaxs = Vector2(TheApp::instance->GetWindowWidth() * (7.f / 8.f), TheApp::instance->GetWindowHeight() * (7.f / 8.f)); RGBA pauseColor = RGBA(0.0f, 0.0f, 0.0f, 0.3f); TheRenderer::instance->PushMatrix(); TheRenderer::instance->DrawAABB(AABB2(screenMins, screenMaxs), pauseColor); TheRenderer::instance->SetOrtho(screenMins, screenMaxs); TheRenderer::instance->DrawTexturedAABB(AABB2(pauseGraphicMins, pauseGraphicMaxs), Vector2(0.f, 0.f), Vector2(1.f, 1.f), *m_pauseTexture, RGBA(1.f, 1.f, 1.f)); TheRenderer::instance->SetOrtho(screenMins, gameMaxs); TheRenderer::instance->PopMatrix(); } }
AABB2 StartupScreen::GetTextInputRect() { SPADES_MARK_FUNCTION(); if (!ui) { return AABB2(); } ScopedPrivilegeEscalation privilege; static ScriptFunction func("StartupScreenUI", "AABB2 GetTextInputRect()"); ScriptContextHandle c = func.Prepare(); c->SetObject(&*ui); c.ExecuteChecked(); return *reinterpret_cast<AABB2 *>(c->GetReturnObject()); }
void HurtRingView::Draw(){ SPADES_MARK_FUNCTION(); Vector3 playerFront; World *w = client->GetWorld(); if(!w){ ClearAll(); return; } Player *p = w->GetLocalPlayer(); if(p == NULL || !p->IsAlive()){ ClearAll(); return; } playerFront = p->GetFront2D(); float hurtRingSize = renderer->ScreenHeight() * .3f; float cx = renderer->ScreenWidth() * .5f; float cy = renderer->ScreenHeight() * .5f; static const float coords[][2]={ {-1,-1},{1,-1},{-1,1} }; std::list<Item>::iterator it; for(it = items.begin(); it != items.end(); it++){ Item& item = *it; float fade = item.fade * 2.f; if(fade > 1.f)fade = 1.f; Vector4 color = {1,1,1,fade}; renderer->SetColor(color); Vector3 dir = -item.dir; float c = dir.x * playerFront.x + dir.y * playerFront.y; float s = dir.y * playerFront.x - dir.x * playerFront.y; Vector2 verts[3]; for(int i = 0; i < 3; i++){ verts[i] = MakeVector2(coords[i][0] * c - coords[i][1] * s, coords[i][0] * s + coords[i][1] * c); verts[i] = verts[i] * hurtRingSize + MakeVector2(cx, cy); } renderer->DrawImage(image, verts[0], verts[1], verts[2], AABB2(0, 0, image->GetWidth(), image->GetHeight())); } }
void MainMenuState::Render() const { g_theRenderer->ClearScreen(0.f, 0.f, 0.f); AABB2 quad = AABB2(Vector2(0.f, 0.f), Vector2(1600.f, 900.f)); g_theRenderer->DrawTexturedAABB2(m_screenImage, RGBA::WHITE, quad); float frequency = 1; // Frequency in Hz float opacity = 0.5f * (1 + sin(2.f * pi * frequency * m_age)); //float opacity = 0.5f * sin(m_age * 4.f) + 1.f; //opacity = ClampFloat(opacity, 0.f, 1.f); String enterText = StringUtils::Stringf("PRESS ENTER"); m_squirrelFont->DrawText2D(Vector2(470.f, 100.f), enterText, 60.f, RGBA(1.f, 1.f, 1.f, opacity), NULL); }
void TheRenderer::DrawText2D(const Vector2& startBottomLeft, const std::string& asciiText, float cellWidth, float cellHeight, const RGBA& tint /*= RGBA::WHITE*/, const BitmapFont* font /*= nullptr*/) { if (font == nullptr) { font = m_defaultFont; } int stringLength = asciiText.size(); Vector2 currentPosition = startBottomLeft; for (int i = 0; i < stringLength; i++) { unsigned char currentCharacter = asciiText[i]; Vector2 topRight = currentPosition + Vector2(cellWidth, cellHeight); AABB2 quadBounds = AABB2(currentPosition, topRight); AABB2 glyphBounds = font->GetTexCoordsForGlyph(currentCharacter); DrawTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, *font->GetTexture(), tint); currentPosition.x += cellWidth; } }
void MainScreen::DrawStartupScreen() { SPADES_MARK_FUNCTION(); Handle<client::IImage> img; Vector2 scrSize = {renderer->ScreenWidth(), renderer->ScreenHeight()}; renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 1.)); img = renderer->RegisterImage("Gfx/White.tga"); renderer->DrawImage(img, AABB2(0, 0, scrSize.x, scrSize.y)); std::string str = _Tr("MainScreen", "NOW LOADING"); Vector2 size = font->Measure(str); Vector2 pos = MakeVector2(scrSize.x - 16.f, scrSize.y - 16.f); pos -= size; font->DrawShadow(str, pos, 1.f, MakeVector4(1,1,1,1), MakeVector4(0,0,0,0.5)); renderer->FrameDone(); renderer->Flip(); }
void ScoreboardView::Draw() { SPADES_MARK_FUNCTION(); world = client->GetWorld(); if(!world){ // no world return; } ctf = dynamic_cast<CTFGameMode *>(world->GetMode()); tc = dynamic_cast<TCGameMode *>(world->GetMode()); Handle<IImage>image; IFont *font; Vector2 pos, size; char buf[256]; std::string str; float scrWidth = renderer->ScreenWidth(); float scrHeight = renderer->ScreenHeight(); const Vector4 whiteColor = {1,1,1,1}; Handle<IImage> whiteImage = renderer->RegisterImage("Gfx/White.tga"); float teamBarTop = 120.f; float teamBarHeight = 60.f; float contentsLeft = scrWidth * .5f - 400.f; float contentsRight = scrWidth * .5f + 400.f; float playersHeight = 300.f; float playersTop = teamBarTop + teamBarHeight; float playersBottom = playersTop + playersHeight; // draw shadow image = renderer->RegisterImage("Gfx/Scoreboard/TopShadow.tga"); size.y = 32.f; renderer->SetColor(MakeVector4(0,0,0,0.2f)); renderer->DrawImage(image, AABB2(0, teamBarTop-size.y, scrWidth, size.y)); renderer->SetColor(MakeVector4(0,0,0,0.2f)); renderer->DrawImage(image, AABB2(0, playersBottom + size.y, scrWidth, -size.y)); // draw scores image = renderer->RegisterImage("Gfx/Scoreboard/ScoresBg.tga"); size = MakeVector2(180.f, 32.f); pos = MakeVector2((scrWidth - size.x) * .5f, teamBarTop - size.y); renderer->SetColor(MakeVector4(1.f, .45f, .2f, 1.f)); renderer->DrawImage(image, AABB2(pos.x,pos.y,size.x,size.y)); pos.y = pos.y + 5.f; font = client->designFont; sprintf(buf, "%d", GetTeamScore(0)); size = font->Measure(buf); pos.x = scrWidth * .5f - size.x - 16.f; font->Draw(buf, pos + MakeVector2(0, 1), 1.f, MakeVector4(0, 0, 0, 0.3)); font->Draw(buf, pos, 1.f, whiteColor); sprintf(buf, "%d", GetTeamScore(1)); size = font->Measure(buf); pos.x = scrWidth * .5f + 16.f; font->Draw(buf, pos + MakeVector2(0, 1), 1.f, MakeVector4(0, 0, 0, 0.3)); font->Draw(buf, pos, 1.f, whiteColor); sprintf(buf, "-"); size = font->Measure(buf); pos.x = scrWidth * .5f - size.x * .5f; font->Draw(buf, pos + MakeVector2(0, 1), 1.f, MakeVector4(0, 0, 0, 0.3)); font->Draw(buf, pos, 1.f, whiteColor); // draw team bar image = whiteImage; renderer->SetColor(AdjustColor(GetTeamColor(0), 0.8f, 0.3f)); renderer->DrawImage(image, AABB2(0, teamBarTop, scrWidth * .5f, teamBarHeight)); renderer->SetColor(AdjustColor(GetTeamColor(1), 0.8f, 0.3f)); renderer->DrawImage(image, AABB2(scrWidth * .5f, teamBarTop, scrWidth * .5f, teamBarHeight)); image = renderer->RegisterImage("Gfx/Scoreboard/Grunt.tga"); size.x = 120.f; size.y = 60.f; renderer->DrawImage(image, AABB2(contentsLeft, teamBarTop + teamBarHeight - size.y, size.x, size.y)); renderer->DrawImage(image, AABB2(contentsRight, teamBarTop + teamBarHeight - size.y, -size.x, size.y)); font = client->bigTextFont; str = world->GetTeam(0).name; pos.x = contentsLeft + 110.f; pos.y = teamBarTop + 5.f; font->Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5)); font->Draw(str, pos, 1.f, whiteColor); str = world->GetTeam(1).name; size = font->Measure(str); pos.x = contentsRight - 110.f - size.x; pos.y = teamBarTop + 5.f; font->Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5)); font->Draw(str, pos, 1.f, whiteColor); // players background image = renderer->RegisterImage("Gfx/Scoreboard/PlayersBg.tga"); renderer->SetColor(MakeVector4(0, 0, 0, 1.f)); renderer->DrawImage(image, AABB2(0, playersTop, scrWidth, playersHeight)); // draw players DrawPlayers(0, contentsLeft, playersTop, (contentsRight - contentsLeft) * .5f, playersHeight); DrawPlayers(1, scrWidth * .5f, playersTop, (contentsRight - contentsLeft) * .5f, playersHeight); }
void MapView::Draw(){ World *world = client->GetWorld(); if(!world) return; Player *player = world->GetLocalPlayer(); if(client->IsFollowing()){ player = world->GetPlayer(client->followingPlayerId); } if(!player) return; if(largeMap) if(zoomState < .0001f) return; GameMap *map = world->GetMap(); Vector2 mapSize = MakeVector2(map->Width(), map->Height()); Vector3 pos = player->GetPosition();; if(player->GetTeamId() >= 2){ pos = client->followPos; } Vector2 center = {pos.x, pos.y}; float cfgMapSize = cg_minimapSize; if(cfgMapSize < 32) cfgMapSize = 32; if(cfgMapSize > 256) cfgMapSize = 256; Vector2 mapWndSize = {cfgMapSize, cfgMapSize}; float scale = actualScale; center = Mix(center, mapSize * .5f, zoomState); Vector2 zoomedSize = {512, 512}; if(renderer->ScreenWidth() < 512.f || renderer->ScreenHeight() < 512.f) zoomedSize = MakeVector2(256, 256); if(largeMap){ float per = zoomState; per = 1.f - per; per *= per; per = 1.f - per; per = Mix(.7f, 1.f, per); zoomedSize = Mix(MakeVector2(0, 0), zoomedSize, per); mapWndSize = zoomedSize; } Vector2 inRange = mapWndSize * .5f * scale; AABB2 inRect(center - inRange, center + inRange); if(largeMap){ inRect.min = MakeVector2(0, 0); inRect.max = mapSize; }else{ if(inRect.GetMinX() < 0.f) inRect = inRect.Translated(-inRect.GetMinX(), 0.f); if(inRect.GetMinY() < 0.f) inRect = inRect.Translated(0, -inRect.GetMinY()); if(inRect.GetMaxX() > mapSize.x) inRect = inRect.Translated(mapSize.x - inRect.GetMaxX(), 0.f); if(inRect.GetMaxY() > mapSize.y) inRect = inRect.Translated(0, mapSize.y - inRect.GetMaxY()); } AABB2 outRect(renderer->ScreenWidth() - mapWndSize.x - 16.f, 16.f, mapWndSize.x, mapWndSize.y); if(largeMap){ outRect.min = MakeVector2((renderer->ScreenWidth() - zoomedSize.x) * .5f, (renderer->ScreenHeight() - zoomedSize.y) * .5f); outRect.max =MakeVector2((renderer->ScreenWidth() + zoomedSize.x) * .5f, (renderer->ScreenHeight() + zoomedSize.y) * .5f); } float alpha = 1.f; if(largeMap){ alpha = zoomState; } // fades bg if(largeMap) { Handle<IImage> bg = renderer->RegisterImage("Gfx/MapBg.png"); Vector2 scrSize = {renderer->ScreenWidth(), renderer->ScreenHeight()}; float size = std::max(scrSize.x, scrSize.y); renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0,alpha * .5f)); renderer->DrawImage(bg, AABB2((scrSize.x - size) * .5f, (scrSize.y - size) * .5f, size, size)); } // draw border Handle<IImage> border; float borderWidth; AABB2 borderRect = outRect; if(largeMap) { border = renderer->RegisterImage("Gfx/MapBorder.png"); borderWidth = 3.f * outRect.GetHeight() / zoomedSize.y; }else{ border = renderer->RegisterImage("Gfx/MinimapBorder.png"); borderWidth = 2.f; } borderRect = borderRect.Inflate(borderWidth - 8.f); renderer->SetColorAlphaPremultiplied(MakeVector4(alpha,alpha,alpha,alpha)); renderer->DrawImage(border, AABB2(borderRect.GetMinX()-16, borderRect.GetMinY()-16, 16, 16), AABB2(0, 0, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMinY()-16, 16, 16), AABB2(16, 0, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX()-16, borderRect.GetMaxY(), 16, 16), AABB2(0, 16, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMaxY(), 16, 16), AABB2(16, 16, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX(), borderRect.GetMinY()-16, borderRect.GetWidth(), 16), AABB2(16, 0, 0, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX(), borderRect.GetMaxY(), borderRect.GetWidth(), 16), AABB2(16, 16, 0, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX()-16, borderRect.GetMinY(), 16, borderRect.GetHeight()), AABB2(0, 16, 16, 0)); renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMinY(), 16, borderRect.GetHeight()), AABB2(16, 16, 16, 0)); // draw map renderer->SetColorAlphaPremultiplied(MakeVector4(alpha,alpha,alpha,alpha)); renderer->DrawFlatGameMap(outRect, inRect); this->inRect = inRect; this->outRect = outRect; // draw grid renderer->SetColorAlphaPremultiplied(MakeVector4(0,0,0,0.8f*alpha)); Handle<IImage> dashLine = renderer->RegisterImage("Gfx/DashLine.tga"); for(float x = 64.f; x < map->Width(); x += 64.f){ float wx = (x - inRect.GetMinX()) / inRect.GetWidth(); if(wx < 0.f || wx >= 1.f) continue; wx = (wx * outRect.GetWidth()) + outRect.GetMinX(); wx = roundf(wx); renderer->DrawImage(dashLine, MakeVector2(wx, outRect.GetMinY()), AABB2(0, 0, 1.f, outRect.GetHeight())); } for(float y = 64.f; y < map->Height(); y += 64.f){ float wy = (y - inRect.GetMinY()) / inRect.GetHeight(); if(wy < 0.f || wy >= 1.f) continue; wy = (wy * outRect.GetHeight()) + outRect.GetMinY(); wy = roundf(wy); renderer->DrawImage(dashLine, MakeVector2(outRect.GetMinX(), wy), AABB2(0, 0, outRect.GetWidth(), 1.f)); } // draw grid label renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(0.8f*alpha)); Handle<IImage> mapFont = renderer->RegisterImage("Gfx/Fonts/MapFont.tga"); for(int i = 0; i < 8; i++){ float startX = (float)i * 64.f; float endX = startX + 64.f; if(startX > inRect.GetMaxX() || endX < inRect.GetMinX()) continue; float fade = std::min((std::min(endX, inRect.GetMaxX()) - std::max(startX, inRect.GetMinX())) / (endX - startX) * 2.f, 1.f); renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(fade * .8f * alpha)); float center = std::max(startX, inRect.GetMinX()); center = .5f * (center + std::min(endX, inRect.GetMaxX())); float wx = (center - inRect.GetMinX()) / inRect.GetWidth(); wx = (wx * outRect.GetWidth()) + outRect.GetMinX(); wx = roundf(wx); float fntX = static_cast<float>((i & 3) * 8); float fntY = static_cast<float>((i >> 2) * 8); renderer->DrawImage(mapFont, MakeVector2(wx - 4.f, outRect.GetMinY() + 4), AABB2(fntX, fntY, 8, 8)); } for(int i = 0; i < 8; i++){ float startY = (float)i * 64.f; float endY = startY + 64.f; if(startY > inRect.GetMaxY() || endY < inRect.GetMinY()) continue; float fade = std::min((std::min(endY, inRect.GetMaxY()) - std::max(startY, inRect.GetMinY())) / (endY - startY) * 2.f, 1.f); renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(fade * .8f * alpha)); float center = std::max(startY, inRect.GetMinY()); center = .5f * (center + std::min(endY, inRect.GetMaxY())); float wy = (center - inRect.GetMinY()) / inRect.GetHeight(); wy = (wy * outRect.GetHeight()) + outRect.GetMinY(); wy = roundf(wy); int fntX = (i & 3) * 8; int fntY = (i >> 2) * 8 + 16; renderer->DrawImage(mapFont, MakeVector2(outRect.GetMinX() + 4, wy - 4.f), AABB2(fntX, fntY, 8, 8)); } //draw objects std::string iconmode = cg_Minimap_Player_Icon;//import variable from configuration file std::string colormode = cg_Minimap_Player_Color;//import variable from configuration file Handle<IImage> playerSMG = renderer->RegisterImage("Gfx/Map/SMG.png"); Handle<IImage> playerRifle = renderer->RegisterImage("Gfx/Map/Rifle.png"); Handle<IImage> playerShotgun = renderer->RegisterImage("Gfx/Map/Shotgun.png"); Handle<IImage> playerIcon = renderer->RegisterImage("Gfx/Map/Player.png"); { IntVector3 teamColor = world->GetLocalPlayer()->GetTeamId() >= 2 ? IntVector3::Make(200, 200, 200) : world->GetTeam(world->GetLocalPlayer()->GetTeamId()).color; Vector4 teamColorF = ModifyColor(teamColor); teamColorF *= alpha; // draw local player's view { Player *p = player; Handle<IImage> viewIcon = renderer->RegisterImage("Gfx/Map/View.png"); if(p->IsAlive()) { Vector3 front = p->GetFront2D(); float ang = atan2(front.x, -front.y); if(player->GetTeamId() >= 2){ ang = client->followYaw - static_cast<float>(M_PI) * .5f; } renderer->SetColorAlphaPremultiplied(teamColorF * 0.9f); DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), viewIcon, ang); } } // draw player's icon for(int i = 0; i < world->GetNumPlayerSlots(); i++){ Player * p = world->GetPlayer(i); if(p == nullptr || p->GetTeamId() != world->GetLocalPlayer()->GetTeamId() || !p->IsAlive()) continue; Vector3 front = p->GetFront2D(); float ang = atan2(front.x, -front.y); if(player->GetTeamId() >= 2){ ang = client->followYaw - static_cast<float>(M_PI) * .5f; } //use a spec color for each player if ( colormode=="1"){ IntVector3 Colorplayer=IntVector3::Make(palette[i][0],palette[i][1],palette[i][2]); Vector4 ColorplayerF = ModifyColor(Colorplayer); ColorplayerF *=1.0f; renderer->SetColorAlphaPremultiplied(ColorplayerF); } else { renderer->SetColorAlphaPremultiplied(teamColorF); } //use a different icon in minimap according to weapon of player if( iconmode=="1"){ WeaponType weapon=world->GetPlayer(i)->GetWeaponType(); if (weapon == WeaponType::SMG_WEAPON){ DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(),playerSMG , ang); } else if (weapon == WeaponType::RIFLE_WEAPON){ DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), playerRifle, ang); } else if (weapon == WeaponType::SHOTGUN_WEAPON){ DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), playerShotgun, ang); } } else{//draw normal color DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), playerIcon, ang); } } } IGameMode* mode = world->GetMode(); if( mode && IGameMode::m_CTF == mode->ModeType() ) { CTFGameMode *ctf = static_cast<CTFGameMode *>(mode); Handle<IImage> intelIcon = renderer->RegisterImage("Gfx/Map/Intel.png"); Handle<IImage> baseIcon = renderer->RegisterImage("Gfx/Map/CommandPost.png"); for(int tId = 0; tId < 2; tId++){ CTFGameMode::Team& team = ctf->GetTeam(tId); IntVector3 teamColor = world->GetTeam(tId).color; Vector4 teamColorF = ModifyColor(teamColor); teamColorF *= alpha; // draw base renderer->SetColorAlphaPremultiplied(teamColorF); DrawIcon(team.basePos, baseIcon, 0.f); // draw flag if(!ctf->GetTeam(1-tId).hasIntel){ renderer->SetColorAlphaPremultiplied(teamColorF); DrawIcon(team.flagPos, intelIcon, 0.f); }else if(world->GetLocalPlayer()->GetTeamId() == 1-tId){ // local player's team is carrying int cId = ctf->GetTeam(1-tId).carrier; // in some game modes, carrier becomes invalid if(cId < world->GetNumPlayerSlots()){ Player * carrier= world->GetPlayer(cId); if(carrier && carrier->GetTeamId() == world->GetLocalPlayer()->GetTeamId()){ Vector4 col = teamColorF; col *= fabsf(sinf(world->GetTime() * 4.f)); renderer->SetColorAlphaPremultiplied(col); DrawIcon(carrier->GetPosition(), intelIcon, 0.f); } } } } } else if( mode && IGameMode::m_TC == mode->ModeType() ) { TCGameMode *tc = static_cast<TCGameMode *>(mode); Handle<IImage> icon = renderer->RegisterImage("Gfx/Map/CommandPost.png"); int cnt = tc->GetNumTerritories(); for(int i = 0; i < cnt; i++){ TCGameMode::Territory *t = tc->GetTerritory(i); IntVector3 teamColor = {128,128,128}; if(t->ownerTeamId < 2){ teamColor = world->GetTeam(t->ownerTeamId).color; } Vector4 teamColorF = ModifyColor(teamColor); teamColorF *= alpha; // draw base renderer->SetColorAlphaPremultiplied(teamColorF); DrawIcon(t->pos, icon, 0.f); } } }
inline void UIElement::SetRenderBounds(AABB2& renderBounds){ Vector2 renderMins = Vector2(m_screenCoordinates); Vector2 renderMaxs = Vector2(m_screenCoordinates + m_size); renderBounds = AABB2(renderMins, renderMaxs); }
//----------------------------------------------------------------------------------- void TheGame::RenderPaused() { RenderPlaying(); Renderer::instance->DrawAABB(AABB2(Vector2::ZERO, Vector2(1600.0f, 900.0f)), RGBA(0x00000033)); Renderer::instance->DrawText2D(Vector2(350, 250), "Paused", 10.0f, RGBA::VAPORWAVE, true, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); }
LimboView::LimboView(Client *client): client(client), renderer(client->GetRenderer()){ // layout now! float menuWidth = 200.f; float menuHeight = menuWidth / 8.f; float rowHeight = menuHeight + 3.f; float left = (renderer->ScreenWidth() - contentsWidth) * .5f; float top = renderer->ScreenHeight() - 150.f; float teamX = left + 10.f; float firstY = top + 35.f; items.push_back(MenuItem(MenuTeam1, AABB2(teamX, firstY, menuWidth, menuHeight), "Team 1")); items.push_back(MenuItem(MenuTeam2, AABB2(teamX, firstY + rowHeight, menuWidth, menuHeight), "Team 2")); // TODO: use team name items.push_back(MenuItem(MenuTeamSpectator, AABB2(teamX, firstY + rowHeight * 2.f, menuWidth, menuHeight), "Spectator")); float weapX = left + 260.f; items.push_back(MenuItem(MenuWeaponRifle, AABB2(weapX, firstY, menuWidth, menuHeight), "Rifle")); items.push_back(MenuItem(MenuWeaponSMG, AABB2(weapX, firstY + rowHeight, menuWidth, menuHeight), "SMG")); // TODO: use team name items.push_back(MenuItem(MenuWeaponShotgun, AABB2(weapX, firstY + rowHeight * 2.f, menuWidth, menuHeight), "Shotgun")); items.push_back(MenuItem(MenuSpawn, AABB2(left + contentsWidth - 266.f, firstY + 4.f, 256.f, 64.f), "Spawn")); cursorPos = MakeVector2(renderer->ScreenWidth()*.5f, renderer->ScreenHeight()*.5f); selectedTeam = 2; selectedWeapon = RIFLE_WEAPON; }
void LimboView::Draw() { Handle<IImage> menuItemImage = renderer->RegisterImage("Gfx/Limbo/MenuItem.tga"); Handle<IImage> menuItemBigImage = renderer->RegisterImage("Gfx/Limbo/BigMenuItem.tga"); //Handle<IImage> menuItemRingImage = renderer->RegisterImage("Gfx/Limbo/MenuItemRing.tga"); IFont *font = client->textFont; float left = (renderer->ScreenWidth() - contentsWidth) * .5f; float top = renderer->ScreenHeight() - 150.f; { std::string msg = "Select Team:"; Vector2 pos; pos.x = left + 10.f; pos.y = top + 10.f; font->Draw(msg, pos + MakeVector2(0, 1), 1.f, MakeVector4(0,0,0,0.4)); font->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1)); } if(selectedTeam != 2){ std::string msg = "Select Weapon:"; Vector2 pos; pos.x = left + 260.f; pos.y = top + 10.f; font->Draw(msg, pos + MakeVector2(0, 1), 1.f, MakeVector4(0,0,0,0.4)); font->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1)); } for(size_t i = 0; i < items.size(); i++){ MenuItem& item = items[i]; bool selected = false; if(!item.visible) continue; switch(item.type){ case MenuTeam1: selected = selectedTeam == 0; break; case MenuTeam2: selected = selectedTeam == 1; break; case MenuTeamSpectator: selected = selectedTeam == 2; break; case MenuWeaponRifle: selected = selectedWeapon == RIFLE_WEAPON; break; case MenuWeaponSMG: selected = selectedWeapon == SMG_WEAPON; break; case MenuWeaponShotgun: selected = selectedWeapon == SHOTGUN_WEAPON; break; default: selected = false; } Vector4 fillColor = {0.2, 0.2, 0.2, 0.5}; Vector4 ringColor = {0, 0, 0, 0}; if(item.hover){ fillColor = MakeVector4(.4f, .4f, .4f, .7f); ringColor = MakeVector4(.8f, .8f, .8f, .7f); } if(selected){ fillColor = MakeVector4(.7f, .7f, .7f, .9f); } renderer->SetColor(fillColor); if(item.type == MenuSpawn){ renderer->DrawImage(menuItemBigImage, item.rect); std::string msg = item.text; IFont *bFont = client->textFont; Vector2 size = bFont->Measure(msg); Vector2 pos; pos.x = item.rect.GetMinX() + (item.rect.GetWidth() - size.x) / 2.f + 2.f; pos.y = item.rect.GetMinY() + (item.rect.GetHeight() - size.y) / 2.f + 2.f; bFont->Draw(msg, pos + MakeVector2(0, 2), 1.f, MakeVector4(0,0,0,0.4)); bFont->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1)); }else{ renderer->DrawImage(menuItemImage, item.rect); std::string msg = item.text; if(item.type == MenuTeam1) msg = client->GetWorld()->GetTeam(0).name; if(item.type == MenuTeam2) msg = client->GetWorld()->GetTeam(1).name; Vector2 size = font->Measure(msg); Vector2 pos; pos.x = item.rect.GetMinX() + 5.f; pos.y = item.rect.GetMinY() + (item.rect.GetHeight() - size.y) / 2.f + 2.f; font->Draw(msg, pos + MakeVector2(0, 1), 1.f, MakeVector4(0,0,0,0.4)); font->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1)); } } Handle<IImage> cursor = renderer->RegisterImage("Gfx/Limbo/Cursor.tga"); renderer->SetColor(MakeVector4(1, 1, 1, 1)); renderer->DrawImage(cursor, AABB2(cursorPos.x - 8, cursorPos.y - 8, 32, 32)); }
//============================================================================================================== #pragma once #ifndef _included_UIElement__ #define _included_UIElement__ #include "Engine/Math/Math2D.hpp" #include "Engine/Renderer/MeshRenderer.hpp" //#include "Engine/Renderer/OGLRenderingUtils.hpp" //=========================================================================================================== //UI constants static const AABB2 DEFAULT_ELEMENT_BOUNDING_BOX = AABB2(Vector2(-16.0f, -16.0f), Vector2(16.0f, 16.0f)); //default 32x32 box about origin static const Vector2 DEFAULT_ELEMENT_SIZE = Vector2(32.0f, 32.0f); static int elementID = 0; struct MeshRenderer; class OpenGLRenderer; enum MouseButtonID; struct ModelViewMatrix; //UI anchor constants // static const Vector2 UI_SCREEN_SIZE = Vector2(theOGLRenderer->GetDisplayWidth(), theOGLRenderer->GetDisplayHeight()); // static const Vector2 UI_ANCHOR_SCREEN_CENTER = UI_SCREEN_SIZE * 0.5f; // static const Vector2 UI_ANCHOR_SCREEN_LEFT_CENTER = Vector2(0.0f, theOGLRenderer->GetDisplayHeight() * 0.5f); // static const Vector2 UI_ANCHOR_SCREEN_RIGHT_CENTER = Vector2(theOGLRenderer->GetDisplayWidth(), theOGLRenderer->GetDisplayHeight() * 0.5f);