操纵GL

编程入门 行业动态 更新时间:2024-10-25 08:25:36
操纵GL_LINE_STRIP中的行(manipulating lines in a GL_LINE_STRIP)

我正在制作一个简单的2d绘图程序,其中我有一个顶点数组(比如a1,a2,a3,.....),这些顶点将使用GL_LINE_STRIP绘制。问题是,有3个连续顶点:p1 ,p2,p3,现在我想要if(p2 ==某个特定的顶点值),那么GL_LINE_STRIP应该在p1结束,新的GL_LINE_STRIP从p3开始,忽略p2。 我想在地带的p2休息一下。 我怎么做?? PS:我尝试在线条的循环中在p2处线宽= 0,但发现由于opengl是一个状态机,我们无法改变glBegin和GLEnd中的宽度。任何其他替代球员???

这里有一些失败的示例代码:

GLfloat thickness; glBegin(GL_LINE_STRIP); for(int i = 0; i < points.size(); i++)//points has all vertices stored...points is an array where each element is a structure containing x and y values { if(points[i].x==randomPoint.x || points[i-1].x==randomPoint.x){//checking if it is equal to p2(i am only checking x coordinate,which is sufficient for me to know that this point is to be excluded) thickness = 0; }else { thickness = 4; } glLineWidth(thickness); glVertex2i(points[i].x, points[i].y); }

I am making a simple 2d drawing program in which i have an array of vertices(say a1,a2,a3,.....) which is to be drawn using GL_LINE_STRIP .Problem is that , say there are 3 consecutive vertices : p1, p2, p3, now i want that if (p2==some specfic vertex value) then the GL_LINE_STRIP should end at p1 and a new GL_LINE_STRIP start at p3, ignoring p2. I want to make a break at p2 in the strip. How do i do that?? PS: I tried making (line width = 0 at p2 in the loop of line strip but found out that since opengl is a state machine, we cant change width inside glBegin and GLEnd. any other alternative guys???

HERE IS SOME FAILED SAMPLE CODE:

GLfloat thickness; glBegin(GL_LINE_STRIP); for(int i = 0; i < points.size(); i++)//points has all vertices stored...points is an array where each element is a structure containing x and y values { if(points[i].x==randomPoint.x || points[i-1].x==randomPoint.x){//checking if it is equal to p2(i am only checking x coordinate,which is sufficient for me to know that this point is to be excluded) thickness = 0; }else { thickness = 4; } glLineWidth(thickness); glVertex2i(points[i].x, points[i].y); }

最满意答案

如果我有正确的问题,你想要在一个顶点停止线条,如果它是一个特定的值,并在下一个顶点开始一个新的。 (如果我误解了,请纠正我)

在要连接的最后一个顶点之后调用glEnd() ,并在想要启动新条带时启动新的glBegin() 。

至于宽度部分,您必须在调用glBegin()之前设置宽度。 如你所说,一条线条(afaik)不能让它的宽度在绘制状态下改变。 您必须结束绘制调用,更改宽度,返回1个顶点并开始新的绘制调用。

If I've got the question right you want to stop the linestrip at a vertex if it is a specific value, and start a new one on the next vertex. (Correct me if I've misunderstood)

Call glEnd() after the last vertex you want to connect and start a new glBegin() when you want to start a new strip.

As for the width part you would have to set the width before the call to glBegin(). A linestrip (afaik) can not have it's width changed in a draw state as you say. You would have to end the draw call, change the width, go 1 vertex back and start a new draw call.

更多推荐

本文发布于:2023-08-07 11:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!