void GLWidget::initializeGL(){ quint8 texData[16][16]; qsrand(100); for (int i = 0; i < 16; ++i) { for (int j = 0; j < 16; ++j) { texData[i][j] = qRound(qrand()*255.0/RAND_MAX); } } glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_TEXTURE_2D);// GLuint m_texture; glGenTextures(1, &m_texture); glBindTexture(GL_TEXTURE_2D, m_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 16, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texData);}void GLWidget::paintGL(){ glLoadIdentity(); glColor3f(1.0, 1.0, 0.0); glBindTexture(GL_TEXTURE_2D, m_texture); glBegin(GL_QUADS); glTexCoord2f(0.0,0.0);glVertex2f(0.0,0.0); glTexCoord2f(1.0,0.0);glVertex2f(1.0,0.0); glTexCoord2f(1.0,1.0);glVertex2f(1.0,1.0); glTexCoord2f(0.0,1.0);glVertex2f(0.0,1.0); glEnd();}
glTexImage2D(GL_TEXTURE_2D, 0, 1, 16, 16, 0, GL_RED, GL_UNSIGNED_BYTE, texData);