我試圖編寫一個類來加載對象到我的程序/問題是,OpenGL只加載所有對象的最後一個紋理。OpenGL中多個紋理的問題
下面是代碼:
的game.cpp類:
object = new Object("table.obj", "wood.bmp",0); // a new object - obj file, texture and
object1 = new Object("aa.obj", "cloth.bmp",1); // texture number
object->draw();
object1->draw();
對象類:
AUX_RGBImageRec *texture;
Object::Object(char* filename, char* texname, int num) {
tex_num = num;
is_loaded = false;
.... some vertex stuff here
texture = auxDIBImageLoadA(texname);
}
void Object::draw() {
if(!is_loaded) {
loadTexture();
is_loaded = true;
}
... vertex stuff again
void Object::loadTexture() {
GLuint *tex = new GLuint[10];
unsigned int names[10];
glGenTextures(1, tex);
glBindTexture(GL_TEXTURE_2D, tex[tex_num]);
cout << tex_num << endl;
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, 3,
texture->sizeX,
texture->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE,
texture->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// free memory
delete tex;
cout << tex_num << endl;
}
請停止使用AUX加載圖像。如果您使用的是使用AUX的教程,請停止使用該教程並[找到更好的教程。](http://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides) – 2013-03-03 11:33:11