I try to render a simple grid using glBegin(GL_LINES). I have a class Camera, which provides values like this:

float farPlane = 100.0f;
float nearPlane= 0.1f;

float screenRatio = 1,42857; //width/height = 1000/700
float frustum = 70.0f;

glm::vec3 position = glm::vec3(3.0f, 3.0f, 3.0f);

glm::vec3 UP = glm::vec3(0.0f, 1.0f, 0.0f);
glm::mat4 view = glm::lookAt(position, position - glm::normalize(position), UP); // makes the lookAt vector always point towards (0, 0, 0)
glm::mat4 projection = glm::perspective(frustum, screenRatio, nearPlane, farPlane);

using the view and projection matrices, i transform every vertex from my Grid model and render it.

glm::mat4 viewProjectionMatrix = Graphic::camera->getViewProjectionMatrix(); // returns Camera::projection * Camera::view
for (unsigned int i = 0; i < vertexNum; ++i) {
    glColor3f(vertexArray[i].normal.x, vertexArray[i].normal.y, vertexArray[i].normal.z); // normal vector is used for color in this case
    glm::vec4 translatedPosition(viewProjectionMatrix*gridTransformationMatrix*(glm::vec4(vertexArray[i].position, 1.0f)));
    glVertex3f(translatedPosition.x, translatedPosition.y, translatedPosition.z);

but this is what i see when i move the camera along the line: (0,0,0) + u*(1,1,1) http://i.imgur.com/PrcDcLs.gifv (you can see the camera cooridnates in the console)

  • \$\begingroup\$ Since you're handling the matrices manually but still sending the data to the fixed function pipeline, did you call glLoadIdentity() before drawing? \$\endgroup\$ – demanze Dec 18 '16 at 18:39
  • \$\begingroup\$ No i didn´t. It does not change anything if i do. \$\endgroup\$ – stimulate Dec 18 '16 at 18:45
  • \$\begingroup\$ How is viewProjectionMatrix calculated? \$\endgroup\$ – user253751 Dec 18 '16 at 21:34
  • \$\begingroup\$ glm::mat4 Graphic::Camera::getViewProjectionMatrix() { return glm::mat4(projection * view); } \$\endgroup\$ – stimulate Dec 18 '16 at 22:17
  • \$\begingroup\$ can it even be anywhere else in the code? i mean this is all opengl should need right? and i am sure that the grid is generated correctly, because i have used it before (with a geometry shader though, but this should not influence the perspective behavior should it?) \$\endgroup\$ – stimulate Dec 18 '16 at 22:27

Could it be that your screenRatio is 1,42857 instead of 1.42857? Sorry in advance, I don't have enough rep to comment yet.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.