//******************************************** // SetAlpha // From RGB to grey scales, then alpha layer //******************************************** int Texture::SetAlphaLayer(Texture *pTexture) { // Check if(!IsValid()) return 0; if(!pTexture->IsValid()) return 0; if(!SameSize(pTexture)) return 0; if(!AddAlphaLayer(0)) return 0; // Fill new data unsigned char *pData = pTexture->GetData(); int size = m_Width * m_Height; int BytePerPixel = pTexture->GetDepth() / 8; for(int i=0;i<size;i++) m_pData[4*i+3] = (unsigned char)((int)pData[BytePerPixel*i+0]+ (int)pData[BytePerPixel*i+1]+ (int)pData[BytePerPixel*i+2])/3; return 1; }
void MainWindow::on_generateButton_clicked() { //Ensure all images are the same size if(!SameSize(topImage, rightImage, leftImage, bottomImage)) { QMessageBox msgBox; msgBox.setText("Images are not the same size!"); msgBox.exec(); return; } int normalMapSize = topImage.size().width()*topImage.size().height(); normals = new QVector3D[normalMapSize]; for(int i = 0; i < normalMapSize; i++) { //Point all vectors -z normals[i].setZ(-1.0); normals[i].setY(0); normals[i].setX(0); } ProcessNormals(topImage, IMAGE::TOP); ProcessNormals(rightImage, IMAGE::RIGHT); ProcessNormals(bottomImage, IMAGE::BOTTOM); ProcessNormals(leftImage, IMAGE::LEFT); resultImage = QImage(topImage.width(), topImage.height(), QImage::Format_RGB32); for(int i = 0; i < normalMapSize; i++) { normals[i].normalize(); QColor normColor; normColor.setRgbF((normals[i].x()+1.0)/2.0, (normals[i].y()+1.0)/2.0, (-normals[i].z()+1.0)/2.0); int yCoord = i / topImage.width(); int xCoord = i % topImage.width(); resultImage.setPixel(QPoint(xCoord, yCoord), normColor.rgb()); } resultScene->addPixmap(QPixmap::fromImage(resultImage.scaled(QSize(100, 100)))); ui->resultView->show(); ui->oglWidget->SetNormalMap(resultImage); }