I can’t really understand what these modes are doing.
I see you set
glMatrixMode(GL_MODELVIEW);
before you draw vertices, but what does that actually mean? What is it doing?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In OpenGL there are two main matrix modes (there are two others, but you probably don’t need to be concerned with them), they are
GL_MODELVIEWandGL_PROJECTION. Together they define much of how opengl transforms the vertices you put in into the visuals you get out. When you have calledglMatrixMode(GL_MODELVIEW)most recently, you will be altering how your points will be shifted around in space, you can cause all of your points to be translated withglTranslatef, rotated withglRotatefand so on. When you have calledglMatrixMode(GL_PROJECTION)you will be altering how your points get projected onto the screen. This is the mode you want to be in to call things likegluPerspectiveorglOrtho.It is common to switch to projection mode before each major drawing step (main scene, GUI, etc) set up the projection matrices, then switch to modelview until the next one. This way, you can leave your projection unaltered while you change around the transformations of the scene by moving the camera, altering positions of objects, etc.