使用 openGL es 2.0 和 iPhone 触摸屏画线

发布于 2024-12-20 01:42:19 字数 226 浏览 2 评论 0原文

这是我之前发布的问题的超级简单版本(我认为太复杂)

如何在 OpenGL ES 2.0 中使用触摸屏上的笔划作为参考来绘制一条线?

例如,如果我用手指在屏幕上绘制一个正方形,我希望使用 OpenGL 在屏幕上绘制它。

我尝试了很多研究,但到目前为止还没有运气。

(我现在只知道如何绘制已经具有固定顶点数组的对象,不知道如何绘制具有不断变化的数组的对象,也不知道如何实现它)

This is the super simple version of the question I posted earlier (Which I think is too complicated)

How do I draw a Line in OpenGL ES 2.0 Using as a reference a stroke on the Touch Screen?

For example If i draw a square with my finger on the screen, i want it to be drawn on the screen with OpenGL.

I have tried researching a lot but no luck so far.

(I only now how to draw objects which already have fixed vertex arrays, no idea of how to draw one with constantly changing array nor how to implement it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-12-27 01:42:19

您应该使用顶点缓冲区对象 (VBO) 作为顶点数据的支持 OpenGL 结构。然后,手势必须转换为一系列位置(我不知道这在你的平台上是如何发生的)。如果现有 VBO 足够大,则必须使用 glBufferSubData 将这些位置推送到 VBO;如果现有 VBO 太小,则必须使用 glBufferData 将这些位置推送到 VBO。

使用 VBO 绘制线条或任何其他 OpenGL 形状很容易,并且有许多教程可以完成它。

更新

根据您的其他问题,您似乎已经快到了!您已经像我提到的那样创建了 VBO,但它们可能不够大。当前大小为 sizeof(Vertices),如 glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); 中指定的

大小,您需要将指定给 glBufferData 的大小更改为某个值足够大以容纳所有原始顶点+后来添加的顶点。您还应该使用GL_STREAM作为最后一个参数(阅读该函数)。

要添加新顶点,请使用类似以下内容:

glBufferSubData(GL_ARRAY_BUFFER, current_nb_vertices*3*sizeof(float), nb_vertices_to_add, newVertices);
current_nb_vertices += nb_vertices_to_add;
//...
// drawing lines
glDrawArrays(GL_LINE_STRIP, 0, current_nb_vertices);

您不需要元素数组中的索引来绘制线条。

You should use vertex buffer objects (VBOs) as the backing OpenGL structure for your vertex data. Then, the gesture must be converted to a series of positions (I don't know how that happens on your platform). These positions must then be pushed to the VBO with glBufferSubData if the existing VBO is large enough or glBufferData if the existing VBO is too small.

Using VBOs to draw lines or any other OpenGL shape is easy and many tutorials exist to accomplish it.

update

Based on your other question, you seem to be almost there! You already create VBOs like I mentioned but they are probably not large enough. The current size is sizeof(Vertices) as specified in glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

You need to change the size given to glBufferData to something large enough to hold all the original vertices + those added later. You should also use GL_STREAM as the last argument (read up on the function).

To add a new vertex, use something like this :

glBufferSubData(GL_ARRAY_BUFFER, current_nb_vertices*3*sizeof(float), nb_vertices_to_add, newVertices);
current_nb_vertices += nb_vertices_to_add;
//...
// drawing lines
glDrawArrays(GL_LINE_STRIP, 0, current_nb_vertices);

You don't need the indices in the element array to draw lines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文