当前位置: 首页>>代码示例>>C++>>正文


C++ GEdge::currentX方法代码示例

本文整理汇总了C++中GEdge::currentX方法的典型用法代码示例。如果您正苦于以下问题:C++ GEdge::currentX方法的具体用法?C++ GEdge::currentX怎么用?C++ GEdge::currentX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GEdge的用法示例。


在下文中一共展示了GEdge::currentX方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: shadeDevicePolygon

void MyCanvas::shadeDevicePolygon(std::vector<GEdge>& Edges, GShader* shader)
{
  assert(shader != nullptr);
  if (Edges.size() < 2)
  {
    //printf("Error: ShadeDevicePolygon needs at least 2 edges to draw\n");
    return;
  }

  // Sort the edges from top to bottom, left to right
  std::sort(Edges.begin(), Edges.end());

  // The first two edges will be the top most edges
  GEdge LeftEdge = Edges[0];
  GEdge RightEdge = Edges[1];

  // Get start of pixel address for bitmap and offset to the top row 
  GPixel *DstPixels = (GPixel*)((char*)Bitmap.pixels() + Bitmap.fRowBytes * LeftEdge.top());

  // Set the context in the shader to the CTM
  float TwoRows[6];
  CTM.GetTwoRows(TwoRows);
  shader->setContext(TwoRows);
  
  int EdgeCounter = 2;
  for (int y = LeftEdge.top(); y < Edges.back().bottom(); ++y)
  {
    int startX = Utility::round(LeftEdge.currentX());
    int count = (int)(RightEdge.currentX() - LeftEdge.currentX());

    count = Utility::clamp(1, count, BmpRect.width() - 1);

    /* Allocate a row of pixels to calculate shader pixel values
     * then blend shader pixels into the dst bitmap */
    GPixel *row = new GPixel[count];
    shader->shadeRow(startX, y, count, row);
    blendRow(DstPixels, startX, row, count);
    delete[] row;  

    // Move currentX of the left and right edges to the next row
    LeftEdge.moveCurrentX(1.0f);
    RightEdge.moveCurrentX(1.0f);

    // Check left and right edge for y has passed bottom, if we have edges left then set the next edge
    if (y >= LeftEdge.bottom() && EdgeCounter < Edges.size())
    {
      LeftEdge = Edges[EdgeCounter];
      ++EdgeCounter;
    }
    if (y >= RightEdge.bottom() && EdgeCounter < Edges.size())
    {
      RightEdge = Edges[EdgeCounter];
      ++EdgeCounter;
    }

    DstPixels = (GPixel*)((char*)DstPixels + Bitmap.fRowBytes);
  }
}
开发者ID:dowoncha,项目名称:2D-Graphics-Engine,代码行数:58,代码来源:MyCanvas.cpp


注:本文中的GEdge::currentX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。