OpenGL/Android -- 设置与屏幕像素匹配的 2D OpenGL 正交坐标系

发布于 2024-11-03 20:24:45 字数 667 浏览 1 评论 0原文

我正在尝试使用适用于 Android 的 OpenGL ES 1.5 在屏幕上绘制一些圆圈。他们绘制,但我希望能够输入 x=300,y=500,它将绘制以该坐标为中心的圆(例如,在屏幕上的 (300,500) 像素处)。目前,我绘制并翻译了圆圈,但它不精确,我不知道如何将其精确地放在我想要的位置:这是我上次尝试的一些损坏的代码:

//doesn't take w/h ratio into consideration, not sure how to implement that
gl.glViewport(0, 0, windowWidth, windowHeight);
gl.glOrthof(0,windowWidth,   0, windowHeight,    1, 2);
GLU.gluLookAt(gl,   0, 0, 5,    0, 0, 0,    0, 1, 0);

//And for drawing a circle, with the desired x and y coordinates:
for (int j = 0; j &lt number_Triangles; j++) {
  x = Math.cos(theta) + xCoor;
  y = Math.sin(theta) + yCoor;
  z = 1;
 theta += 2 * Math.PI / (number_Triangles);
}

I am trying to get some circles drawn onscreen using OpenGL ES 1.5 for android. They draw, but I want to be able to input x=300, y=500, and it will draw the circle centered at that coordinate (e.g. at the (300,500) pixel on the screen). Currently, I draw and translate the circles, but its not precise, I don't know how to get it exactly where i want it: here's some broken code from my last attempt:

//doesn't take w/h ratio into consideration, not sure how to implement that
gl.glViewport(0, 0, windowWidth, windowHeight);
gl.glOrthof(0,windowWidth,   0, windowHeight,    1, 2);
GLU.gluLookAt(gl,   0, 0, 5,    0, 0, 0,    0, 1, 0);

//And for drawing a circle, with the desired x and y coordinates:
for (int j = 0; j < number_Triangles; j++) {
  x = Math.cos(theta) + xCoor;
  y = Math.sin(theta) + yCoor;
  z = 1;
 theta += 2 * Math.PI / (number_Triangles);
}

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

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

发布评论

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

评论(1

懵少女 2024-11-10 20:24:45

如果你正在做 2D 图形,我推荐 gluOrtho2D(left,right,bottom,top)。这样您就可以精确控制映射到屏幕每个边缘的坐标。

因此,例如,您可以:

gl.glViewport(0,0,windowWidth,windowHeight);
GLU.gluOrtho2D(-2.0f, 2.0f, -2.0f, 2.0f);

对于 (int j = .....

If you are doing 2D graphics, I'd recommend gluOrtho2D(left,right,bottom,top). That way you have exact control over what coordinates will map to each edge of your screen.

So, for example, you could have:

gl.glViewport(0,0,windowWidth,windowHeight);
GLU.gluOrtho2D(-2.0f, 2.0f, -2.0f, 2.0f);

for (int j = .....

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