0
\$\begingroup\$

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 glBegin(GL_LINES); 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); } glEnd(); 

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)

\$\endgroup\$
5
  • \$\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\$ Commented Dec 18, 2016 at 18:39
  • \$\begingroup\$ No i didn´t. It does not change anything if i do. \$\endgroup\$ Commented Dec 18, 2016 at 18:45
  • \$\begingroup\$ How is viewProjectionMatrix calculated? \$\endgroup\$ Commented Dec 18, 2016 at 21:34
  • \$\begingroup\$ glm::mat4 Graphic::Camera::getViewProjectionMatrix() { return glm::mat4(projection * view); } \$\endgroup\$ Commented Dec 18, 2016 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\$ Commented Dec 18, 2016 at 22:27

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.