cl781121

06-24-2016, 08:29 PM

hi there,i dont want to use glm lib，so i change code like below

glm code

glm::mat4 lightProjection, lightView;

glm::mat4 lightSpaceMatrix;

GLfloat near_plane = 1.0f, far_plane = 7.5f;

lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);

lightView = glm::lookAt(lightPos, glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));

lightSpaceMatrix = lightProjection * lightView;

i change it like this:

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

GLfloat near_plane = 1.0f, far_plane = 7.5f;

GLdouble lightProjection[16],lightView[16];

GLfloat lightSpaceMatrix[16];

glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);

glGetDoublev(GL_PROJECTION_MATRIX, lightProjection);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(lightPos[0],lightPos[1],lightPos[2],0,0,0,0,1,0);

glGetDoublev(GL_MODELVIEW_MATRIX, lightView);

lightSpaceMatrix[16] = lightProjection[16]*lightView[16];

but it is incorrect,where is my wrong thanks

and error:Run-Time Check Failure #2 - Stack around the variable 'lightSpaceMatrix' was corrupted.

glm code

glm::mat4 lightProjection, lightView;

glm::mat4 lightSpaceMatrix;

GLfloat near_plane = 1.0f, far_plane = 7.5f;

lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);

lightView = glm::lookAt(lightPos, glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));

lightSpaceMatrix = lightProjection * lightView;

i change it like this:

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

GLfloat near_plane = 1.0f, far_plane = 7.5f;

GLdouble lightProjection[16],lightView[16];

GLfloat lightSpaceMatrix[16];

glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);

glGetDoublev(GL_PROJECTION_MATRIX, lightProjection);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(lightPos[0],lightPos[1],lightPos[2],0,0,0,0,1,0);

glGetDoublev(GL_MODELVIEW_MATRIX, lightView);

lightSpaceMatrix[16] = lightProjection[16]*lightView[16];

but it is incorrect,where is my wrong thanks

and error:Run-Time Check Failure #2 - Stack around the variable 'lightSpaceMatrix' was corrupted.