   Can only apply textures in my draw function
  I'm using Qt and OpenGL, and I'm kinda unsure if this is a Qt issue, or an OpenGL issue.  Basically, Qt handles making my OpenGL window for me.  My OpenGL window's draw function calls a particle engine class which will draw a bunch of particles (each particle is also a class).The particles themselves are just textured GL_QUADS, but the ONLY way I've been able to get the textures to apply to the squares is to put all the texture loading and generation code inside the particle class' draw function.  If I put the texture loading code anywhere else, and just try to pass the GLuint texture id to the particle's draw function, it will not draw the textures anymore:Heres some code:1.  The particle System class.  My Qt OpenGL window contains an instance of this class, so all the OpenGL stuff should be initialized by this point.#include "ParticleSystem.h"#include <stdlib.h>#include <time.h>//// This is particle system constructor.  Notice that I'm loading// the texture here to pass to the particle class.  I'm using some// Qt functionality here, but if you check out the example at:// http://doc.trolltech.com/4.2/opengl-textures-glwidget-cpp.html// you can see that the way I'm doing things seems to match their// example.//ParticleSystem::ParticleSystem(QGLWidget *parent):Parent(parent), time_counter(0){srand(time(NULL));// Set up the particle textureQImage tex_image;if ( !tex_image.load( "particle.bmp" ) ){exit(1);}ptexture_id = Parent->bindTexture(tex_image);}ParticleSystem::~ParticleSystem(void){Parent->deleteTexture(ptexture_id);}void ParticleSystem::Update(int time){UpdateParticles(time, UPDATE_ALL);CreateNewParticles(time);}//// The particle system draws all the particles by looping through a// list of particles and telling the particles to draw themselves.//void ParticleSystem::Draw(void){Vec3d pos;glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE);glDepthMask(false);glEnable(GL_COLOR_MATERIAL);std::vector<Particle>::iterator i;for(i = particles.begin(); i != particles.end(); ++i){glPushMatrix();pos = i->Position();glTranslated(pos.x(), pos.y(), pos.z());i->draw();glPopMatrix();}glPopAttrib();}//// This function generates new particles as time goes on.  Notice that// the particles built are passed the texture ID made in the constructor.// void ParticleSystem::CreateNewParticles(int time){// How often to generate particles, in millisecondsint gen_frequency = 100;// Keep track of how much time has passed since last particle gentime_counter += time;// If enough time has passed, generate a new particle and reset the timerif(time_counter >= gen_frequency){time_counter = 0;// Create a pseudorandom velocity vectorVec3d velocity( rand()%16 - 8, rand()%10 + 5, rand()%16 - 8 ); Particle new_particle(Parent,// Pointer to OpenGL windowptexture_id,// ID of the texture for the particle to useVec3d(0.0, 0.0, 1.0),// ColorVec3d(0.0, 0.0, 0.0),// Positionvelocity,// Velocity2000);// Lifespan of the particle in milliseconds.// Add the particle to our vectorparticles.push_back(new_particle);}}void ParticleSystem::UpdateParticles(int time, enum updateType update, int index){Vec3d accel(0.0, -9.81, 0.0);Vec3d pos;Vec3d vel;std::vector<Particle>::iterator i;for(i = particles.begin(); i != particles.end(); ++i){// If our particle is too old, we must delete it from the listif(i->IsDead()){particles.erase(i);i = particles.begin();}else{pos = i->Position();vel = i->Velocity();i->SetPosition(pos + vel*(time/1000.0) + accel*( 0.5 * pow((time/1000.0), 2) ) );i->SetVelocity(vel + accel*(time/1000.0));i->IncreaseAge(time);}}}2.  Here is the particle class implementation.  Note that the particle takes a texture id in its constructor.  This comes from the texture that the particle system generates.#include "Particle.h"#include <iostream>#include <QImage>#include <stdio.h>//// This is the constructor for the particle class.  Notice it stores the// texture id it was passed for later use.//Particle::Particle(QGLWidget *parent, GLuint tex_id, Vec3d initColor, Vec3d initPosition, Vec3d initVelocity, int initLifespan):Parent(parent), texture_id(tex_id), color(initColor), position(initPosition), velocity(initVelocity){if(initLifespan > 0){mortality = MORTAL;lifespan = initLifespan;age = 0;}elsemortality = IMMORTAL;}Particle::~Particle(){}Vec3d Particle::Color(void){return color;}Vec3d Particle::Position(void){return position;}Vec3d Particle::Velocity(void){return velocity;}void Particle::IncreaseAge(int timePassed){if(mortality == MORTAL)age += timePassed;}void Particle::SetColor(Vec3d newColor){color = newColor;}void Particle::SetPosition(Vec3d newPosition){position = newPosition;}void Particle::SetVelocity(Vec3d newVelocity){velocity = newVelocity;}bool Particle::IsDead(void){if(age > lifespan)return true;elsereturn false;}//// This function tries to draw a textured quad.  It doesn't work though.// If I copy and paste my texture loading code from my particle system// class into this function, everything works fine (except that things// run slow as heck).  Anyone have any ideas why?//void Particle::draw(void){glColor4d(color.x(), color.y(), color.z(), 0.5);glBindTexture( GL_TEXTURE_2D, texture_id);glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );// Draw the squareglBegin(GL_QUADS);glTexCoord2i(1, 1); glVertex3f( 1.0,  1.0, 0.0);glTexCoord2i(0, 1); glVertex3f(-1.0,  1.0, 0.0);glTexCoord2i(0, 0); glVertex3f(-1.0, -1.0, 0.0);glTexCoord2i(1, 0); glVertex3f( 1.0, -1.0, 0.0);glEnd();}
  To give an update, the GLuint from Qt's bindTexture() function is being passed correctly, but it is returning a really huge number like 16834.  That seems way too high for my texture id.  This is the 1 and only texture i'm loading in at the moment too...   ;  Well, looks like I got it working. I was making my instance of the ParticleSystem class too early.  I think the opengl stuff wasn't properly initialized at that point.  I changed my code to generate my particle engine at the end of my gl init function and everything worked like a charm ;)   