void CInMapDraw::Draw(void) { GML_STDMUTEX_LOCK(inmap); //! Draw CVertexArray* va = GetVertexArray(); va->Initialize(); CVertexArray* lineva = GetVertexArray(); lineva->Initialize(); InMapDraw_QuadDrawer drawer; drawer.imd = this; drawer.lineva = lineva; drawer.va = va; drawer.visLabels = &visibleLabels; glDepthMask(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, texture); readmap->GridVisibility(camera, DRAW_QUAD_SIZE, 3000.0f, &drawer); glDisable(GL_TEXTURE_2D); glLineWidth(3.f); lineva->DrawArrayC(GL_LINES); //! draw lines // XXX hopeless drivers, retest in a year or so... // width greater than 2 causes GUI flicker on ATI hardware as of driver version 9.3 // so redraw lines with width 1 if (globalRendering->atiHacks) { glLineWidth(1.f); lineva->DrawArrayC(GL_LINES); } // draw points glLineWidth(1); glEnable(GL_TEXTURE_2D); va->DrawArrayTC(GL_QUADS); //! draw point markers if (!visibleLabels.empty()) { font->SetColors(); //! default //! draw point labels for (std::vector<MapPoint*>::iterator pi = visibleLabels.begin(); pi != visibleLabels.end(); ++pi) { float3 pos = (*pi)->pos; pos.y += 111.0f; font->SetTextColor((*pi)->color[0]/255.0f, (*pi)->color[1]/255.0f, (*pi)->color[2]/255.0f, 1.0f); //FIXME (overload!) font->glWorldPrint(pos, 26.0f, (*pi)->label); } visibleLabels.clear(); } glDepthMask(1); }
void CInMapDrawView::Draw() { CVertexArray* pointsVa = GetVertexArray(); pointsVa->Initialize(); CVertexArray* linesVa = GetVertexArray(); linesVa->Initialize(); InMapDraw_QuadDrawer drawer; drawer.linesVa = linesVa; drawer.pointsVa = pointsVa; drawer.visibleLabels = &visibleLabels; glDepthMask(0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, texture); readMap->GridVisibility(camera, CInMapDrawModel::DRAW_QUAD_SIZE, 1e9, &drawer); glDisable(GL_TEXTURE_2D); glLineWidth(3.f); linesVa->DrawArrayC(GL_LINES); //! draw lines // XXX hopeless drivers, retest in a year or so... // width greater than 2 causes GUI flicker on ATI hardware as of driver version 9.3 // so redraw lines with width 1 if (globalRendering->atiHacks) { glLineWidth(1.f); linesVa->DrawArrayC(GL_LINES); } // draw points glLineWidth(1); glEnable(GL_TEXTURE_2D); pointsVa->DrawArrayTC(GL_QUADS); //! draw point markers if (!visibleLabels.empty()) { font->SetColors(); //! default //! draw point labels for (std::vector<const CInMapDrawModel::MapPoint*>::const_iterator pi = visibleLabels.begin(); pi != visibleLabels.end(); ++pi) { float3 pos = (*pi)->GetPos(); pos.y += 111.0f; const unsigned char* color = (*pi)->IsBySpectator() ? color4::white : teamHandler->Team((*pi)->GetTeamID())->color; font->SetTextColor(color[0]/255.0f, color[1]/255.0f, color[2]/255.0f, 1.0f); //FIXME (overload!) font->glWorldPrint(pos, 26.0f, (*pi)->GetLabel()); } visibleLabels.clear(); } glDepthMask(1); }
void CInMapDraw::Draw(void) { glDepthMask(0); CVertexArray* va = GetVertexArray(); va->Initialize(); CVertexArray* lineva = GetVertexArray(); lineva->Initialize(); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); InMapDraw_QuadDrawer drawer; drawer.imd = this; drawer.lineva = lineva; drawer.va = va; drawer.texture = texture; readmap->GridVisibility(camera, DRAW_QUAD_SIZE, 3000.0f, &drawer); glDisable(GL_TEXTURE_2D); glLineWidth(3); lineva->DrawArrayC(GL_LINES); glLineWidth(1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture); va->DrawArrayTC(GL_QUADS); glDepthMask(1); }
void CSMFGroundDrawer::CreateWaterPlanes(bool camOufOfMap) { glDisable(GL_TEXTURE_2D); glDepthMask(GL_FALSE); const float xsize = (smfMap->mapSizeX) >> 2; const float ysize = (smfMap->mapSizeZ) >> 2; const float size = std::min(xsize, ysize); CVertexArray* va = GetVertexArray(); va->Initialize(); const unsigned char fogColor[4] = { (unsigned char)(255 * mapInfo->atmosphere.fogColor[0]), (unsigned char)(255 * mapInfo->atmosphere.fogColor[1]), (unsigned char)(255 * mapInfo->atmosphere.fogColor[2]), 255 }; const unsigned char planeColor[4] = { (unsigned char)(255 * mapInfo->water.planeColor[0]), (unsigned char)(255 * mapInfo->water.planeColor[1]), (unsigned char)(255 * mapInfo->water.planeColor[2]), 255 }; const float alphainc = fastmath::PI2 / 32; float alpha,r1,r2; float3 p(0.0f, std::min(-200.0f, smfMap->initMinHeight - 400.0f), 0.0f); for (int n = (camOufOfMap) ? 0 : 1; n < 4 ; ++n) { if ((n == 1) && !camOufOfMap) { // don't render vertices under the map r1 = 2 * size; } else { r1 = n*n * size; } if (n == 3) { // last stripe: make it thinner (looks better with fog) r2 = (n+0.5)*(n+0.5) * size; } else { r2 = (n+1)*(n+1) * size; } for (alpha = 0.0f; (alpha - fastmath::PI2) < alphainc ; alpha += alphainc) { p.x = r1 * fastmath::sin(alpha) + 2 * xsize; p.z = r1 * fastmath::cos(alpha) + 2 * ysize; va->AddVertexC(p, planeColor ); p.x = r2 * fastmath::sin(alpha) + 2 * xsize; p.z = r2 * fastmath::cos(alpha) + 2 * ysize; va->AddVertexC(p, (n==3) ? fogColor : planeColor); } } va->DrawArrayC(GL_TRIANGLE_STRIP); glDepthMask(GL_TRUE); }
void CInMapDraw::Draw(void) { GML_STDMUTEX_LOCK(inmap); //! Draw glDepthMask(0); CVertexArray* va = GetVertexArray(); va->Initialize(); CVertexArray* lineva = GetVertexArray(); lineva->Initialize(); //font->Begin(); font->SetColors(); //! default InMapDraw_QuadDrawer drawer; drawer.imd = this; drawer.lineva = lineva; drawer.va = va; drawer.texture = texture; readmap->GridVisibility(camera, DRAW_QUAD_SIZE, 3000.0f, &drawer); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glLineWidth(3.f); lineva->DrawArrayC(GL_LINES); //! draw lines // XXX hopeless drivers, retest in a year or so... // width greater than 2 causes GUI flicker on ATI hardware as of driver version 9.3 // so redraw lines with width 1 if (gu->atiHacks) { glLineWidth(1.f); lineva->DrawArrayC(GL_LINES); } // draw points glLineWidth(1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture); va->DrawArrayTC(GL_QUADS); //! draw point markers //font->End(); //! draw point markers text glDepthMask(1); }
void CMiniMap::DrawNotes() { if (notes.empty()) { return; } const float baseSize = gs->mapx * SQUARE_SIZE; CVertexArray* va = GetVertexArray(); va->Initialize(); std::list<Notification>::iterator ni = notes.begin(); while (ni != notes.end()) { const float age = gu->gameTime - ni->creationTime; if (age > 2) { ni = notes.erase(ni); continue; } for (int a = 0; a < 3; ++a) { const float modage = age + a * 0.1f; const float rot = modage * 3; float size = baseSize - modage * baseSize * 0.9f; if (size < 0){ if (size < -baseSize * 0.4f) { continue; } else if (size > -baseSize * 0.2f) { size = modage * baseSize * 0.9f - baseSize; } else { size = baseSize * 1.4f - modage * baseSize * 0.9f; } } const float sinSize = fastmath::sin(rot) * size; const float cosSize = fastmath::cos(rot) * size; const unsigned char color[4] = { (unsigned char)(ni->color[0] * 255), (unsigned char)(ni->color[1] * 255), (unsigned char)(ni->color[2] * 255), (unsigned char)(ni->color[3] * 255) }; va->AddVertexC(float3(ni->pos.x + sinSize, ni->pos.z + cosSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x + cosSize, ni->pos.z - sinSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x + cosSize, ni->pos.z - sinSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x - sinSize, ni->pos.z - cosSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x - sinSize, ni->pos.z - cosSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x - cosSize, ni->pos.z + sinSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x - cosSize, ni->pos.z + sinSize, 0.0f),color); va->AddVertexC(float3(ni->pos.x + sinSize, ni->pos.z + cosSize, 0.0f),color); } ++ni; } va->DrawArrayC(GL_LINES); }
void CProjectileHandler::DrawProjectilesMiniMap(const ProjectileContainer& pc) { if (pc.render_size() > 0) { CVertexArray* lines = GetVertexArray(); CVertexArray* points = GetVertexArray(); lines->Initialize(); lines->EnlargeArrays(pc.render_size() * 2, 0, VA_SIZE_C); points->Initialize(); points->EnlargeArrays(pc.render_size(), 0, VA_SIZE_C); for (ProjectileContainer::render_iterator pci = pc.render_begin(); pci != pc.render_end(); ++pci) { CProjectile* p = *pci; if ((p->owner() && (p->owner()->allyteam == gu->myAllyTeam)) || gu->spectatingFullView || loshandler->InLos(p, gu->myAllyTeam)) { p->DrawOnMinimap(*lines, *points); } } lines->DrawArrayC(GL_LINES); points->DrawArrayC(GL_POINTS); } }
void QTPFSPathDrawer::DrawNodeTree(const MoveDef* md) const { QTPFS::QTNode* nt = pm->nodeTrees[md->pathType]; CVertexArray* va = GetVertexArray(); std::list<const QTPFS::QTNode*> nodes; std::list<const QTPFS::QTNode*>::const_iterator nodesIt; GetVisibleNodes(nt, nodes); va->Initialize(); va->EnlargeArrays(nodes.size() * 4, 0, VA_SIZE_C); for (nodesIt = nodes.begin(); nodesIt != nodes.end(); ++nodesIt) { DrawNode(*nodesIt, md, va, false, true, true); } glLineWidth(2); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); va->DrawArrayC(GL_QUADS); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLineWidth(1); }
void CProjectileDrawer::DrawProjectilesMiniMap() { GML_RECMUTEX_LOCK(proj); // DrawProjectilesMiniMap typedef std::set<CProjectile*> ProjectileSet; typedef std::set<CProjectile*>::const_iterator ProjectileSetIt; typedef std::map<int, ProjectileSet> ProjectileBin; typedef std::map<int, ProjectileSet>::const_iterator ProjectileBinIt; for (int modelType = MODELTYPE_3DO; modelType < MODELTYPE_OTHER; modelType++) { const ProjectileBin& projectileBin = modelRenderers[modelType]->GetProjectileBin(); if (!projectileBin.empty()) { for (ProjectileBinIt binIt = projectileBin.begin(); binIt != projectileBin.end(); ++binIt) { CVertexArray* lines = GetVertexArray(); CVertexArray* points = GetVertexArray(); lines->Initialize(); lines->EnlargeArrays((binIt->second).size() * 2, 0, VA_SIZE_C); points->Initialize(); points->EnlargeArrays((binIt->second).size(), 0, VA_SIZE_C); for (ProjectileSetIt setIt = (binIt->second).begin(); setIt != (binIt->second).end(); ++setIt) { CProjectile* p = *setIt; CUnit *owner = p->owner(); if ((owner && (owner->allyteam == gu->myAllyTeam)) || gu->spectatingFullView || loshandler->InLos(p, gu->myAllyTeam)) { p->DrawOnMinimap(*lines, *points); } } lines->DrawArrayC(GL_LINES); points->DrawArrayC(GL_POINTS); } } } if (!renderProjectiles.empty()) { CVertexArray* lines = GetVertexArray(); CVertexArray* points = GetVertexArray(); lines->Initialize(); lines->EnlargeArrays(renderProjectiles.size() * 2, 0, VA_SIZE_C); points->Initialize(); points->EnlargeArrays(renderProjectiles.size(), 0, VA_SIZE_C); for (std::set<CProjectile*>::iterator it = renderProjectiles.begin(); it != renderProjectiles.end(); ++it) { CProjectile* p = *it; const CUnit* owner = p->owner(); if ((owner && (owner->allyteam == gu->myAllyTeam)) || gu->spectatingFullView || loshandler->InLos(p, gu->myAllyTeam)) { p->DrawOnMinimap(*lines, *points); } } lines->DrawArrayC(GL_LINES); points->DrawArrayC(GL_POINTS); } }
void Patch::DrawBorder() { CVertexArray* va = GetVertexArray(); GenerateBorderIndices(va); va->DrawArrayC(GL_TRIANGLES); }
void CSelectedUnits::Draw() { glDisable(GL_TEXTURE_2D); glDepthMask(false); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); // for line smoothing glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(cmdColors.UnitBoxLineWidth()); GML_RECMUTEX_LOCK(grpsel); // Draw if (cmdColors.unitBox[3] > 0.05f) { const CUnitSet* unitSet; if (selectedGroup != -1) { unitSet = &grouphandlers[gu->myTeam]->groups[selectedGroup]->units; } else { unitSet = &selectedUnits; } CVertexArray* va = GetVertexArray(); va->Initialize(); va->EnlargeArrays(unitSet->size() * 8, 0, VA_SIZE_C); for (CUnitSet::const_iterator ui = unitSet->begin(); ui != unitSet->end(); ++ui) { const CUnit* unit = *ui; if (unit->isIcon) { continue; } const int uhxsize = (unit->xsize * SQUARE_SIZE) >> 1, uhzsize = (unit->zsize * SQUARE_SIZE) >> 1, mhxsize = (unit->mobility == NULL)? uhxsize: ((unit->mobility->xsize * SQUARE_SIZE) >> 1), mhzsize = (unit->mobility == NULL)? uhzsize: ((unit->mobility->zsize * SQUARE_SIZE) >> 1); const float3 verts[8] = { // UnitDef footprint corners float3(unit->drawPos.x + uhxsize, unit->drawPos.y, unit->drawPos.z + uhzsize), float3(unit->drawPos.x - uhxsize, unit->drawPos.y, unit->drawPos.z + uhzsize), float3(unit->drawPos.x - uhxsize, unit->drawPos.y, unit->drawPos.z - uhzsize), float3(unit->drawPos.x + uhxsize, unit->drawPos.y, unit->drawPos.z - uhzsize), // MoveDef footprint corners float3(unit->drawPos.x + mhxsize, unit->drawPos.y, unit->drawPos.z + mhzsize), float3(unit->drawPos.x - mhxsize, unit->drawPos.y, unit->drawPos.z + mhzsize), float3(unit->drawPos.x - mhxsize, unit->drawPos.y, unit->drawPos.z - mhzsize), float3(unit->drawPos.x + mhxsize, unit->drawPos.y, unit->drawPos.z - mhzsize), }; const unsigned char colors[2][4] = { {(0.0f + cmdColors.unitBox[0]) * 255, (0.0f + cmdColors.unitBox[1]) * 255, (0.0f + cmdColors.unitBox[2] * 255), cmdColors.unitBox[3] * 255}, {(1.0f - cmdColors.unitBox[0]) * 255, (1.0f - cmdColors.unitBox[1]) * 255, (1.0f - cmdColors.unitBox[2] * 255), cmdColors.unitBox[3] * 255}, }; va->AddVertexQC(verts[0], colors[0]); va->AddVertexQC(verts[1], colors[0]); va->AddVertexQC(verts[2], colors[0]); va->AddVertexQC(verts[3], colors[0]); if (globalRendering->drawdebug && (mhxsize != uhxsize || mhzsize != uhzsize)) { va->AddVertexQC(verts[4], colors[1]); va->AddVertexQC(verts[5], colors[1]); va->AddVertexQC(verts[6], colors[1]); va->AddVertexQC(verts[7], colors[1]); } } va->DrawArrayC(GL_QUADS); } // highlight queued build sites if we are about to build something // (or old-style, whenever the shift key is being held down) if (cmdColors.buildBox[3] > 0.0f) { if (!selectedUnits.empty() && ((cmdColors.BuildBoxesOnShift() && keyInput->IsKeyPressed(SDLK_LSHIFT)) || ((guihandler->inCommand >= 0) && (guihandler->inCommand < int(guihandler->commands.size())) && (guihandler->commands[guihandler->inCommand].id < 0)))) { GML_STDMUTEX_LOCK(cai); // Draw bool myColor = true; glColor4fv(cmdColors.buildBox); std::list<CBuilderCAI*>::const_iterator bi; for (bi = uh->builderCAIs.begin(); bi != uh->builderCAIs.end(); ++bi) { CBuilderCAI* builder = *bi; if (builder->owner->team == gu->myTeam) { if (!myColor) { glColor4fv(cmdColors.buildBox); myColor = true; } commandDrawer->DrawQuedBuildingSquares(builder); } else if (teamHandler->AlliedTeams(builder->owner->team, gu->myTeam)) { if (myColor) { glColor4fv(cmdColors.allyBuildBox); myColor = false; } commandDrawer->DrawQuedBuildingSquares(builder); } } } } glLineWidth(1.0f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); glDepthMask(true); glEnable(GL_TEXTURE_2D); }
void DebugDrawerAI::Graph::Draw() { static unsigned char color[4] = {0.75f * 255, 0.75f * 255, 0.75f * 255, 0.5f * 255}; CVertexArray* va = GetVertexArray(); { color[0] = 0.25f * 255; color[1] = 0.25f * 255; color[2] = 0.25f * 255; color[3] = 1.00f * 255; // label-box va->Initialize(); va->AddVertexC(pos, color); va->AddVertexC(pos + float3(-(((maxLabelWidth * 1.33f) / globalRendering->viewSizeX) * size.x), 0.0f, 0.0f), color); va->AddVertexC(pos + float3(-(((maxLabelWidth * 1.33f) / globalRendering->viewSizeX) * size.x), size.y, 0.0f), color); va->AddVertexC(pos + float3( 0.0f, size.y, 0.0f), color); va->DrawArrayC(GL_LINE_STRIP); if (scale.y > 0.0f && scale.x > 0.0f) { font->Begin(); font->SetTextColor(0.25f, 0.25f, 0.25f, 1.0f); // horizontal grid lines for (float s = 0.0f; s <= (scale.y + 0.01f); s += (scale.y * 0.1f)) { va->Initialize(); va->AddVertexC(pos + float3( 0.0f, (s / scale.y) * size.y, 0.0f), color); va->AddVertexC(pos + float3(size.x, (s / scale.y) * size.y, 0.0f), color); va->DrawArrayC(GL_LINES); const float tx = (pos.x + size.x) + (size.x * 0.025f); const float ty = pos.y + (s / scale.y) * size.y; font->glFormat(tx, ty, 1.0f, FONT_SCALE | FONT_NORM, "%2.1e", s + minScale.y); } // vertical grid lines for (float s = 0.0f; s <= (scale.x + 0.01f); s += (scale.x * 0.1f)) { va->Initialize(); va->AddVertexC(pos + float3((s / scale.x) * size.x, 0.0f, 0.0f), color); va->AddVertexC(pos + float3((s / scale.x) * size.x, size.y, 0.0f), color); va->DrawArrayC(GL_LINES); const float tx = (pos.x + (s / scale.x) * size.x) - (size.x * 0.05f); const float ty = pos.y - size.y * 0.1f; font->glFormat(tx, ty, 1.0f, FONT_SCALE | FONT_NORM, "%2.1e", s + minScale.x); } font->End(); } } { typedef std::map<int, Graph::GraphLine>::const_iterator LineIt; typedef std::list<float3>::const_iterator ListIt; if (!lines.empty()) { font->Begin(); int lineNum = 0; float linePad = (1.0f / lines.size()) * 0.5f; for (LineIt lit = lines.begin(); lit != lines.end(); ++lit) { const Graph::GraphLine& line = lit->second; const std::list<float3>& data = line.lineData; if (data.empty()) { continue; } // right-outline the labels const float sx = (maxLabelWidth / globalRendering->viewSizeX) * size.x; const float tx = pos.x - ((line.lineLabelWidth / maxLabelWidth) * 1.33f) * sx; const float ty = pos.y + ((lineNum * linePad * 2.0f) + linePad) * size.y; font->SetTextColor(line.lineColor.x, line.lineColor.y, line.lineColor.z, 1.0f); font->glPrint(tx, ty, 1.0f, FONT_SCALE | FONT_NORM, line.lineLabel); color[0] = line.lineColor.x * 255; color[1] = line.lineColor.y * 255; color[2] = line.lineColor.z * 255; color[3] = 255; glLineWidth(line.lineWidth); va->Initialize(); for (ListIt pit = data.begin(); pit != data.end(); ++pit) { ListIt npit = pit; ++npit; const float px1 = ((pit->x - minScale.x) / scale.x) * size.x; const float py1 = ((pit->y - minScale.y) / scale.y) * size.y; const float px2 = (npit == data.end()) ? px1 : ((npit->x - minScale.x) / scale.x) * size.x; const float py2 = (npit == data.end()) ? py1 : ((npit->y - minScale.y) / scale.y) * size.y; va->AddVertexC(pos + float3(px1, py1, 0.0f), color); va->AddVertexC(pos + float3(px2, py2, 0.0f), color); } va->DrawArrayC(GL_LINE_STRIP); glLineWidth(1.0f); lineNum += 1; } font->End(); } } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); }
void CSelectedUnitsHandler::Draw() { glDisable(GL_TEXTURE_2D); glDepthMask(false); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); // for line smoothing glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(cmdColors.UnitBoxLineWidth()); SColor color1(cmdColors.unitBox); SColor color2(cmdColors.unitBox); color2.r = 255 - color2.r; color2.g = 255 - color2.g; color2.b = 255 - color2.b; if (color1.a > 0) { const CUnitSet* unitSet; if (selectedGroup != -1) { // note: units in this set are not necessarily all selected themselves, eg. // if autoAddBuiltUnitsToSelectedGroup is true, so we check IsUnitSelected // for each unitSet = &grouphandlers[gu->myTeam]->groups[selectedGroup]->units; } else { unitSet = &selectedUnits; } CVertexArray* va = GetVertexArray(); va->Initialize(); va->EnlargeArrays(unitSet->size() * 8, 0, VA_SIZE_C); for (CUnitSet::const_iterator ui = unitSet->begin(); ui != unitSet->end(); ++ui) { const CUnit* unit = *ui; const MoveDef* moveDef = unit->moveDef; if (unit->isIcon) continue; if (!IsUnitSelected(unit)) continue; const int uhxsize = (unit->xsize * SQUARE_SIZE) >> 1, uhzsize = (unit->zsize * SQUARE_SIZE) >> 1, mhxsize = (moveDef == NULL)? uhxsize: ((moveDef->xsize * SQUARE_SIZE) >> 1), mhzsize = (moveDef == NULL)? uhzsize: ((moveDef->zsize * SQUARE_SIZE) >> 1); const float3 verts[8] = { // UnitDef footprint corners float3(unit->drawPos.x + uhxsize, unit->drawPos.y, unit->drawPos.z + uhzsize), float3(unit->drawPos.x - uhxsize, unit->drawPos.y, unit->drawPos.z + uhzsize), float3(unit->drawPos.x - uhxsize, unit->drawPos.y, unit->drawPos.z - uhzsize), float3(unit->drawPos.x + uhxsize, unit->drawPos.y, unit->drawPos.z - uhzsize), // MoveDef footprint corners float3(unit->drawPos.x + mhxsize, unit->drawPos.y, unit->drawPos.z + mhzsize), float3(unit->drawPos.x - mhxsize, unit->drawPos.y, unit->drawPos.z + mhzsize), float3(unit->drawPos.x - mhxsize, unit->drawPos.y, unit->drawPos.z - mhzsize), float3(unit->drawPos.x + mhxsize, unit->drawPos.y, unit->drawPos.z - mhzsize), }; va->AddVertexQC(verts[0], color1); va->AddVertexQC(verts[1], color1); va->AddVertexQC(verts[2], color1); va->AddVertexQC(verts[3], color1); if (globalRendering->drawdebug && (mhxsize != uhxsize || mhzsize != uhzsize)) { va->AddVertexQC(verts[4], color2); va->AddVertexQC(verts[5], color2); va->AddVertexQC(verts[6], color2); va->AddVertexQC(verts[7], color2); } } va->DrawArrayC(GL_QUADS); } // highlight queued build sites if we are about to build something // (or old-style, whenever the shift key is being held down) if (cmdColors.buildBox[3] > 0.0f) { if (!selectedUnits.empty() && ((cmdColors.BuildBoxesOnShift() && KeyInput::GetKeyModState(KMOD_SHIFT)) || ((guihandler->inCommand >= 0) && (guihandler->inCommand < int(guihandler->commands.size())) && (guihandler->commands[guihandler->inCommand].id < 0)))) { bool myColor = true; glColor4fv(cmdColors.buildBox); for (const auto bi: unitHandler->GetBuilderCAIs()) { const CBuilderCAI* builderCAI = bi.second; const CUnit* builder = builderCAI->owner; if (builder->team == gu->myTeam) { if (!myColor) { glColor4fv(cmdColors.buildBox); myColor = true; } commandDrawer->DrawQuedBuildingSquares(builderCAI); } else if (teamHandler->AlliedTeams(builder->team, gu->myTeam)) { if (myColor) { glColor4fv(cmdColors.allyBuildBox); myColor = false; } commandDrawer->DrawQuedBuildingSquares(builderCAI); } } } } glLineWidth(1.0f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); glDepthMask(true); glEnable(GL_TEXTURE_2D); }
static void DrawProfiler() { font->SetTextColor(1,1,1,1); CVertexArray* va = GetVertexArray(); CVertexArray* va2 = GetVertexArray(); // draw the background of the window if(!profiler.profile.empty()){ va->Initialize(); va->AddVertex0(start_x, end_y, 0); va->AddVertex0(end_x, end_y, 0); va->AddVertex0(start_x, end_y-profiler.profile.size()*0.024f-0.01f, 0); va->AddVertex0(end_x, end_y-profiler.profile.size()*0.024f-0.01f, 0); glColor4f(0.0f, 0.0f, 0.5f, 0.5f); va->DrawArray0(GL_TRIANGLE_STRIP); } std::map<std::string, CTimeProfiler::TimeRecord>::iterator pi; // draw the textual info (total-time, short-time percentual time, timer-name) int y = 0; for (pi = profiler.profile.begin(); pi != profiler.profile.end(); ++pi, ++y) { const float fStartY = start_y - y * 0.024f; float fStartX = start_x + 0.005f + 0.015f + 0.005f; // print total-time running since application start fStartX += 0.04f; font->glFormat(fStartX, fStartY, 0.7f, FONT_BASELINE | FONT_SCALE | FONT_NORM | FONT_RIGHT, "%.2fs", pi->second.total.toSecsf()); // print percent of CPU time used within the last 500ms fStartX += 0.04f; font->glFormat(fStartX, fStartY, 0.7f, FONT_BASELINE | FONT_SCALE | FONT_NORM | FONT_RIGHT, "%.2f%%", pi->second.percent * 100); fStartX += 0.04f; font->glFormat(fStartX, fStartY, 0.7f, FONT_BASELINE | FONT_SCALE | FONT_NORM | FONT_RIGHT, "\xff\xff%c%c%.2f%%", pi->second.newPeak?1:255, pi->second.newPeak?1:255, pi->second.peak * 100); fStartX += 0.04f; font->glFormat(fStartX, fStartY, 0.7f, FONT_BASELINE | FONT_SCALE | FONT_NORM | FONT_RIGHT, "\xff\xff%c%c%.0fms", pi->second.newLagPeak?1:255, pi->second.newLagPeak?1:255, pi->second.maxLag); // print timer name fStartX += 0.01f; font->glFormat(fStartX, fStartY, 0.7f, FONT_BASELINE | FONT_SCALE | FONT_NORM, pi->first); } // draw the Timer selection boxes glPushMatrix(); glTranslatef(start_x + 0.005f, start_y, 0); glScalef(0.015f, 0.02f, 0.02f); va->Initialize(); va2->Initialize(); int i = 0; for (pi = profiler.profile.begin(); pi != profiler.profile.end(); ++pi, ++i){ auto& fc = pi->second.color; SColor c(fc[0], fc[1], fc[2]); va->AddVertexC(float3(0, 0 - i * 1.2f, 0), c); va->AddVertexC(float3(1, 0 - i * 1.2f, 0), c); va->AddVertexC(float3(1, 1 - i * 1.2f, 0), c); va->AddVertexC(float3(0, 1 - i * 1.2f, 0), c); if (!pi->second.showGraph) { va2->AddVertex0(0, 0 - i * 1.2f, 0); va2->AddVertex0(1, 1 - i * 1.2f, 0); va2->AddVertex0(1, 0 - i * 1.2f, 0); va2->AddVertex0(0, 1 - i * 1.2f, 0); } } // draw the boxes va->DrawArrayC(GL_QUADS); // draw the 'graph view disabled' cross glColor3f(1,0,0); va2->DrawArray0(GL_LINES); glPopMatrix(); // draw the graph glLineWidth(3.0f); for (pi = profiler.profile.begin(); pi != profiler.profile.end(); ++pi) { if (!pi->second.showGraph) { continue; } va->Initialize(); const float steps_x = (end_x - start_x) / CTimeProfiler::TimeRecord::frames_size; for (size_t a=0; a < CTimeProfiler::TimeRecord::frames_size; ++a) { // profile runtime; eg 0.5f means: uses 50% of a CPU (during that frame) // This may be more then 1.0f, in case an operation // which ran over many frames, ended in this one. const float p = pi->second.frames[a].toSecsf() * GAME_SPEED; const float x = start_x + (a * steps_x); const float y = 0.02f + (p * 0.96f); va->AddVertex0(x, y, 0.0f); } glColorf3((float3)pi->second.color); va->DrawArray0(GL_LINE_STRIP); } glLineWidth(1.0f); }
static void DrawProfiler() { font->SetTextColor(1,1,1,1); // draw the background of the window { CVertexArray* va = GetVertexArray(); va->Initialize(); va->AddVertex0(start_x, start_y + lineHeight + 0.005f, 0); va->AddVertex0(end_x, start_y + lineHeight + 0.005f, 0); va->AddVertex0(start_x, start_y - profiler.profile.size() * lineHeight - 0.01f, 0); va->AddVertex0(end_x, start_y - profiler.profile.size() * lineHeight - 0.01f, 0); glColor4f(0.0f, 0.0f, 0.5f, 0.5f); va->DrawArray0(GL_TRIANGLE_STRIP); } const float textSize = 0.5f; // table header { const float fStartY = start_y + 0.005f; float fStartX = start_x + 0.005f + 0.015f + 0.005f; // print total-time running since application start fStartX += 0.04f; font->glFormat(fStartX, fStartY, textSize, FONT_SHADOW | FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "totaltime"); // print percent of CPU time used within the last 500ms fStartX += 0.06f; font->glFormat(fStartX, fStartY, textSize, FONT_SHADOW | FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "cur-%%usage"); fStartX += 0.04f; font->glFormat(fStartX, fStartY, textSize, FONT_SHADOW | FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "max-%%usage"); fStartX += 0.04f; font->glFormat(fStartX, fStartY, textSize, FONT_SHADOW | FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "lag"); // print timer name fStartX += 0.01f; font->glFormat(fStartX, fStartY, textSize, FONT_SHADOW | FONT_DESCENDER | FONT_SCALE | FONT_NORM, "title"); } // draw the textual info (total-time, short-time percentual time, timer-name) int y = 1; for (auto pi = profiler.profile.begin(); pi != profiler.profile.end(); ++pi, ++y) { const auto& profileData = pi->second; const float fStartY = start_y - y * lineHeight; float fStartX = start_x + 0.005f + 0.015f + 0.005f; // print total-time running since application start fStartX += 0.04f; font->glFormat(fStartX, fStartY, textSize, FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "%.2fs", profileData.total.toSecsf()); // print percent of CPU time used within the last 500ms fStartX += 0.06f; font->glFormat(fStartX, fStartY, textSize, FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "%.2f%%", profileData.percent * 100); fStartX += 0.04f; font->glFormat(fStartX, fStartY, textSize, FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "\xff\xff%c%c%.2f%%", profileData.newPeak?1:255, profileData.newPeak?1:255, profileData.peak * 100); fStartX += 0.04f; font->glFormat(fStartX, fStartY, textSize, FONT_DESCENDER | FONT_SCALE | FONT_NORM | FONT_RIGHT, "\xff\xff%c%c%.0fms", profileData.newLagPeak?1:255, profileData.newLagPeak?1:255, profileData.maxLag); // print timer name fStartX += 0.01f; font->glFormat(fStartX, fStartY, textSize, FONT_DESCENDER | FONT_SCALE | FONT_NORM, pi->first); } // draw the Timer selection boxes const float boxSize = lineHeight*0.9; const float selOffset = boxSize*0.2; glPushMatrix(); glTranslatef(start_x + 0.005f, start_y + boxSize, 0); // we are now at upper left of first box CVertexArray* va = GetVertexArray(); CVertexArray* va2 = GetVertexArray(); va->Initialize(); va2->Initialize(); int i = 1; for (auto pi = profiler.profile.begin(); pi != profiler.profile.end(); ++pi, ++i){ auto& fc = pi->second.color; SColor c(fc[0], fc[1], fc[2]); va->AddVertexC(float3(0, -i*lineHeight, 0), c); // upper left va->AddVertexC(float3(0, -i*lineHeight-boxSize, 0), c); // lower left va->AddVertexC(float3(boxSize, -i*lineHeight-boxSize, 0), c); // lower right va->AddVertexC(float3(boxSize, -i*lineHeight, 0), c); // upper right if (pi->second.showGraph) { va2->AddVertex0(lineHeight+selOffset, -i*lineHeight-selOffset, 0); // upper left va2->AddVertex0(lineHeight+selOffset, -i*lineHeight-boxSize+selOffset, 0); // lower left va2->AddVertex0(lineHeight+boxSize-selOffset, -i*lineHeight-boxSize+selOffset, 0); // lower right va2->AddVertex0(lineHeight+boxSize-selOffset, -i*lineHeight-selOffset, 0); // upper right } } // draw the boxes va->DrawArrayC(GL_QUADS); // draw the 'graph view disabled' cross glColor3f(1,0,0); va2->DrawArray0(GL_QUADS); glPopMatrix(); // draw the graph glLineWidth(3.0f); for (auto pi = profiler.profile.begin(); pi != profiler.profile.end(); ++pi) { if (!pi->second.showGraph) { continue; } CVertexArray* va = GetVertexArray(); va->Initialize(); const float steps_x = (end_x - start_x) / CTimeProfiler::TimeRecord::frames_size; for (size_t a=0; a < CTimeProfiler::TimeRecord::frames_size; ++a) { // profile runtime; eg 0.5f means: uses 50% of a CPU (during that frame) // This may be more then 1.0f, in case an operation // which ran over many frames, ended in this one. const float p = pi->second.frames[a].toSecsf() * GAME_SPEED; const float x = start_x + (a * steps_x); const float y = 0.02f + (p * 0.96f); va->AddVertex0(x, y, 0.0f); } glColorf3((float3)pi->second.color); va->DrawArray0(GL_LINE_STRIP); } glLineWidth(1.0f); }