QImage texture, buffer; buffer.load("C:/Users/wukesong/Pictures/flower.jpg"); texture = QGLWidget::convertToGLFormat(buffer);//转换为OpenGL支持的格式 glGenTextures(1, &gColorSpec);//创建纹理数量 :一个 glBindTexture(GL_TEXTURE_2D, gColorSpec);//将纹理绑定到目标纹理上 glTexImage2D(GL_TEXTURE_2D, 0, 3, texture.width(), texture.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.bits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//滤波 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0);