Aliii

09-25-2013, 03:58 AM

Im just moving to the modern OpenGL. I set up the view-matrix(without projection) and it works OK. I added a minimalist projection matrix and it also works fine.

GLfloat projection_matrix[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 };Then Ive tried to use a proper matrix and its not working out. That means, as I move the camera the movement and rotation seem like its mirrored.(I use a 90.0 perspective angle and 1.0 aspect ratio, to keep it simple.)

float n = 0.5, f = 100.0, w2 = 0.5, //width / 2 h2 = 0.5; //height / 2 GLfloat projection_matrix[16] = { n/w2, 0.0, 0.0, 0.0, 0.0, n/h2, 0.0, 0.0, 0.0, 0.0, -((f+n)/(f-n)), -1.0, 0.0, 0.0, -(2*f*n)/(f-n), 0.0 };I got it from here: http://www.songho.ca/opengl/gl_projectionmatrix.html...but its the same in the OGL Programming Guide 8th, so I guess it should be correct.This is the shader source BTW:

#version 330 corelayout(location = 0) in vec3 vertex_pos;uniform mat4 V_trans;uniform mat4 V_rot;uniform mat4 P;void main(){ vec4 pos_HOM = vec4( vertex_pos, 1); gl_Position = P * (V_rot * V_trans) * pos_HOM;} Im also wondering how can I set the near and far planes, ....as gluPerspective is for the "old" openGL I guess.Thanks!

GLfloat projection_matrix[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 };Then Ive tried to use a proper matrix and its not working out. That means, as I move the camera the movement and rotation seem like its mirrored.(I use a 90.0 perspective angle and 1.0 aspect ratio, to keep it simple.)

float n = 0.5, f = 100.0, w2 = 0.5, //width / 2 h2 = 0.5; //height / 2 GLfloat projection_matrix[16] = { n/w2, 0.0, 0.0, 0.0, 0.0, n/h2, 0.0, 0.0, 0.0, 0.0, -((f+n)/(f-n)), -1.0, 0.0, 0.0, -(2*f*n)/(f-n), 0.0 };I got it from here: http://www.songho.ca/opengl/gl_projectionmatrix.html...but its the same in the OGL Programming Guide 8th, so I guess it should be correct.This is the shader source BTW:

#version 330 corelayout(location = 0) in vec3 vertex_pos;uniform mat4 V_trans;uniform mat4 V_rot;uniform mat4 P;void main(){ vec4 pos_HOM = vec4( vertex_pos, 1); gl_Position = P * (V_rot * V_trans) * pos_HOM;} Im also wondering how can I set the near and far planes, ....as gluPerspective is for the "old" openGL I guess.Thanks!