c++ - OpenGL – Severe distortions even with correct matrices -
my simple opengl program displaying severely distorted shape. i'm using glm matrix math. compared modelview matrix , projection matrix values program displaying values correctly. yet, still distorted. cause? here matrix code:
modelviewmatrix = glm::lookat(glm::vec3(3.0f, 5.0f, 7.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); projectionmatrix = glm::perspective(glm::radians(45.0f), (float)height/(float)width, 0.01f, 100.0f);
and here vertex shader code:
#version 300 es in mediump vec3 vertexposition; uniform mediump mat4 modelviewmatrix; uniform mediump mat4 projectionmatrix; out vec3 finalposition; void main(void) { gl_position = projectionmatrix * modelviewmatrix * vec4(vertexposition, 1.0); }
here screenshots of (unlit) cuboid:
note correct image black one. both using exact same shader , same model view , projection matrix numbers. why happening?
i believe aspect ratio being calculated incorrectly - should width / height.
you have:
projectionmatrix = glm::perspective(glm::radians(45.0f), (float)height/(float)width, 0.01f, 100.0f);
try replacing with:
projectionmatrix = glm::perspective(glm::radians(45.0f), (float)width/(float)height, 0.01f, 100.0f);
Comments
Post a Comment