summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorleo2001-01-07 15:09:01 +0000
committerleo2001-01-07 15:09:01 +0000
commite4bf8681d41af8c27ac0c104a80bddc8e7669f9d (patch)
tree6f48317d6b3963c495b136f96a5ddb7f80c93b9d /common
parent33132667d786063f1c0ee9079e5015c463f5f5b0 (diff)
Cross platform Piece Preview
git-svn-id: http://svn.leocad.org/trunk@214 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common')
-rw-r--r--common/preview.cpp74
-rw-r--r--common/preview.h23
2 files changed, 97 insertions, 0 deletions
diff --git a/common/preview.cpp b/common/preview.cpp
new file mode 100644
index 0000000..bc63a0b
--- /dev/null
+++ b/common/preview.cpp
@@ -0,0 +1,74 @@
+//
+// Piece Preview window
+//
+
+#include "preview.h"
+#include "globals.h"
+#include "project.h"
+#include "pieceinf.h"
+
+PiecePreview::PiecePreview (GLWindow *share)
+ : GLWindow (share)
+{
+ m_pPieceInfo = NULL;
+}
+
+PiecePreview::~PiecePreview ()
+{
+}
+
+void PiecePreview::OnDraw ()
+{
+ if (m_pPieceInfo == NULL)
+ return;
+
+ if (!MakeCurrent ())
+ return;
+
+ glEnable (GL_LIGHT0);
+ glEnable (GL_LIGHTING);
+ glEnable (GL_DEPTH_TEST);
+ glDepthFunc (GL_LEQUAL);
+ glEnable (GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset (0.5f, 0.1f);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+ glEnable (GL_COLOR_MATERIAL);
+ glDisable (GL_DITHER);
+ glShadeModel (GL_FLAT);
+
+ double aspect = (float)m_nWidth/(float)m_nHeight;
+ glViewport (0, 0, m_nWidth, m_nHeight);
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+ gluPerspective (30.0f, aspect, 1.0f, 100.0f);
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+ m_pPieceInfo->ZoomExtents ();
+
+ float pos[4] = { 0, 0, 10, 0 }, *bg = project->GetBackgroundColor ();
+ glLightfv (GL_LIGHT0, GL_POSITION, pos);
+ glClearColor (bg[0], bg[1], bg[2], bg[3]);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ m_pPieceInfo->RenderPiece (project->GetCurrentColor ());
+
+ glFinish ();
+ SwapBuffers ();
+}
+
+void PiecePreview::SetCurrentPiece (PieceInfo *pInfo)
+{
+ MakeCurrent ();
+
+ if (m_pPieceInfo != NULL)
+ m_pPieceInfo->DeRef();
+
+ m_pPieceInfo = pInfo;
+
+ if (m_pPieceInfo != NULL)
+ {
+ m_pPieceInfo->AddRef ();
+ project->SetCurrentPiece (m_pPieceInfo);
+ Redraw ();
+ }
+}
diff --git a/common/preview.h b/common/preview.h
new file mode 100644
index 0000000..21ff3a8
--- /dev/null
+++ b/common/preview.h
@@ -0,0 +1,23 @@
+#ifndef _PREVIEW_H_
+#define _PREVIEW_H_
+
+#include "glwindow.h"
+
+class PieceInfo;
+
+class PiecePreview : public GLWindow
+{
+ public:
+ PiecePreview (GLWindow *share);
+ virtual ~PiecePreview ();
+
+ void OnDraw ();
+
+ void SetCurrentPiece (PieceInfo *pInfo);
+
+ private:
+ PieceInfo* m_pPieceInfo;
+};
+
+#endif // _PREVIEW_H_
+