I was loading a image in openGl with the Glaux library when I came across a very strange phenomenon with a array. Some example of what I tried and if they succeeded or not are below. The curFreeId variable is global. The extra variables I created to test with are local to the function.
Since when does this effect the flow of code.
unsigned int curFreeId = 0;
modStruct->t[ i 开发者_StackOverflow].gluId = curFreeId;
glGenTextures(1, &glTextureList[curFreeId]);
glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);
vs
modStruct->t[ i ].gluId = 0;
glGenTextures(1, &glTextureList[0]);
glBindTexture(GL_TEXTURE_2D, glTextureList[0]);
The first code will not work. The second will. Does anyone have any clue why this happens?
EDIT: Strangely enough, this also works correctly.
unsigned int curFreeId = 0;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[0]);
glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);
and so does this.
unsigned int curFreeId = 0;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[curFreeId]);
glBindTexture(GL_TEXTURE_2D, glTextureList[0]);
Continuing on with some testing. I came across even more curious results.
This works
unsigned int curFreeId = 0;
unsigned int curid = 0;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[curid]);
glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);
But this does not...
unsigned int curFreeId = 0;
unsigned int curid = curFreeId;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[curid]);
glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);
But this does...
unsigned int curFreeId = 0;
unsigned int curid = curFreeId = 0;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[curid]);
glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);
What is the world... Is this some glitch of some sort?
Okay... I just went through the entire project looking for all relations to curFreeId. I managed to find a random addition sign someplace.
curFreeId++;
I hate the simple bugs...
Thanks for your help guys. I managed to fix a few other bugs because of your suggestions.
精彩评论