GLuint readImage(char *filename)
{
GLuint tex_id;
GLint alignment;
QImage tex, buf;
buf.load(filename);
tex = QGLWidget::convertToGLFormat( buf );
glBindTexture( GL_TEXTURE_2D, tex_id );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, tex.bits() );
glPixelStorei (GL_UNPACK_ALIGNMENT, alignment);
return tex_id;
}
顯示PNG透明,不顯示BMP白邊等方法參考前面兩篇。
在QT界面的顯示參考BMP那篇
http://stackoverflow.com/questions/5335218/using-qimage-with-opengl
2012/5/21
還是要多看書,前面一大堆讀取綁定紋理的方式
現在就只要下面三句就行了
//bindTexture() 綁定紋理
GLuint texture = bindTexture(QPixmap(QString(FileNameImage)), GL_TEXTURE_2D);
QRectF rect(0.0f,0.0f,0.2f,0.2f);
drawTexture(rect,texture,GL_TEXTURE_2D);
效果沒有前面的方式好,正在研究。
圖片的顯示,需要旋轉一下glRotatef();
使用glBegin()glEnd()畫的圖形開始會顯示,給圖片加上拖動效果后,一移動圖片,其他圖形就會消失,不解;
http://blog.csdn.net/zmy3376365/article/details/7572303
參考http://www.cnblogs.com/dabaopku/archive/2011/11/14/2247721.html
在QGraphicsView的事件中,不論使用 update,repaint,抑或updateScence,resetCacheContent, 均不可以刷新界面
要調用 viewport 的update函數!!!
給GraphicsView設置這么一個屬性setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
例如:ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
在需要的地方后面加一句update例如在GraphicsScene(繼承自QGraphicsScene)中加update();
或着是GraphicsView(繼承自QGraphicsView): this->viewport()->update();
具體情況,具體分析
http://blog.csdn.net/zmy3376365/article/details/7572698
