今天花了大半天的时间做QT opengl 关于贴图的例子http://www.qiliang.net/old/nehe_qt/lesson06.html
这个例子的框架是对的,但有些错误,改错的过程也是学习的过程
发现以前C语言关于指针,数组的知识都忘光了
GLuint myTexture;
glGenTextures(1, &myTexture); // generate just one texture
GLuint myTextures[32];
glGenTextures(32, myTextures); // generate 32 textures
GLuint myOtherTexture;
GLuint* myTexturePointer = &myOtherTexture;
glGenTextures(1, myTexturePointer); // generate 1 texture using a pointer
GLuint* moreTextures = new GLuint[16];
// generate only 8 textures in the latter half of the array
glGenTextures(8, moreTextures + 8);
这是stack overflow 上的一篇回答 (http://stackoverflow.com/questions/5027672/glgentextures-gluint-or-array)
glGenTextures()函数的第二个参数是一个GLuint型的指针,这个参数可以用GLuint 型变量的地址(&), 数组名,或者一个GLuint类型的指针来充当
第二点,发现贴图貌似对格式要求很高,长宽比必须是2的整数倍,128×128, 256×256,,, 还必须是bmp格式的
第三点, 想要让六面体在窗口中转起来的话,要加一个QTimer
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(50);
加在构造函数里就行了