使用纹理渲染抗锯齿线 =>寻找非常简单的例子
有 这个网站...
...他们解释了如何绘制抗锯齿线。
正是我想要的!
但是...
我不明白如何通过简单的线条来实现这一点。我找到了这本书的在线版本(这篇文章是从这本书中衍生出来的),我已经下载了示例代码(显示了一个简笔画做花哨的动作),但是有太多的曼波詹博正在发生......一些奇怪的python脚本...循环为png图像和头文件,几乎所有内容都是用cpp编写的,我复制到项目的文件会产生很多我无法正确解决的错误等等。我想我不需要所有这些花哨的东西,因为我只想在一个简单的基于 cocos2d 的应用程序中画线 [顺便说一句....我不想使用 AA,但我的线比 5px 粗,这使它们在连接时有难看的孔(fe 在由几条线组成的圆圈中),因此我必须使用 AA,因为看起来]。
那么,是否有人拥有或找到了一小段使用链接文章中解释的原理的可运行示例代码?
注释:
在图片中您可以看到孔:
http://pimml.de/circles.png在这里您可以找到以下代码提到火柴人(AA线):http://examples.oreilly.com/9780596804831/readme .html#AaLines
这就是我画圆圈的方式:
int 段 = 80; CGFloat 宽度 = 100; CG浮动高度 = 100; CG点中心 = ccp(800,200); glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); //gl启用(GL_LINE_SMOOTH); // 不适用于设备 glTranslatef(center.x, center.y, 0.0); glLineWidth(3.0f); GLfloat 顶点[段*2]; 整数计数=0; for (GLfloat i = 0; i < 360.0f; i+=(360.0f/段)) { 顶点[count++] = (cos( DegreesToRadian(i))*width); 顶点[count++] = (sin( DegreesToRadian(i))*height); } glVertexPointer (2, GL_FLOAT , 0, 顶点); glDrawArrays(GL_LINE_LOOP, 0, 段); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D);
There is this site...
... where they explain how to draw an antialiased line.
Exactly what I want!
but...
I don't understand how to achieve that for a simple line. I have found the online version of the book (the article is kind of derived from the book), i have downloaded the sample code (showing a stick figure doing fancy moves), but there is so much mambojambo going on... some strange python script... circles as png-images and as header files, almost everything is written in cpp, files i copy to my project produce lots of errors that i can't resolve properly and so on and so on. And I think I don't need all of that fancy stuff, since I only want to draw lines in a simple cocos2d based app [Btw.... I didn't want to use AA, but my lines are thicker than 5px which makes them have ugly holes when connected (f.e. in a circle made of several lines) so that I must use AA as it seems].
So does someone have or found a tiny little piece of runnable sample code using the principle explained in the linked article ?
Notes:
In the picture you see the holes:
http://pimml.de/circles.pngHere you will find the code of the mentioned stickman (AA Lines): http://examples.oreilly.com/9780596804831/readme.html#AaLines
This is how I draw my circles:
int segments = 80; CGFloat width = 100; CGFloat height = 100; CGPoint center = ccp(800,200); glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); //glEnable(GL_LINE_SMOOTH); // doesn't work on device glTranslatef(center.x, center.y, 0.0); glLineWidth(3.0f); GLfloat vertices[segments*2]; int count=0; for (GLfloat i = 0; i < 360.0f; i+=(360.0f/segments)) { vertices[count++] = (cos(degreesToRadian(i))*width); vertices[count++] = (sin(degreesToRadian(i))*height); } glVertexPointer (2, GL_FLOAT , 0, vertices); glDrawArrays (GL_LINE_LOOP, 0, segments); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢 Paul Haeberli,以下是他与我分享的一些用于绘制抗锯齿框、点和线的代码:
Thanks to Paul Haeberli, here is some code he shared with me for drawing antialiased boxes, points, and lines:
我也遇到了这个问题。我花了一段时间才弄清楚这个问题...我使用了与此类似的解决方案一段时间(通过 Apple.com 上的 walterBenjamin):
https://devforums.apple.com/message/264670
这有效,很简单,看起来不错,但它仍然不是最好的(对于我正在做的事情)。最后我写了自己的解决方案,将GL Paint粒子绘制和他的点对点线条绘制解决方案结合起来。
我创建了一个数组,并在 attemptsBegin、touchesMoved 处添加了一个点:
[currentStroke addObject:[NSValue valueWithCGPoint:point]]
然后我迭代笔划,就像您在 GL Paint 中看到的那样GL_Points。
I ran into that issue as well. I spent a while figuring this out... I used a solution similar to this one for a while (via walterBenjamin on Apple.com):
https://devforums.apple.com/message/264670
This works, it is easy and it looks nice, but it still isn't the best (for what I am doing). In the end, I wrote my own solution that combined GL Paint particle drawing with his solution of point-to-point line drawing.
I made an array and at touchesBegin, touchesMoved, I added a point to it:
[currentStroke addObject:[NSValue valueWithCGPoint:point]]
Then I iterate through the strokes, such as you see in GL Paint using GL_Points.
也许你可以看到这个。
我从该链接解决了 opengl-es 的问题。
Maybe you can see this.
I resolve the problem from that link for opengl-es.