Search code examples
openglglm-math

using glm::ortho projection in OpenGL


I'm trying to simulate dropping a ball from 200 meters. I know I have to convert the coordinates from -1.0, 1.0 to 0, 200.

I draw my vertices of my ball like so:

for(int i=0; i < NUM_VERTICES; i++)
{
  GLfloat angle = 2*M_PI/NUM_VERTICES * i;

  GLfloat x = 10 * cos(angle);
  GLfloat y = 10 * sin(angle);

  vertices.push_back(x);
  vertices.push_back(y);
}  

then I have an orthographic projection like so:

glm:mat4 projection;
projection = glm::ortho(0.0f, 200.0f, 0.0f, 200.0f, 0.1f, 100.0f);

and a translation

glm::mat4 view;
view = glm::translate(view, glm::vec3(100.0f, 200.0f, 0.0f));

but nothing appears in my viewport.


Solution

  • You seem to draw at z=0, while your z range is [-0.1, -100], so the geometry is clipped because it lies in front of the near plane.