OpenGL's coordinate system is not quite the same as how you'd think of a camera's coordinate system; with a camera, a higher z means it's farther away. But in OpenGL it's actually quite the opposite: the higher the z value, the closer something is to the camera. The reason gluPerspective works when you have 0 as an angle is because it doesn't really do anything when the angle is 0. Otherwise, it catches that you're drawing something that's actually behind the camera, and disregards it. The solution to all this? Negate all your z values. If you make them
Code: Select all
glTranslatef(0, 0,-translationAmount);
Code: Select all
gluPerspective(45.0f,2.0f,-0.1f,-100.0f);
He also brought up the fact that you have an entire function defined in your header file. In this case, there's no point in having the header file, and if you try to use it like you would a normal header file you can have tons of problems, primarily multiple include and multiple definition problems. The point of a header is to separate interface and implementation. Think about the buttons in an elevator: they all pretty much look the same, no matter which elevator your in. The same is true with a lot of programming libraries: it doesn't matter which version they are or what internal tweaks they have, they all look exactly the same. In the case of your header, you haven't separated the implementation from the interface whatsoever, and honestly, in this case, there's no reason to have a header file at all. Are you expecting to call initialize_it() from a different file? Because if so, you didn't approach it correctly. There are two main features that all good header files have: include guards, and declarations without implementations.
Include guards are pretty simple to do; just format your header like this:
Code: Select all
#ifndef MYFILE_H
#define MYFILE_H
/* other stuff goes here */
#endif
Declarations without implementations are also simple. Just declare a function in your header:
Code: Select all
void foo();
Code: Select all
void foo() {
/* content goes here */
}