有没有更好的办法做到这一点?这一点、办法

2023-09-11 05:09:31 作者:卌蒢ゞ汜忔

我绘制2D,凹,有时multicontoured,有时可自行相交多边形的OpenGL。 下面是一个例子:

I'm drawing 2D, concave, sometimes multicontoured, sometimes self intersecting polygons with OpenGL. Here is a sample:

现在,我把它连接是否会导致多边形的轮廓点。然后,我把这些进入GLUTesselator,其中三角形出来。然后,我让纹理坐标和纹理的多边形。

Right now, I take the points which if connected would result in the polygon's outline. Then I put these into the GLUTesselator where triangles come out. I then make texture coordinates and texture the polygon.

绝对最慢的组件是细分/三角。由于我只需要画出这些,你看,有什么更快的替代三角?我能否找到一个画画的算法,将设置适当的像素?

The absolute slowest component is the tessellation / triangulation. Given that I just need to draw these as you see, what are faster alternatives to triangulating? Could I possibly find a painting algorithm that would set the pixel appropriately?

感谢

推荐答案

首先一个简单的问题:假设你只是想用一种颜色。你可以先从轮廓的列表,然后通过行和列扫描整个窗口:当你越过边界,你会增加或减少(取决于交叉的意义上)的反 how_many_outlines_am_I_inside 。当它是零,油漆像素白色的,否则它漆成绿色(我猜黑色的边界本身)。这将正确处理自相交的曲线。

First a simpler problem: suppose you just wanted to use one color. You could start with the list of outlines, then scan the whole window by row and column: whenever you crossed a boundary, you would increment or decrement (depending on the sense of the crossing) a counter how_many_outlines_am_I_inside. When it's zero, paint the pixel white, otherwise paint it green (and I guess black for the boundary itself). This will handle self-intersecting curves correctly.

现在的色调。通过你的例子来看,着色均匀垂直,但水平的变化,调整为轮廓的宽度。而不是一个简单的计数器所以,你需要一个堆栈(我建议STL ::名单)轮廓,这样就可以跟踪其轮廓(的那些你在里面)是最上面,这样就可以计算出哪一部分你从x 已经覆盖距离的最小为x 最大。最后为半透明(与星通过矩形部分可见):你必须自己决定的规则,我不能眼球推断出,但堆栈应该可以很容易地实现

Now for the shades. Judging by your example, shading is uniform vertically, but changes horizontally, scaled to the full width of the outline. So instead of a simple counter, you'll need a stack (I recommend stl::list) of outlines, so that you can keep track of which outline (of the ones you're inside) is uppermost, so that you can calculate what fraction of the distance you've covered from xmin to xmax. Finally for the translucency (as with the star partly visible through the rectangle): you'll have to decide on the rules yourself, I can't infer them by eyeball, but the stack should make it easy to implement.

想一些帮助与C ++ code?

Want some help with the C++ code?