summaryrefslogtreecommitdiff
path: root/opengl/generate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'opengl/generate.cpp')
-rw-r--r--opengl/generate.cpp496
1 files changed, 265 insertions, 231 deletions
diff --git a/opengl/generate.cpp b/opengl/generate.cpp
index 33d2f13..960fd7c 100644
--- a/opengl/generate.cpp
+++ b/opengl/generate.cpp
@@ -5,7 +5,7 @@
#include <sstream>
#include <algorithm>
#include <cctype>
-#include <cstdio>
+#include <stdarg.h>
#include <w32dlib/w32dlib.h>
#include "generate.h"
#include "msLib.h"
@@ -38,7 +38,9 @@ Generate::Generate(msModel *model) : m_model(model),
m_max_z(FLT_MIN),
m_min_z(FLT_MAX),
- m_blitzMax(false)
+ m_blitzMax(false),
+ m_normals(false),
+ m_indent(0)
{
CalcModelBounds();
}
@@ -83,6 +85,23 @@ std::string Generate::Info()
void Generate::MakeFiles(HWND parent)
{
+ if (m_normals)
+ {
+ for(int m=0;m<m_model->nNumMeshes;m++)
+ {
+ msMesh *mesh=m_model->pMeshes+m;
+
+ if (mesh->nMaterialIndex<0)
+ {
+ W32DLib::Common::Error
+ (parent,0,
+ "Materials must be assigned if the object is to be lit");
+
+ return;
+ }
+ }
+ }
+
if (m_blitzMax)
{
GenerateBlitzMax(parent);
@@ -99,7 +118,8 @@ void Generate::Setup(const std::string& dir,
bool texture,
bool info,
bool forceCOG,
- bool blitzMax)
+ bool blitzMax,
+ bool vertex_normals)
{
m_dir=dir;
m_funcName=funcname;
@@ -107,6 +127,7 @@ void Generate::Setup(const std::string& dir,
m_useInfo=info;
m_forceCOG=forceCOG;
m_blitzMax=blitzMax;
+ m_normals=vertex_normals;
if (m_forceCOG)
{
@@ -134,7 +155,7 @@ std::string Generate::GenerateFuncname()
for(int f=0;name[f];f++)
{
- if (std::isalpha(name[f]) || (f && name[f]=='_'))
+ if (std::isalnum(name[f]) || (f && name[f]=='_'))
{
fn+=name[f];
}
@@ -172,6 +193,29 @@ const char *Generate::Space(int len)
}
+void Generate::Output(const char *fmt, ...)
+{
+ if (m_fp==0)
+ {
+ return;
+ }
+
+ if (*fmt!='\n')
+ {
+ for(int f=0;f<m_indent;f++)
+ {
+ std::fprintf(m_fp,"%s",INDENT);
+ }
+ }
+
+ va_list va;
+
+ va_start(va,fmt);
+ std::vfprintf(m_fp,fmt,va);
+ va_end(va);
+}
+
+
void Generate::CalcModelBounds()
{
for(int m=0;m<m_model->nNumMeshes;m++)
@@ -213,13 +257,14 @@ void Generate::CalcModelBounds()
void Generate::GenerateC(HWND parent)
{
- std::FILE *fp;
int len;
std::string fname_c;
std::string fname_h;
std::string def;
std::string missing;
+ m_indent=0;
+
len=m_funcName.length()+6;
fname_c=m_dir+"\\"+m_funcName;
@@ -234,179 +279,113 @@ void Generate::GenerateC(HWND parent)
// Generate header
//
- if (!(fp=fopen(fname_h.c_str(),"w")))
+ if (!(m_fp=fopen(fname_h.c_str(),"w")))
{
W32DLib::Common::Error(parent,0,"Couldn't create header file");
return;
}
- std::fprintf(fp,"%s","/* Code generated with Milkshape "
- "Export OpenGL plugin\n*/\n");
- std::fprintf(fp,"\n");
+ Output("%s","/* Code generated with Milkshape Export OpenGL plugin\n*/\n");
+ Output("\n");
- std::fprintf(fp,"#ifndef %s_H\n#define %s_H\n\n",
+ Output("#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");
+ Output("%s","#ifdef _cplusplus\nextern \"C\" {\n#endif\n\n");
- std::fprintf(fp,"void %s(GLfloat x, GLfloat y, GLfloat z,\n",
+ Output("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",
+ Output("%sGLfloat rot_x, GLfloat rot_y, GLfloat rot_z",
Space(len));
if (m_useTexture)
{
- std::fprintf(fp,",\n%sGLint tid);\n\n", Space(len));
+ Output(",\n%sGLint texture_id);\n\n", Space(len));
}
else
{
- std::fprintf(fp,");\n\n");
+ Output(");\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);
+ Output("#define %s_COG_X %f\n",def.c_str(),m_cogx-m_appcogx);
+ Output("#define %s_COG_Y %f\n",def.c_str(),m_cogy-m_appcogy);
+ Output("#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);
+ Output("#define %s_MIN_X %f\n",def.c_str(),m_min_x-m_appcogx);
+ Output("#define %s_MAX_X %f\n",def.c_str(),m_max_x-m_appcogx);
+ Output("#define %s_MIN_Y %f\n",def.c_str(),m_min_y-m_appcogy);
+ Output("#define %s_MAX_Y %f\n",def.c_str(),m_max_y-m_appcogy);
+ Output("#define %s_MIN_Z %f\n",def.c_str(),m_min_z-m_appcogz);
+ Output("#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);
+ Output("#define %s_SIZE_X %f\n",def.c_str(),sx);
+ Output("#define %s_SIZE_Y %f\n",def.c_str(),sy);
+ Output("#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);
+ Output("#define %s_TEXTURED %d\n\n",def.c_str(),m_useTexture?1:0);
- std::fprintf(fp,"%s","#ifdef _cplusplus\n}\n#endif\n\n");
+ Output("%s","#ifdef _cplusplus\n}\n#endif\n\n");
- std::fprintf(fp,"#endif /* %s_H */\n\n",def.c_str());
+ Output("#endif /* %s_H */\n\n",def.c_str());
- std::fprintf(fp,"%s","/* END OF FILE */\n");
+ Output("%s","/* END OF FILE */\n");
- std::fclose(fp);
+ std::fclose(m_fp);
// Generate C source
//
- if (!(fp=fopen(fname_c.c_str(),"w")))
+ if (!(m_fp=fopen(fname_c.c_str(),"w")))
{
W32DLib::Common::Error(parent,0,"Couldn't create source file");
return;
}
- std::fprintf(fp,"%s","/* Code generated with Milkshape "
- "Export OpenGL plugin\n*/\n");
+ Output("%s","/* Code generated with Milkshape Export OpenGL plugin\n*/\n");
- std::fprintf(fp,"%s","#include <GL/gl.h>\n\n");
+ Output("%s","#include <GL/gl.h>\n\n");
- std::fprintf(fp,"void %s(GLfloat x, GLfloat y, GLfloat z,\n",
+ Output("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",
+ Output("%sGLfloat rot_x, GLfloat rot_y, GLfloat rot_z",
Space(len));
if (m_useTexture)
{
- std::fprintf(fp,",\n%sGLint tid)\n", Space(len));
+ Output(",\n%sGLint texture_id)\n", Space(len));
}
else
{
- std::fprintf(fp,")\n");
+ Output(")\n");
}
- std::fprintf(fp,"{\n");
+ Output("{\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");
+ m_indent++;
- std::fprintf(fp,INDENT "glBegin(GL_TRIANGLES);\n");
-
- if (m_useTexture)
+ if (m_normals)
{
- std::fprintf(fp,INDENT "glBindTexture(GL_TEXTURE_2D,tid);\n");
+ Output("GLfloat ambient[4];\n");
+ Output("GLfloat diffuse[4];\n");
+ Output("GLfloat specular[4];\n");
+ Output("GLfloat emission[4];\n");
+ Output("\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;
+ GenerateCommon(missing,";","/*","*/");
- if (!(tri->nFlags&eHidden))
- {
- // To allow vertex order to be tweaked...
- //
- static int order[3]={0,1,2};
+ m_indent--;
- for(int i=0;i<3;i++)
- {
- msVertex *v=mesh->pVertices+tri->nVertexIndices[order[i]];
+ Output("}\n");
- 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);
+ std::fclose(m_fp);
if (missing.length()>0)
{
@@ -420,158 +399,177 @@ void Generate::GenerateC(HWND parent)
void Generate::GenerateBlitzMax(HWND parent)
{
- std::FILE *fp;
- int len;
- std::string fname_c;
- std::string fname_h;
- std::string def;
+ std::string fname_bmx;
std::string missing;
- len=m_funcName.length()+6;
+ fname_bmx=m_dir+"\\"+m_funcName+".bmx";
- fname_c=m_dir+"\\"+m_funcName;
- fname_h=fname_c+".h";
- fname_c+=".c";
+ m_indent=0;
- for(std::string::const_iterator i=m_funcName.begin();
- i!=m_funcName.end();++i)
- {
- def+=std::toupper(*i);
- }
-
- // Generate header
+ // Generate class
//
- if (!(fp=fopen(fname_h.c_str(),"w")))
+ if (!(m_fp=fopen(fname_bmx.c_str(),"w")))
{
- W32DLib::Common::Error(parent,0,"Couldn't create header file");
+ W32DLib::Common::Error(parent,0,"Couldn't create source 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");
+ Output("%s","' Code generated with Milkshape Export OpenGL plugin\n'\n");
+ Output("\n");
+ Output("Type %s\n",m_funcName.c_str());
+ Output("\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");
- }
+ m_indent++;
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);
+ Output("' Consts relating to the model's size and centre of gravity\n");
+ Output("'\n");
+ Output("Const COG_X:Float=%f\n",m_cogx-m_appcogx);
+ Output("Const COG_Y:Float=%f\n",m_cogy-m_appcogy);
+ Output("Const COG_Z:Float=%f\n\n",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);
+ Output("Const MIN_X:Float=%f\n",m_min_x-m_appcogx);
+ Output("Const MAX_X:Float=%f\n",m_max_x-m_appcogx);
+ Output("Const MIN_Y:Float=%f\n",m_min_y-m_appcogy);
+ Output("Const MAX_Y:Float=%f\n",m_max_y-m_appcogy);
+ Output("Const MIN_Z:Float=%f\n",m_min_z-m_appcogz);
+ Output("Const MAX_Z:Float=%f\n\n",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);
- }
+ Output("Const SIZE_X:Float=%f\n",sx);
+ Output("Const SIZE_Y:Float=%f\n",sy);
+ Output("Const SIZE_Z:Float=%f\n\n",sz);
- std::fprintf(fp,"#define %s_TEXTURED %d\n\n",def.c_str(),m_useTexture?1:0);
+ Output("const TEXTURED:Int=%s\n",m_useTexture ? "true":"false");
- std::fprintf(fp,"%s","#ifdef _cplusplus\n}\n#endif\n\n");
+ Output("\n");
+ }
- std::fprintf(fp,"#endif /* %s_H */\n\n",def.c_str());
+ Output("' These fields control the position/orientation of the object\n");
+ Output("'\n");
+ Output("Field x:Float\n");
+ Output("Field y:Float\n");
+ Output("Field z:Float\n");
+ Output("Field rot_x:Float\n");
+ Output("Field rot_y:Float\n");
+ Output("Field rot_z:Float\n");
+ Output("\n");
+
+ Output("' Use this function to create an instance\n");
+ Output("'\n");
+ Output("Function Create:%s()\n",m_funcName.c_str());
+ m_indent++;
+ Output("Local o:%s = New %s\n",m_funcName.c_str(),m_funcName.c_str());
+ Output("o.x=0\n");
+ Output("o.y=0\n");
+ Output("o.z=0\n");
+ Output("o.rot_x=0\n");
+ Output("o.rot_y=0\n");
+ Output("o.rot_z=0\n");
+ Output("return o\n");
+ m_indent--;
+ Output("End Function\n");
+ Output("\n");
+
+ Output("' Use this member to draw the object\n");
+ Output("'\n");
- std::fprintf(fp,"%s","/* END OF FILE */\n");
+ if (m_useTexture)
+ {
+ Output("Method Render(texture_id:Int)\n");
+ }
+ else
+ {
+ Output("Method Render()\n");
+ }
- std::fclose(fp);
+ m_indent++;
- // Generate C source
- //
- if (!(fp=fopen(fname_c.c_str(),"w")))
+ if (m_normals)
{
- W32DLib::Common::Error(parent,0,"Couldn't create source file");
- return;
+ Output("Local ambient:Float[4]\n");
+ Output("Local diffuse:Float[4]\n");
+ Output("Local specular:Float[4]\n");
+ Output("Local emission:Float[4]\n");
+ Output("\n");
}
- std::fprintf(fp,"%s","/* Code generated with Milkshape "
- "Export OpenGL plugin\n*/\n");
+ GenerateCommon(missing,"","'","");
- std::fprintf(fp,"%s","#include <GL/gl.h>\n\n");
+ m_indent--;
- 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));
+ Output("End Method\n");
- if (m_useTexture)
- {
- std::fprintf(fp,",\n%sGLint tid)\n", Space(len));
- }
- else
+ m_indent--;
+
+ Output("End Type\n");
+
+ std::fclose(m_fp);
+
+ if (missing.length()>0)
{
- std::fprintf(fp,")\n");
+ missing="The following meshes had no material:\n\n"+missing;
+ missing+="\n\nThey were given the colour white.";
+
+ W32DLib::Common::Message(parent,0,missing);
}
+}
- 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");
+void Generate::GenerateCommon(std::string& missing,
+ const char *term,
+ const char *start_comment,
+ const char *end_comment)
+{
+ int last_mat=-1;
- std::fprintf(fp,INDENT "glBegin(GL_TRIANGLES);\n");
+ Output("glPushMatrix()%s\n",term);
+ Output("glLoadIdentity()%s\n",term);
+ Output("glTranslatef(x,y,z)%s\n",term);
+ Output("glRotatef(rot_x,1,0,0)%s\n",term);
+ Output("glRotatef(rot_y,0,1,0)%s\n",term);
+ Output("glRotatef(rot_z,0,0,1)%s\n",term);
if (m_useTexture)
{
- std::fprintf(fp,INDENT "glBindTexture(GL_TEXTURE_2D,tid);\n");
+ Output("glBindTexture(GL_TEXTURE_2D,texture_id)%s\n",term);
}
- std::fprintf(fp,"\n");
+ Output("\n");
+ Output("glBegin(GL_TRIANGLES)%s\n",term);
+ Output("\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");
+ Output("%s Mesh %d - %s %s\n",
+ start_comment,m+1,mesh->szName,end_comment);
+ Output("\n");
if (mesh->nMaterialIndex<0)
{
missing+=mesh->szName;
missing+="\n";
- std::fprintf(fp,INDENT "glColor3f(1.0f,1.0f,1.0f);\n");
+ Output("glColor3f(1.0f,1.0f,1.0f)%s\n",term);
+ last_mat=-1;
}
else
{
- msMaterial *mat=m_model->pMaterials+mesh->nMaterialIndex;
+ if (mesh->nMaterialIndex!=last_mat)
+ {
+ 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]);
+ GenerateMaterial(mat,missing,term);
+
+ last_mat=mesh->nMaterialIndex;
+ }
}
for(int t=0;t<mesh->nNumTriangles;t++)
@@ -590,39 +588,75 @@ void Generate::GenerateBlitzMax(HWND parent)
{
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);
+ Output("glTexCoord2f(%f,%f)%s\n",v->u,v->v,term);
}
+
+ if (m_normals)
+ {
+ msVec3 n;
+
+ msMesh_GetVertexNormalAt(mesh,
+ tri->nNormalIndices[order[i]],
+ n);
+
+ Output("glNormal3f(%f,%f,%f)%s\n",
+ n[0],
+ n[1],
+ n[2],
+ term);
+ }
+
+ Output("glVertex3f(%f,%f,%f)%s\n",
+ v->Vertex[0]-m_appcogx,
+ v->Vertex[1]-m_appcogy,
+ v->Vertex[2]-m_appcogz,
+ term);
}
}
}
- std::fprintf(fp,"\n");
- }
-
- std::fprintf(fp,INDENT "glEnd();\n");
- std::fprintf(fp,INDENT "glPopMatrix();\n");
+ Output("\n");
+ }
- std::fprintf(fp,"}\n");
+ Output("glEnd()%s\n",term);
+ Output("glPopMatrix()%s\n",term);
+}
- std::fclose(fp);
- if (missing.length()>0)
+void Generate::GenerateMaterial(msMaterial *mat,
+ std::string& missing,
+ const char *term)
+{
+ if (m_normals)
{
- missing="The following meshes had no material:\n\n"+missing;
- missing+="\n\nThey were given the colour white.";
+ int f;
- W32DLib::Common::Message(parent,0,missing);
+ for(f=0;f<4;f++)
+ {
+ Output("ambient[%d]=%f%s\n",f,mat->Ambient[f],term);
+ Output("diffuse[%d]=%f%s\n",f,mat->Diffuse[f],term);
+ Output("specular[%d]=%f%s\n",f,mat->Specular[f],term);
+ Output("emission[%d]=%f%s\n",f,mat->Emissive[f],term);
+ }
+
+ Output("glMaterialf(GL_FRONT,GL_SHININESS,%f)%s\n",
+ mat->fShininess,term);
+
+ Output("glMaterialfv(GL_FRONT,GL_AMBIENT,ambient)%s\n",term);
+ Output("glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse)%s\n",term);
+ Output("glMaterialfv(GL_FRONT,GL_SPECULAR,specular)%s\n",term);
+ Output("glMaterialfv(GL_FRONT,GL_EMISSION,emission)%s\n",term);
+ }
+ else
+ {
+ Output("glColor3f(%f,%f,%f)%s\n",
+ mat->Diffuse[0],
+ mat->Diffuse[1],
+ mat->Diffuse[2],
+ term);
}
}
-
// END OF FILE