1
\$\begingroup\$

Today I was trying to make a test camera, with a new method(I usually use gluLookAt)

So I got a problem,

void GameDraw()
{
    glPushMatrix();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90, WIDTH / HEIGHT, 0.001, 10000.0);
    pitch += 1;
    glRotatef(pitch, 1.0, 0.0, 0.0);
    glRotatef(yaw, 0.0, 1.0, 0.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    s->bind();
    test->drawMesh();
    glPopMatrix();
}

And my draw function is:

glDrawElements(GL_TRIANGLES, indices, GL_UNSIGNED_INT, nullptr);

if it isn't working with glDrawElements is there any alternative to use?

Edit: Disabling shader it works fine, but how I can use this with Shader

Please don't use glm examples, because I don't like to use it, I feel more comfortable by using the my math

\$\endgroup\$
0
1
\$\begingroup\$

Edit: Disabling shader it works fine, but how I can use this with Shader

There is you problem, the default shader gets and uses the matrix stack but your shader probably doesn't. You should multiply the position with gl_ModelViewProjectionMatrix in the vertex shader:

gl_Position = gl_ModelViewProjectionMatrix * position;

The Matrix stack was removed in modern opengl (core version 3.1+) however, which requires you to use a 3rd party lib for your matrix math on cpu and use uniforms to pass it to the shader.

\$\endgroup\$
6
  • \$\begingroup\$ "The Matrix stack was removed in modern opengl (core version 3.1+) however, which requires you to use a 3rd party lib for your matrix math on cpu and use uniforms to pass it to the shader." I believe calling glGet for all 3 matrices, and passing them to the shader, I think it may not require. So my idea will work?(I'm questioning this because if I start something in my code, and remove after, it will be a buggy mess in my code) \$\endgroup\$ Aug 4 '17 at 8:47
  • \$\begingroup\$ It's not that hard to duplicate the opengl matrix stack. Even to give it mostly the same api. \$\endgroup\$ Aug 4 '17 at 9:00
  • \$\begingroup\$ glGet on matrix will return an 16 element array, to the opengl I pass 2D array of matrice? Or works with 16 too? \$\endgroup\$ Aug 4 '17 at 9:13
  • \$\begingroup\$ Opengl expects the 16 element array \$\endgroup\$ Aug 4 '17 at 9:15
  • \$\begingroup\$ no matter if is flat or not? \$\endgroup\$ Aug 4 '17 at 9:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .