Creating and uploading a new texture is illegal between a glBegin/glEnd pair, as is changing the current texture.
http://www.opengl.org/sdk/docs/man/xhtm ... mage2D.xml"
GL_INVALID_OPERATION is generated if glTexImage2D is executed between the execution of glBegin and the corresponding execution of glEnd."
http://www.opengl.org/sdk/docs/man/xhtm ... exture.xml"
GL_INVALID_OPERATION is generated if glBindTexture is executed between the execution of glBegin and the corresponding execution of glEnd."
The right solution is
not to put your glBegin/glEnd inside the loop; that will cause your performance to plummet like a stone. What you want instead is to check if the texture has changed from the last one used, if so you call glEnd, then switch texture, then call glBegin again. (you can optimize out the case where no particles have yet been drawn later on).
It's also not a good idea to load textures at runtime like this, you'll want to load them upfront during initialization, otherwise it will also hurt performance.