'What is the difference between local and global variable in C++?
I'm trying to make some simple OpenGL application with light included. I want to have a position of my light in the global scope to change it in some other parts of my program. So here is my function to set the light's position:
void lightSetup(){
glMatrixMode(GL_MODELVIEW);
GLfloat light_position[] = {0, 0, 0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
Other lightning settings are being done in my init function, and everything works if the light position is declared as shown above. That is the result I expect and get when using the local variable:
.
When I declare light_position
in the global scope
GLfloat light_position[] = {0, 0, 0};
void lightSetup(){
glMatrixMode(GL_MODELVIEW);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
it doesn't work, and my scene looks like this:
Watching the values of these variables in the debugger didn't bring me anywhere as they are the same. So I have no idea why the results differ.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|