1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// ...
typedef std::list<RenderObject*> ObjectList;
template <typename T> class Scene
{
private:
typedef MipMap<T> Tex;
typedef std::map<std::string, Tex*, StringCompareCaseInsensitive> TexMap;
typedef std::map<std::string, GLuint, StringCompareCaseInsensitive> GLTexMap;
typedef std::pair<std::string, GLuint> GLTexMapPair;
public:
// ...
void initToGL() {
std::cout << "Soft iteration:" << std::endl; // This iteration works fine
for (TexMap::iterator it = textures.begin(); it != textures.end(); it++) {
std::cout << "Texture: " << it->first << std::endl;
}
system("@pause>nul");
for (TexMap::iterator it = textures.begin(); it != textures.end(); it++) { // Crash right here
std::cout << "Making texture " << std::flush;
std::cout << it->first << "..." << std::endl;
MipMap<T>* mipMap = it->second;
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
std::cout << "Generated and bound GL textures." << std::endl;
RGBTexture tex(mipMap->getWidth(0), mipMap->getHeight(0));
T* topMap = mipMap->getMipMap(0);
for (UINT x = 0; x < mipMap->getWidth(0); x++) {
for (UINT y = 0; y < mipMap->getHeight(0); y++) {
tex.setColorAt(x, y, topMap->getColorAt(x, y));
}
}
std::cout << "Built RGBTexture with dimensions " << tex.getWidth() << "x" << tex.getHeight() << std::endl;
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, tex.getWidth(), tex.getHeight(),
GL_RGB, GL_UNSIGNED_BYTE, (void*) tex.getRawData());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
std::cout << "Generated mipmaps." << std::endl;
glBindTexture(GL_TEXTURE_2D, 0);
std::cout << "Unbound texture." << std::endl;
glTextureList.emplace(GLTexMapPair(it->first, texture));
std::cout << "Emplaced texture." << std::endl;
}
std::cout << "Made textures." << std::endl;
for (ObjectList::iterator it = objectList.begin(); it != objectList.end(); it++) {
(*it)->initToGL();
}
}
// ...
private:
TexMap textures;
GLTexMap glTextureList;
ObjectList objectList;
UINT frameCount;
Camera* cam;
};
|