# glm::lookat upside down

I’m trying to create my projection and view matrices using glm’s lookat and perspective function but can’t figure out why it ends up upside down.

Here’s the drawing code

``````    void draw(float dt)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

auto size = window->getSize();
glm::mat4 view = glm::lookAt(glm::vec3(0.0, 0.0, 10.0), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
glm::mat4 proj = glm::perspective(100.0f, (float)size.x / (float)size.y, 1.0f, 100.0f);

glBegin(GL_TRIANGLES);

glVertex3f(-10, -10, 0);
glVertex3f(10, -10, 0);
glVertex3f(0, 10, 0);

glEnd();

window->swapBuffers();
}
``````

``````#version 130

uniform mat4 mvp;
in vec3 a_Vertex;
in vec4 a_Color;
out vec4 color;

void main(void)
{
color = a_Color;
gl_Position = mvp * vec4(a_Vertex, 1.0);
}

``````

The output of that code looks like this:

[ATTACH=CONFIG]1338[/ATTACH]

Changing the glm::lookat line to have a negative y axis up vector like:

``````glm::mat4 view = glm::lookAt(glm::vec3(0.0, 0.0, 10.0), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0));
``````

solves the problem but it doesn’t make sense to me why the original code is upside down.

[QUOTE=sixtyonetwo;1280834]I’m trying to create my projection and view matrices using glm’s lookat and perspective function but can’t figure out why it ends up upside down.

Here’s the drawing code

``````
glm::mat4 proj = glm::perspective(100.0f, (float)size.x / (float)size.y, 1.0f, 100.0f);

``````

[/QUOTE]
You’re requesting a field-of-view of 100 radians, which is around 5730 degrees. Modulo 360, that’s 330 degrees, i.e. +/- 165 degrees, which is more than 90 degrees. This results in cotan(fovy/2) being negative, resulting in the X and Y scale factors being negative, which is equivalent to rotation by 180 degrees about the centre of the viewport.

Aha! Thanks a bunch, always forget things being in radians.