开发者

OpenGL: Triangles with points at infinity

开发者 https://www.devze.com 2023-01-20 21:06 出处:网络
I am trying to render a two-dimensional half-plane in OpenGL with the following code: void renderHalfplane(double *x, double *n)

I am trying to render a two-dimensional half-plane in OpenGL with the following code:

void renderHalfplane(double *x, double *n)
{
  glPushMatrix();
  double theta = -360.0 * atan2(n[0], n[1])/(2.0*PI);

  glTranslated(x[0], x[1], 0);
  glRotated(theta, 0, 0, 1.0);

  glBegin(GL_TRIANGLES);
  glVertex4d(0.0, 0.0, 0.0, 1.0);
  glVertex4d(1.0, 0.0, 0.0, 0.0);
  glVertex4d(0.0,-1.0, 0.0, 0.0);
  glVertex4d(0.0, 0.0, 0.0, 1,0);
  glVertex4d(-1.0,0.0, 0.0, 0.0);
  glVertex4d(0.0,-1.0, 0.0, 0.0);
  glEnd();

  glPopMatrix();
}

Here I'm using homogeneous coordinates to draw triangles with two vertices at "infinity."

This code works like a charm开发者_开发知识库 on my computer, but a user is reporting that it doesn't render correctly on theirs: instead of an infinite half-plane they are seeing two (finite) triangles.

Is my use of w-coordinate 0 undefined behavior? Is it something that only works on some versions of OpenGL? I tried looking through the Khronos OpenGL specs but couldn't find a section where rendering of primitives with w-coordinate 0 was addressed.


I tested this on my machine(nVidia Quadro) and it renders correctly. I've found code samples (for shadow volumes) that scales the W coordinate to infinity that work fine also.

I'm going to guess it's a driver issue or something external to this code?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号