Further work on image generation experiment

Fri, 24 May 2013 19:44:53 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 24 May 2013 19:44:53 +0300
changeset 254
434c9844e45d
parent 253
0737c217a54d
child 255
67d4aedf1041

Further work on image generation experiment

src/addObjectDialog.cpp file | annotate | diff | comparison | revisions
src/file.cpp file | annotate | diff | comparison | revisions
src/file.h file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui_actions.cpp file | annotate | diff | comparison | revisions
src/gui_editactions.cpp file | annotate | diff | comparison | revisions
--- a/src/addObjectDialog.cpp	Fri May 24 16:43:56 2013 +0300
+++ b/src/addObjectDialog.cpp	Fri May 24 19:44:53 2013 +0300
@@ -480,7 +480,7 @@
 			if (~name == 0)
 				return; // no subfile filename
 			
-			LDOpenFile* file = loadFile (name);
+			LDOpenFile* file = getFile (name);
 			if (!file) {
 				critical (fmt ("Couldn't open `%s': %s", name.c (), strerror (errno)));
 				return;
--- a/src/file.cpp	Fri May 24 16:43:56 2013 +0300
+++ b/src/file.cpp	Fri May 24 19:44:53 2013 +0300
@@ -687,7 +687,7 @@
 			// not loading the main file now, but the subfile
 			bool oldLoadingMainFile = g_loadingMainFile;
 			g_loadingMainFile = false;
-			LDOpenFile* load = loadFile (tokens[14]);
+			LDOpenFile* load = getFile (tokens[14]);
 			g_loadingMainFile = oldLoadingMainFile;
 			
 			// If we cannot open the file, mark it an error
@@ -772,8 +772,8 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-LDOpenFile* loadFile (str fname) {
-	// Try find the subfile in the list of loaded files
+LDOpenFile* getFile (str fname) {
+	// Try find the file in the list of loaded files
 	LDOpenFile* load = findLoadedFile (fname);
 	
 	// If it's not loaded, try open it
@@ -803,7 +803,7 @@
 		if (obj->getType() == LDObject::Subfile) {
 			// Note: ref->fileInfo is invalid right now since all subfiles were closed.
 			LDSubfile* ref = static_cast<LDSubfile*> (obj);
-			LDOpenFile* fileInfo = loadFile (ref->fileName);
+			LDOpenFile* fileInfo = getFile (ref->fileName);
 			
 			if (fileInfo)
 				ref->fileInfo = fileInfo;
--- a/src/file.h	Fri May 24 16:43:56 2013 +0300
+++ b/src/file.h	Fri May 24 19:44:53 2013 +0300
@@ -97,7 +97,7 @@
 LDObject* parseLine (str line);
 
 // Retrieves the pointer to - or loads - the given subfile.
-LDOpenFile* loadFile (str zFile);
+LDOpenFile* getFile (str zFile);
 
 // Re-caches all subfiles.
 void reloadAllSubfiles ();
--- a/src/gldraw.cpp	Fri May 24 16:43:56 2013 +0300
+++ b/src/gldraw.cpp	Fri May 24 19:44:53 2013 +0300
@@ -129,9 +129,6 @@
 
 // =============================================================================
 GLRenderer::~GLRenderer () {
-	for (CameraIcon& info : g_CameraIcons)
-		delete info.img;
-	
 	for (int i = 0; i < 6; ++i)
 		delete m_overlays[i].img;
 }
@@ -1399,4 +1396,9 @@
 
 overlayMeta& GLRenderer::getOverlay (int newcam) {
 	 return m_overlays[newcam];
+}
+
+void deleteCameraIcons () {
+	for (CameraIcon& info : g_CameraIcons)
+		delete info.img;
 }
\ No newline at end of file
--- a/src/gldraw.h	Fri May 24 16:43:56 2013 +0300
+++ b/src/gldraw.h	Fri May 24 19:44:53 2013 +0300
@@ -75,10 +75,12 @@
 	void           compileObject       (LDObject* obj);
 	void           compileAllObjects   ();
 	double         depthValue          () const;
+	void           drawGLScene         ();
 	void           endDraw             (bool accept);
 	QColor         getMainColor        ();
 	overlayMeta&   getOverlay          (int newcam);
 	void           hardRefresh         ();
+	void           initGLData          ();
 	void           refresh             ();
 	void           resetAngles         ();
 	uchar*         screencap           (ushort& w, ushort& h);
@@ -128,13 +130,11 @@
 	void           compileVertex       (const vertex& vrt);                     // Compile a single vertex to a list
 	vertex         coordconv2_3        (const QPoint& pos2d, bool snap) const;  // Convert a 2D point to a 3D point
 	QPoint         coordconv3_2        (const vertex& pos3d) const;             // Convert a 3D point to a 2D point
-	void           drawGLScene         ();                                // Paint the GL scene
 	void           pick                (uint mouseX, uint mouseY);              // Perform object selection
 	void           setObjectColor      (LDObject* obj, const ListType list);    // Set the color to an object list
 	
 private slots:
 	void	slot_toolTipTimer	();
-	void initGLData();
 };
 
 // Alias for short namespaces
@@ -147,6 +147,7 @@
 	GL::BFCBackList,
 };
 
+void deleteCameraIcons ();
 extern const GL::Camera g_Cameras[7];
 extern const char* g_CameraNames[7];
 
--- a/src/gui.cpp	Fri May 24 16:43:56 2013 +0300
+++ b/src/gui.cpp	Fri May 24 19:44:53 2013 +0300
@@ -96,7 +96,8 @@
 
 // =============================================================================
 void ForgeWindow::slot_lastSecondCleanup () {
-	m_renderer->setParent (null);
+	deleteCameraIcons ();
+	
 	delete m_renderer;
 }
 
--- a/src/gui_actions.cpp	Fri May 24 16:43:56 2013 +0300
+++ b/src/gui_actions.cpp	Fri May 24 19:44:53 2013 +0300
@@ -452,15 +452,38 @@
 }
 
 MAKE_ACTION (testpic, "Test picture", "", "", (0)) {
-	LDOpenFile* file = loadFile ("axle.dat");
+	LDOpenFile* file = getFile ("axle.dat");
+	setlocale (LC_ALL, "C");
 	
 	if (!file) {
 		critical ("couldn't load axle.dat");
 		return;
 	}
 	
+	ushort w, h;
+	
 	GLRenderer* rend = new GLRenderer;
+	rend->setAttribute (Qt::WA_DontShowOnScreen);
+	rend->show ();
 	rend->setFile (file);
 	rend->setDrawOnly (true);
-	rend->show ();
+	rend->compileAllObjects ();
+	rend->initGLData ();
+	rend->drawGLScene ();
+	uchar* imagedata = rend->screencap (w, h);
+	
+	QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored ();
+	if (img.isNull ()) {
+		critical ("Failed to create the image!\n");
+	} else {
+		QLabel* label = new QLabel;
+		QDialog* dlg = new QDialog;
+		label->setPixmap (QPixmap::fromImage (img));
+		QVBoxLayout* layout = new QVBoxLayout (dlg);
+		layout->addWidget (label);
+		dlg->exec ();
+	}
+	
+	delete[] imagedata;
+	rend->deleteLater ();
 }
\ No newline at end of file
--- a/src/gui_editactions.cpp	Fri May 24 16:43:56 2013 +0300
+++ b/src/gui_editactions.cpp	Fri May 24 19:44:53 2013 +0300
@@ -198,7 +198,7 @@
 		LDRadial* rad = static_cast<LDRadial*> (obj);
 		str name = rad->makeFileName ();
 		
-		LDOpenFile* file = loadFile (name);
+		LDOpenFile* file = getFile (name);
 		if (file == null) {
 			fails << name;
 			continue;

mercurial