(OpenGL iOS) 在 X 和 Y 坐标中移动时,原始形状 (2D) 扭曲 (GL_TRIANGLE_STRIP)

发布于 2024-12-28 23:03:17 字数 828 浏览 2 评论 0原文

当我通过 x 和 y 坐标移动图元时,我得到了这个奇怪的扭曲的图元形状(而不是正方形)。

这是一个快照: http://img535.imageshack.us/img535/9046/screenshot20120126at122.png

我正在使用正交投影,因为我想以 2D 渲染。

这是渲染代码:

//vertex definition
static GLfloat qdt[] = {
    30.0f, 60.0f, -0.03f,
    30.0f, 30.0f, -0.03f,
    60.0f, 60.0f, -0.03f,
    60.0f, 30.0f, -0.03f
};

//clear buffers
glClear(GL_COLOR_BUFFER_BIT);// also tried using GL_DEPTH_BUFFER_BIT

//load matrices
glLoadIdentity();

//drawing
glVertexPointer(3, GL_FLOAT, 0, &qdt[0]);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 12);

//swap buffers
[glContext presentRenderbuffer:GL_RENDERBUFFER_OES];

我也禁用了深度缓冲区。 如果有人指出导致这种扭曲的错误,那就太好了。 提前致谢。

I get this strange distorted primitive shape (instead of a square) when i move the primitive through the x and y co-ordinates.

Here is a snapshot:
http://img535.imageshack.us/img535/9046/screenshot20120126at122.png

I'm using orthogonal projection since i want to render in 2D.

Here is the render code:

//vertex definition
static GLfloat qdt[] = {
    30.0f, 60.0f, -0.03f,
    30.0f, 30.0f, -0.03f,
    60.0f, 60.0f, -0.03f,
    60.0f, 30.0f, -0.03f
};

//clear buffers
glClear(GL_COLOR_BUFFER_BIT);// also tried using GL_DEPTH_BUFFER_BIT

//load matrices
glLoadIdentity();

//drawing
glVertexPointer(3, GL_FLOAT, 0, &qdt[0]);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 12);

//swap buffers
[glContext presentRenderbuffer:GL_RENDERBUFFER_OES];

I've disabled the depth buffers too.
It would be nice if someone points out the mistakes which is causing this distortion.
Thanks in advance.

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

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

发布评论

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

评论(1

讽刺将军 2025-01-04 23:03:17

将 12 替换为 4,因为您绘制了 4 个顶点:

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Replace 12 by 4, because you draw 4 vertices:

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