summaryrefslogtreecommitdiff
path: root/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'opengl')
-rw-r--r--opengl/.cvsignore2
-rw-r--r--opengl/GNUmakefile77
-rw-r--r--opengl/dialog.h35
-rw-r--r--opengl/dialog.rc23
-rw-r--r--opengl/generate.cpp392
-rw-r--r--opengl/generate.h72
-rw-r--r--opengl/gldialog.cpp142
-rw-r--r--opengl/gldialog.h63
-rw-r--r--opengl/main.cpp74
9 files changed, 880 insertions, 0 deletions
diff --git a/opengl/.cvsignore b/opengl/.cvsignore
new file mode 100644
index 0000000..1efcba0
--- /dev/null
+++ b/opengl/.cvsignore
@@ -0,0 +1,2 @@
+msGLExport.dll
+dialog.RES \ No newline at end of file
diff --git a/opengl/GNUmakefile b/opengl/GNUmakefile
new file mode 100644
index 0000000..0259322
--- /dev/null
+++ b/opengl/GNUmakefile
@@ -0,0 +1,77 @@
+# MSPlugins - Simple OpenGL Milkshape plugin
+#
+# Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -------------------------------------------------------------------------
+#
+# $Id: GNUmakefile,v 1.1 2005-04-15 00:53:56 ianc Exp $
+#
+include ../make.conf
+
+TARGET = msGLExport
+
+RES = dialog
+
+SOURCES = main.cpp \
+ gldialog.cpp \
+ generate.cpp
+
+HEADERS = $(RES).h \
+ gldialog.h \
+ generate.h
+
+OBJECTS = $(SOURCES:.cpp=.o) $(RES).o
+
+OUTDLL = $(TARGET).dll
+
+OUTLIB = $(TARGET).a
+
+WRAPPER = ../wrapper
+
+DLLLIBS = $(WRAPPER)/mingwms.lib $(MILKSHAPE)/lib/msModelLib.lib \
+ `w32dlib-config --libs`
+
+FLAGS = -I$(WRAPPER) -I$(MILKSHAPE) -Wall `w32dlib-config --cflags`
+
+
+$(OUTDLL): $(OBJECTS)
+ dllwrap --output-lib=$(OUTLIB) --dllname=$(OUTDLL) \
+ --driver-name=c++ $(OBJECTS) $(DLLLIBS)
+
+# Unfortunately the windres resource compiler doesn't like my RC, so you
+# need RC.EXE from the Platform SDK to compile it to a RES first.
+#
+$(RES).o: $(RES).res
+ windres -v -i $(RES).res -o $(RES).o
+
+$(RES).res: $(RES).rc $(RES).h
+ rc $(RES).rc
+
+%.o: %.cpp
+ $(CXX) -c $(FLAGS) $< -o $@
+
+-include depend.mak
+
+clean:
+ -rm -f $(OUTDLL) $(OUTLIB) $(OBJECTS) $(RES).res depend.mak
+
+depend:
+ @echo Dependencies updated....
+ $(CXX) -MM $(FLAGS) $(SOURCES) > depend.mak
+
+
+# END OF FILE
diff --git a/opengl/dialog.h b/opengl/dialog.h
new file mode 100644
index 0000000..4955fd6
--- /dev/null
+++ b/opengl/dialog.h
@@ -0,0 +1,35 @@
+//
+// msGLExport - OpenGL exporter for Milkshape
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// -------------------------------------------------------------------------
+//
+// $Id$
+//
+#define GL_DIALOG 101
+
+#define IDC_BUT_SELECTDIR 3004
+#define IDC_TXT_FUNCNAME 3009
+#define IDC_CHK_TEXTURE 3008
+#define IDC_CHK_DEFINE 3010
+#define IDC_BUT_CANCEL 3002
+#define IDC_BUT_GENERATE 3001
+#define IDC_TXT_INFO 3000
+#define IDC_TXT_DIR 3003
+#define IDC_CHK_FORCECOG 3011
+#define IDC_CHK_BLITZMAX 3012
diff --git a/opengl/dialog.rc b/opengl/dialog.rc
new file mode 100644
index 0000000..68f85e5
--- /dev/null
+++ b/opengl/dialog.rc
@@ -0,0 +1,23 @@
+#include <windows.h>
+#include "dialog.h"
+
+GL_DIALOG DIALOG 0, 0, 337, 181
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
+CAPTION "OpenGL Export"
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+FONT 8, "MS Sans Serif"
+{
+ CONTROL "...", IDC_BUT_SELECTDIR, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 240, 90, 25, 15
+ CONTROL "", IDC_TXT_FUNCNAME, EDIT, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 65, 110, 145, 12
+ CONTROL "Use Textures", IDC_CHK_TEXTURE, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 5, 135, 60, 10
+ CONTROL "Generate info", IDC_CHK_DEFINE, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 75, 135, 85, 10
+ CONTROL "Cancel", IDC_BUT_CANCEL, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 170, 160, 75, 15
+ CONTROL "Generate", IDC_BUT_GENERATE, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 255, 160, 75, 15
+ CONTROL "", IDC_TXT_INFO, EDIT, ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL, 5, 15, 325, 70
+ CONTROL "", IDC_TXT_DIR, EDIT, ES_LEFT | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER, 65, 90, 170, 12
+ CONTROL "Directory", -1, STATIC, SS_LEFT | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 90, 30, 10
+ CONTROL "Function/object", -1, STATIC, SS_LEFT | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 110, 55, 10
+ CONTROL "Force COG to 0,0,0", IDC_CHK_FORCECOG, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 165, 135, 75, 10
+ CONTROL "Generate for Blitz MAX", IDC_CHK_BLITZMAX, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 248, 135, 85, 10
+ CONTROL "Info:", -1, STATIC, SS_LEFT | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 5, 15, 10
+}
diff --git a/opengl/generate.cpp b/opengl/generate.cpp
new file mode 100644
index 0000000..cdce010
--- /dev/null
+++ b/opengl/generate.cpp
@@ -0,0 +1,392 @@
+// Generate.cpp: implementation of the Generate class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include <sstream>
+#include <algorithm>
+#include <cctype>
+#include <cstdio>
+#include <w32dlib/w32dlib.h>
+#include "generate.h"
+#include "msLib.h"
+
+#define INDENT " "
+#define EOL "\r\n"
+
+#define FLT_MAX 10e35
+#define FLT_MIN -10e35
+
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+Generate::Generate(msModel *model) : m_model(model),
+
+ m_cogx(0),
+ m_cogy(0),
+ m_cogz(0),
+
+ m_appcogx(0),
+ m_appcogy(0),
+ m_appcogz(0),
+
+ m_max_x(FLT_MIN),
+ m_min_x(FLT_MAX),
+ m_max_y(FLT_MIN),
+ m_min_y(FLT_MAX),
+ m_max_z(FLT_MIN),
+ m_min_z(FLT_MAX)
+{
+ CalcModelBounds();
+}
+
+Generate::~Generate()
+{
+}
+
+//////////////////////////////////////////////////////////////////////
+// Public members
+//////////////////////////////////////////////////////////////////////
+
+std::string Generate::Info()
+{
+ std::ostringstream str;
+
+ str << "Create files : " << EOL
+ << "\t" << m_dir << "\\" << m_funcName << ".c" << EOL
+ << "\t" << m_dir << "\\" << m_funcName << ".h" << EOL << EOL
+ << "Centre of gravity : "
+ << (m_cogx-m_appcogx) << ","
+ << (m_cogy-m_appcogy) << ","
+ << (m_cogz-m_appcogz) << EOL
+ << "Lowest X co-ord : " << m_min_x-m_appcogx << EOL
+ << "Highest X co-ord : " << m_max_x-m_appcogx << EOL
+ << "Lowest Y co-ord : " << m_min_y-m_appcogx << EOL
+ << "Highest Y co-ord : " << m_max_y-m_appcogx << EOL
+ << "Lowest Z co-ord : " << m_min_z-m_appcogx << EOL
+ << "Highest Z co-ord : " << m_max_z-m_appcogx << EOL;
+
+ return str.str();
+}
+
+void Generate::MakeFiles()
+{
+ std::FILE *fp;
+ int len;
+ std::string fname_c;
+ std::string fname_h;
+ std::string def;
+ std::string missing;
+
+ len=m_funcName.length()+6;
+
+ fname_c=m_dir+"\\"+m_funcName;
+ fname_h=fname_c+".h";
+ fname_c+=".c";
+
+ for(std::string::const_iterator i=m_funcName.begin();
+ i!=m_funcName.end();++i)
+ {
+ def+=std::toupper(*i);
+ }
+
+ // Generate header
+ //
+ if (!(fp=fopen(fname_h.c_str(),"w")))
+ {
+ W32DLib::Common::Error(0,"Couldn't create header file");
+ return;
+ }
+
+ std::fprintf(fp,"%s","/* Code generated with Milkshape "
+ "Export OpenGL plugin\n*/\n");
+ std::fprintf(fp,"\n");
+
+ std::fprintf(fp,"#ifndef %s_H\n#define %s_H\n\n",
+ def.c_str(),def.c_str());
+
+ std::fprintf(fp,"%s","#ifdef _cplusplus\nextern \"C\" {\n#endif\n\n");
+
+
+ std::fprintf(fp,"void %s(GLfloat x, GLfloat y, GLfloat z,\n",
+ m_funcName.c_str());
+ std::fprintf(fp,"%sGLfloat rot_x, GLfloat rot_y, GLfloat rot_z",
+ Space(len));
+
+ if (m_useTexture)
+ {
+ std::fprintf(fp,",\n%sGLint tid);\n\n", Space(len));
+ }
+ else
+ {
+ std::fprintf(fp,");\n\n");
+ }
+
+ if (m_useInfo)
+ {
+ std::fprintf(fp,"#define %s_COG_X %f\n",def.c_str(),m_cogx-m_appcogx);
+ std::fprintf(fp,"#define %s_COG_Y %f\n",def.c_str(),m_cogy-m_appcogy);
+ std::fprintf(fp,"#define %s_COG_Z %f\n\n",def.c_str(),m_cogz-m_appcogz);
+
+ std::fprintf(fp,"#define %s_MIN_X %f\n",def.c_str(),m_min_x-m_appcogx);
+ std::fprintf(fp,"#define %s_MAX_X %f\n",def.c_str(),m_max_x-m_appcogx);
+ std::fprintf(fp,"#define %s_MIN_Y %f\n",def.c_str(),m_min_y-m_appcogy);
+ std::fprintf(fp,"#define %s_MAX_Y %f\n",def.c_str(),m_max_y-m_appcogy);
+ std::fprintf(fp,"#define %s_MIN_Z %f\n",def.c_str(),m_min_z-m_appcogz);
+ std::fprintf(fp,"#define %s_MAX_Z %f\n\n",def.c_str(),
+ m_max_z-m_appcogz);
+
+ float sx=m_max_x-m_min_x;
+ float sy=m_max_y-m_min_y;
+ float sz=m_max_z-m_min_z;
+
+ std::fprintf(fp,"#define %s_SIZE_X %f\n",def.c_str(),sx);
+ std::fprintf(fp,"#define %s_SIZE_Y %f\n",def.c_str(),sy);
+ std::fprintf(fp,"#define %s_SIZE_Z %f\n\n",def.c_str(),sz);
+ }
+
+ std::fprintf(fp,"#define %s_TEXTURED %d\n\n",def.c_str(),m_useTexture?1:0);
+
+ std::fprintf(fp,"%s","#ifdef _cplusplus\n}\n#endif\n\n");
+
+ std::fprintf(fp,"#endif /* %s_H */\n\n",def.c_str());
+
+ std::fprintf(fp,"%s","/* END OF FILE */\n");
+
+ std::fclose(fp);
+
+ // Generate C source
+ //
+ if (!(fp=fopen(fname_c.c_str(),"w")))
+ {
+ W32DLib::Common::Error(0,"Couldn't create source file");
+ return;
+ }
+
+ std::fprintf(fp,"%s","/* Code generated with Milkshape "
+ "Export OpenGL plugin\n*/\n");
+
+ std::fprintf(fp,"%s","#include <GL/gl.h>\n\n");
+
+ std::fprintf(fp,"void %s(GLfloat x, GLfloat y, GLfloat z,\n",
+ m_funcName.c_str());
+ std::fprintf(fp,"%sGLfloat rot_x, GLfloat rot_y, GLfloat rot_z",
+ Space(len));
+
+ if (m_useTexture)
+ {
+ std::fprintf(fp,",\n%sGLint tid)\n", Space(len));
+ }
+ else
+ {
+ std::fprintf(fp,")\n");
+ }
+
+ std::fprintf(fp,"{\n");
+
+ std::fprintf(fp,INDENT "glPushMatrix();\n");
+ std::fprintf(fp,INDENT "glLoadIdentity();\n");
+ std::fprintf(fp,INDENT "glTranslatef(x,y,z);\n");
+ std::fprintf(fp,INDENT "glRotatef(rot_x,1.0f,0.0f,0.0f);\n"),
+ std::fprintf(fp,INDENT "glRotatef(rot_y,0.0f,1.0f,0.0f);\n"),
+ std::fprintf(fp,INDENT "glRotatef(rot_z,0.0f,0.0f,1.0f);\n"),
+ std::fprintf(fp,"\n");
+
+ std::fprintf(fp,INDENT "glBegin(GL_TRIANGLES);\n");
+
+ if (m_useTexture)
+ {
+ std::fprintf(fp,INDENT "glBindTexture(GL_TEXTURE_2D,tid);\n");
+ }
+
+ std::fprintf(fp,"\n");
+
+ for(int m=0;m<m_model->nNumMeshes;m++)
+ {
+ msMesh *mesh=m_model->pMeshes+m;
+
+ std::fprintf(fp,INDENT "/* Mesh %d - %s\n",m+1,mesh->szName);
+ std::fprintf(fp,INDENT "*/\n");
+
+ if (mesh->nMaterialIndex<0)
+ {
+ missing+=mesh->szName;
+ missing+="\n";
+
+ std::fprintf(fp,INDENT "glColor3f(1.0f,1.0f,1.0f);\n");
+ }
+ else
+ {
+ msMaterial *mat=m_model->pMaterials+mesh->nMaterialIndex;
+
+ std::fprintf(fp,INDENT "glColor3f(%f,%f,%f);\n",
+ mat->Diffuse[0],
+ mat->Diffuse[1],
+ mat->Diffuse[2]);
+ }
+
+ for(int t=0;t<mesh->nNumTriangles;t++)
+ {
+ msTriangle *tri;
+
+ tri=mesh->pTriangles+t;
+
+ if (!(tri->nFlags&eHidden))
+ {
+ // To allow vertex order to be tweaked...
+ //
+ static int order[3]={0,1,2};
+
+ for(int i=0;i<3;i++)
+ {
+ msVertex *v=mesh->pVertices+tri->nVertexIndices[order[i]];
+
+ std::fprintf(fp,INDENT "glVertex3f(%f,%f,%f);\n",
+ v->Vertex[0]-m_appcogx,
+ v->Vertex[1]-m_appcogy,
+ v->Vertex[2]-m_appcogz);
+
+ if (m_useTexture)
+ {
+ std::fprintf(fp,INDENT "glTexCoord2f(%f,%f);\n",
+ v->u,
+ v->v);
+ }
+ }
+ }
+ }
+
+ std::fprintf(fp,"\n");
+ }
+
+ std::fprintf(fp,INDENT "glEnd();\n");
+ std::fprintf(fp,INDENT "glPopMatrix();\n");
+
+ std::fprintf(fp,"}\n");
+
+ std::fclose(fp);
+
+ if (missing.length()>0)
+ {
+ missing="The following meshes had no material:\n\n"+missing;
+ missing+="\n\nThey were given the colour white.";
+
+ W32DLib::Common::Message(0,missing);
+ }
+}
+
+
+void Generate::Setup(const std::string& dir,
+ const std::string& funcname,
+ bool texture,
+ bool info,
+ bool forceCOG)
+{
+ m_dir=dir;
+ m_funcName=funcname;
+ m_useTexture=texture;
+ m_useInfo=info;
+ m_forceCOG=forceCOG;
+
+ if (m_forceCOG)
+ {
+ m_appcogx=m_cogx;
+ m_appcogy=m_cogy;
+ m_appcogz=m_cogz;
+ }
+ else
+ {
+ m_appcogx=0;
+ m_appcogy=0;
+ m_appcogz=0;
+ }
+}
+
+
+std::string Generate::GenerateFuncname()
+{
+ std::string fn;
+ char *name;
+
+ msMesh *mesh=msModel_GetMeshAt(m_model,0);
+
+ name=mesh->szName;
+
+ for(int f=0;name[f];f++)
+ {
+ if (std::isalpha(name[f]) || (f && name[f]=='_'))
+ {
+ fn+=name[f];
+ }
+ }
+
+ if (fn=="")
+ {
+ fn="object";
+ }
+
+ return fn;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+// Private members
+//////////////////////////////////////////////////////////////////////
+
+const char *Generate::Space(int len)
+{
+ static int cyc=0;
+ static char buff[10][128];
+ int f;
+
+ cyc=(cyc+1)%10;
+
+ for(f=0;f<len && f < 126;f++)
+ {
+ buff[cyc][f]=' ';
+ }
+
+ buff[cyc][f]=0;
+
+ return &buff[cyc][0];
+}
+
+
+void Generate::CalcModelBounds()
+{
+ for(int m=0;m<m_model->nNumMeshes;m++)
+ {
+ msMesh *mesh;
+
+ mesh=m_model->pMeshes+m;
+
+ for(int t=0;t<mesh->nNumTriangles;t++)
+ {
+ msTriangle *tri;
+
+ tri=mesh->pTriangles+t;
+
+ if (!(tri->nFlags&eHidden))
+ {
+ for(int i=0;i<3;i++)
+ {
+ msVertex *v=mesh->pVertices+tri->nVertexIndices[i];
+
+ m_min_x=std::min(m_min_x,v->Vertex[0]);
+ m_max_x=std::max(m_max_x,v->Vertex[0]);
+
+ m_min_y=std::min(m_min_y,v->Vertex[1]);
+ m_max_y=std::max(m_max_y,v->Vertex[1]);
+
+ m_min_z=std::min(m_min_z,v->Vertex[2]);
+ m_max_z=std::max(m_max_z,v->Vertex[2]);
+ }
+ }
+ }
+ }
+
+ m_cogx=m_min_x+(m_max_x-m_min_x)/2;
+ m_cogy=m_min_y+(m_max_y-m_min_y)/2;
+ m_cogz=m_min_z+(m_max_z-m_min_z)/2;
+}
diff --git a/opengl/generate.h b/opengl/generate.h
new file mode 100644
index 0000000..2aa1ec1
--- /dev/null
+++ b/opengl/generate.h
@@ -0,0 +1,72 @@
+// msGLExport - OpenGL exporter for Milkshape
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// -------------------------------------------------------------------------
+//
+// $Id$
+//
+#ifndef GENERATE_H
+#define GENERATE_H
+
+#include <string>
+#include <msLib.h>
+
+class Generate
+{
+public:
+ Generate(msModel *model);
+ virtual ~Generate();
+
+ std::string GenerateFuncname();
+ void Setup(const std::string& dir,
+ const std::string& funcname,
+ bool texture,
+ bool info,
+ bool forceCOG);
+ void MakeFiles();
+ std::string Info();
+
+private:
+ msModel *m_model;
+ std::string m_funcName;
+ std::string m_dir;
+ bool m_useTexture;
+ bool m_useInfo;
+ bool m_forceCOG;
+
+ float m_cogx;
+ float m_cogy;
+ float m_cogz;
+
+ float m_appcogx;
+ float m_appcogy;
+ float m_appcogz;
+
+ float m_max_x;
+ float m_min_x;
+ float m_max_y;
+ float m_min_y;
+ float m_max_z;
+ float m_min_z;
+
+ const char *Space(int len);
+
+ void CalcModelBounds();
+};
+
+#endif // GENERATE_H
diff --git a/opengl/gldialog.cpp b/opengl/gldialog.cpp
new file mode 100644
index 0000000..c279944
--- /dev/null
+++ b/opengl/gldialog.cpp
@@ -0,0 +1,142 @@
+// msGLExport - OpenGL exporter for Milkshape
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// -------------------------------------------------------------------------
+//
+static const char rcs_id[]="$Id$";
+
+#include "gldialog.h"
+#include "dialog.h"
+
+
+/////////////////////////////////////////////////////////////////////////////
+// GLDialog dialog
+
+
+GLDialog::GLDialog(Generate& gen)
+ : m_gen(gen)
+ , m_dirButton(this,IDC_BUT_SELECTDIR,0)
+ , m_funcName(this,IDC_TXT_FUNCNAME,0)
+ , m_useTexture(this,IDC_CHK_TEXTURE,0)
+ , m_useInfo(this,IDC_CHK_DEFINE,0)
+ , m_cancelButton(this,IDC_BUT_CANCEL,0)
+ , m_genButton(this,IDC_BUT_GENERATE,0)
+ , m_info(this,IDC_TXT_INFO,0)
+ , m_dir(this,IDC_TXT_DIR,0)
+ , m_forceCOG(this,IDC_CHK_FORCECOG,0)
+ , m_blitzMax(this,IDC_CHK_BLITZMAX,0)
+{
+ char path[1024];
+
+ GetCurrentDirectory(sizeof path,path);
+
+ m_fname=path;
+
+ m_dirButton.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnSelect));
+
+ m_cancelButton.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnCancel));
+
+ m_genButton.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnGenerate));
+
+ m_funcName.OnTextChanged
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnChange));
+
+ m_useTexture.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnChange));
+
+ m_useInfo.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnChange));
+
+ m_forceCOG.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnChange));
+
+ m_blitzMax.OnPress
+ (this,static_cast<W32DLib::W32DLibCallback>(&GLDialog::OnChange));
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+// GLDialog public members
+
+int GLDialog::ResourceID()
+{
+ return GL_DIALOG;
+}
+
+
+void GLDialog::OnInit()
+{
+ m_dir.SetText(m_fname);
+ m_funcName.SetText(m_gen.GenerateFuncname());
+ m_genButton.Enable(true);
+ Preview();
+}
+
+
+
+/////////////////////////////////////////////////////////////////////////////
+// GLDialog message handlers
+
+BOOL GLDialog::OnGenerate(UINT msg, WPARAM wp, LPARAM lp)
+{
+ Close(IDOK);
+ return TRUE;
+}
+
+
+BOOL GLDialog::OnSelect(UINT msg, WPARAM wp, LPARAM lp)
+{
+ if (W32DLib::Common::SelectDir(m_wnd,"Select Directory",m_fname))
+ {
+ OnChange(msg,wp,lp);
+ }
+ return TRUE;
+}
+
+
+BOOL GLDialog::OnCancel(UINT msg, WPARAM wp, LPARAM lp)
+{
+ Close(IDCANCEL);
+ return TRUE;
+}
+
+
+BOOL GLDialog::OnChange(UINT msg, WPARAM wp, LPARAM lp)
+{
+ Preview();
+ m_genButton.Enable(m_funcName.GetText().length()!=0);
+ return TRUE;
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+// GLDialog private members
+
+void GLDialog::Preview()
+{
+ m_gen.Setup(m_fname,
+ m_funcName.GetText(),
+ m_useTexture.GetState(),
+ m_useInfo.GetState(),
+ m_forceCOG.GetState());
+
+ m_info.SetText(m_gen.Info());
+}
diff --git a/opengl/gldialog.h b/opengl/gldialog.h
new file mode 100644
index 0000000..675454d
--- /dev/null
+++ b/opengl/gldialog.h
@@ -0,0 +1,63 @@
+// msGLExport - OpenGL exporter for Milkshape
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// -------------------------------------------------------------------------
+//
+// $Id$
+//
+#ifndef GLDIALOG_H
+#define GLDIALOG_H
+
+#include <w32dlib/w32dlib.h>
+#include "generate.h"
+
+class GLDialog : public W32DLib::Dialog
+{
+public:
+ GLDialog(Generate& gen);
+
+ int ResourceID();
+
+ void OnInit();
+
+private:
+
+ Generate& m_gen;
+
+ W32DLib::Button m_dirButton;
+ W32DLib::Text m_funcName;
+ W32DLib::AutoCheck m_useTexture;
+ W32DLib::AutoCheck m_useInfo;
+ W32DLib::Button m_cancelButton;
+ W32DLib::Button m_genButton;
+ W32DLib::Text m_info;
+ W32DLib::Text m_dir;
+ W32DLib::AutoCheck m_forceCOG;
+ W32DLib::AutoCheck m_blitzMax;
+
+ std::string m_fname;
+
+ BOOL OnGenerate(UINT msg, WPARAM wp, LPARAM lp);
+ BOOL OnSelect(UINT msg, WPARAM wp, LPARAM lp);
+ BOOL OnCancel(UINT msg, WPARAM wp, LPARAM lp);
+ BOOL OnChange(UINT msg, WPARAM wp, LPARAM lp);
+
+ void Preview();
+};
+
+#endif // GLDIALOG_H
diff --git a/opengl/main.cpp b/opengl/main.cpp
new file mode 100644
index 0000000..19ca5a9
--- /dev/null
+++ b/opengl/main.cpp
@@ -0,0 +1,74 @@
+// msGLExport - OpenGL exporter for Milkshape
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// -------------------------------------------------------------------------
+//
+static const char rcs_id[]="$Id$";
+
+#include <cstring>
+#include <cstdio>
+
+#include "mingwms.h"
+#include "msLib.h"
+
+#include "gldialog.h"
+
+
+// ----------------------------------------------------------------------
+// MINGW WRAPPER FUNCTIONS
+//
+static const char* GetTitle()
+{
+ return "Simple OpenGL";
+}
+
+static int Execute(msModel* model)
+{
+ if (!model)
+ {
+ return -1;
+ }
+
+ if (msModel_GetMeshCount(model)<1)
+ {
+ W32DLib::Common::Error(NULL,"No meshes in the model!");
+ return 0;
+ }
+
+ W32DLib::Common::Initialise();
+
+ Generate gen(model);
+ GLDialog dlg(gen);
+
+ if (dlg.ShowModal(W32DLib::Common::GetInstance(),NULL)==IDOK)
+ {
+ SetCursor(LoadCursor(NULL,IDC_WAIT));
+ gen.MakeFiles();
+ SetCursor(LoadCursor(NULL,IDC_ARROW));
+ }
+
+ return 1;
+}
+
+PLUGIN_SPEC void* CreatePlugIn()
+{
+ return CreateMINGWPlugin(MS_TYPE_EXPORT, GetTitle, Execute);
+}
+
+
+// END OF FILE