Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Triangles with points at infinity

Tags:

c++

opengl

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.

like image 334
user168715 Avatar asked Nov 15 '22 06:11

user168715


1 Answers

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?

like image 147
Ron Warholic Avatar answered Nov 16 '22 22:11

Ron Warholic