Added experimental snapshot saving function

This commit is contained in:
Paolo Cignoni cignoni 2005-11-29 11:22:23 +00:00
parent 919ca09fd3
commit e8fc9bcdcb
4 changed files with 72 additions and 1 deletions

View File

@ -24,6 +24,9 @@
History
$Log$
Revision 1.23 2005/11/29 11:22:23 vannini
Added experimental snapshot saving function
Revision 1.22 2005/11/28 21:05:37 alemochi
Added menu preferences and configurable background
@ -146,6 +149,7 @@ void GLArea::initializeGL()
rm.drawMode = GLW::DMSmooth;
rm.drawColor = GLW::CMNone;
}
void GLArea::paintGL()
@ -205,6 +209,41 @@ void GLArea::resizeGL(int _width, int _height)
glViewport(0,0, _width, _height);
}
bool GLArea::saveSnapshot(QString path)
{
std::vector<Color4b> snap;
int vp[4];
int p;
glGetIntegerv( GL_VIEWPORT,vp ); // Lettura viewport
glPixelStorei( GL_PACK_ROW_LENGTH, 0);
glPixelStorei( GL_PACK_ALIGNMENT, 1);
snap.resize(vp[2] * vp[3]);
glReadPixels(vp[0],vp[1],vp[2],vp[3],GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid *)&snap[0]);
FILE * fp = fopen(path.toLocal8Bit(),"wb");
if (fp==0) return false;
fprintf(fp,"P6\n%d %d\n255\n",vp[2],vp[3]);
int j=0;
for(int py=vp[3]-1; py >= 0; --py)
{
for(int px=0; px < vp[2]; ++px)
{
p=py * vp[2] + px;
fwrite(&(snap[p]),3,1,fp);
//printf("%d %d\n",px, py);
}
}
fclose(fp);
return true;
}
Trackball::Button QT2VCG(Qt::MouseButton qtbt, Qt::KeyboardModifiers modifiers)
{
int vcgbt=Trackball::BUTTON_NONE;

View File

@ -24,6 +24,9 @@
History
$Log$
Revision 1.14 2005/11/29 11:22:23 vannini
Added experimental snapshot saving function
Revision 1.13 2005/11/28 21:05:37 alemochi
Added menu preferences and configurable background
@ -133,6 +136,7 @@ public:
void setColorMode(vcg::GLW::ColorMode mode);
void setLight(bool state);
void setLightMode(bool state,LightingModel lmode);
bool saveSnapshot(QString path);
inline void RenderLight();
list<pair<QAction *,MeshRenderInterface *> > *iRendersList;
protected:
@ -145,7 +149,8 @@ protected:
void mouseReleaseEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent*e);
private:
RenderMode rm;
Point3f bColor;

View File

@ -24,6 +24,9 @@
History
$Log$
Revision 1.44 2005/11/29 11:22:23 vannini
Added experimental snapshot saving function
Revision 1.43 2005/11/28 21:05:37 alemochi
Added menu preferences and configurable background
@ -256,6 +259,19 @@ bool MainWindow::saveAs()
}
}
bool MainWindow::saveSnapshot()
{
QString snapshotPath = "snapshot.ppm";
bool ret=GLA()->saveSnapshot(snapshotPath);
if (ret)
GLA()->log.Log(GLLogStream::Info,"Snapshot saved to %s",snapshotPath.toLocal8Bit().constData());
else
GLA()->log.Log(GLLogStream::Error,"Error saving snapshot %s",snapshotPath.toLocal8Bit().constData());
return ret;
}
void MainWindow::about()
{
QMessageBox::about(this, tr("About Plug & Paint"),
@ -280,6 +296,11 @@ void MainWindow::createActions()
saveAsAct->setShortcut(tr("Ctrl+S"));
connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
saveSnapshotAct = new QAction(QIcon(":/images/save.png"),tr("&Save snapshot"), this);
connect(saveSnapshotAct, SIGNAL(triggered()), this, SLOT(saveSnapshot()));
for (int i = 0; i < MAXRECENTFILES; ++i) {
recentFileActs[i] = new QAction(this);
recentFileActs[i]->setVisible(false);
@ -393,6 +414,7 @@ void MainWindow::createToolBars()
mainToolBar->setIconSize(QSize(32,32));
mainToolBar->addAction(openAct);
mainToolBar->addAction(saveAsAct);
mainToolBar->addAction(saveSnapshotAct);
renderToolBar = addToolBar(tr("Render"));
renderToolBar->setIconSize(QSize(32,32));
@ -406,6 +428,8 @@ void MainWindow::createMenus()
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAct);
fileMenu->addAction(saveAsAct);
fileMenu->addAction(saveSnapshotAct);
separatorAct = fileMenu->addSeparator();
for (int i = 0; i < MAXRECENTFILES; ++i) fileMenu->addAction(recentFileActs[i]);
updateRecentFileActions();
@ -767,6 +791,7 @@ void MainWindow::updateMenus()
{
bool active = (bool)workspace->activeWindow();
saveAsAct->setEnabled(active);
saveSnapshotAct->setEnabled(active);
filterMenu->setEnabled(active && !filterMenu->actions().isEmpty());
renderMenu->setEnabled(active);
windowsMenu->setEnabled(active);

View File

@ -50,6 +50,7 @@ private slots:
void open(QString fileName=QString());
void openRecentFile();
bool saveAs();
bool saveSnapshot();
void about();
// Plugin Slots ///////////
@ -121,6 +122,7 @@ private:
QAction *openAct;
QAction *saveAsAct;
QAction *saveSnapshotAct;
QActionGroup *renderModeGroup;