From 3ecd4938767e9fab5a80861fc755dd303da7cfb3 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 27 Apr 2005 00:04:48 +0000 Subject: Document updates and fixed use of in OpenGL --- docs/msGLExport.txt | 214 +++++++++++++++++++++++++++++++++++++++++++++++++- docs/msGrpExplode.txt | 35 +++++++++ opengl/dialog.rc | 2 +- opengl/generate.cpp | 154 ++++++++++++++++++++++++++++++------ 4 files changed, 377 insertions(+), 28 deletions(-) create mode 100644 docs/msGrpExplode.txt diff --git a/docs/msGLExport.txt b/docs/msGLExport.txt index f3cb54b..8eff565 100644 --- a/docs/msGLExport.txt +++ b/docs/msGLExport.txt @@ -1 +1,213 @@ -!! TODO !! + Milkshape Simple OpenGL Exporter + -------------------------------- + +This exporter outputs simple OpenGL as either C-source or BlitzMax compatible +source. + +To use select 'Simple OpenGL' from the 'Export' menu. When activated a dialog +is displayed with the following items: + + +Info + + A text box with some basic info on the model and what will be created. + + +Directory + + The directory that the sources will be generated in. Use the button + with the 3 periods to the left to select the directory. + + +Class/Function name + + The name of the generated function or class. + + +Use Textures + + Outputs the required 2D texture commands. + + +Generate Info + + Defines some macros or constants that define info on the model, + such as its size, largest co-ordinates and centre of gravity. + + +Force COG to 0,0,0 + + The centre of gravity of the model is defined as the mid-point between + the most distance vertices. If you select this then the co-ordinates + are adjusted so that the model is centered on 0,0,0. + + +Generate for BlitzMax + + If selected generates source for use with BlitzMax, otherwise C sources + are generated. See the following sections describing what's generated + for each language type. + + +Generate for lit scenes + + If selected then the appropriate Open GL commands are output setting + the ambient, diffuse, specular and emissive colours. + + If not selected, then the vertexes are given a simple colour taken + from the materials diffuse colour (or white if no material is + defined). + + + +--------------------------------------------------------------------------- +C Usage +--------------------------------------------------------------------------- + +To use the C source in your project, assuming you gave the function name as +Test, simply include Test.c and #include "Test.h" to use the model. The +function either has the prototype: + +void Test(GLfloat x, GLfloat y, GLfloat z, + GLfloat rot_x, GLfloat rot_y, GLfloat rot_z) + +or if 'Use Textures' was selected: + +void Test(GLfloat x, GLfloat y, GLfloat z, + GLfloat rot_x, GLfloat rot_y, GLfloat rot_z, + GLint texture_id); + + +Simply call it with a position and rotation (and texture ID if needed) to draw +the model. Obviously the function can be called as many times as required +during scene generation. + +Also generated is this function: + +int Test2_CreateList(void); + +If this is called then a OpenGL display list for the model is created (the +function returns FALSE if the list couldn't be created). The Test() function +will automatically use this list once it's created. + + +If 'Generate Info' was selected, then the following macros are defined: + + +TEST_COG_X +TEST_COG_Y +TEST_COG_Z + + Defines the COG of the model (always zeros if 'Force COG ...' was + selected). + + +TEST_MIN_X +TEST_MAX_X +TEST_MIN_Y +TEST_MAX_Y +TEST_MIN_Z +TEST_MAX_Z + + The maximum and minimum vertex values for each axis. + + +TEST_SIZE_X +TEST_SIZE_Y +TEST_SIZE_Z + + The size of the model along each axis. + + +TEST_TEXTURED + + Set to one if 'Use Textures' was selected. Otherwise zero. + + +TEST_MATERIALS + + + Set to one if 'Generate for lit scenes' was selected. Otherwise zero. + + + +--------------------------------------------------------------------------- +BlitzMAX Usage +--------------------------------------------------------------------------- + +To use the source in your project, assuming you gave the function name as +Test, simply include "Test.bmx" to use the model. This defines a class called +Test, which has the following fields: + + +Field x:Float +Field y:Float +Field z:Float +Field rot_x:Float +Field rot_y:Float +Field rot_z:Float + + These defines the position and orientation of each instance. + + +Function Create:Test() + + Used to create an instance. + + +Method Render() *OR* +Method Render(texture_id:Int) + + Renders the model (with the supplied texture if 'Use Textures' was + selected). + + +Function CreateDisplayList:Int() + + Creates a common OpenGL display list used by all instances of the + class. Returns True if the list was created, otherwise False. + + Note that Render() will use the display list automatically if it's + been created. + + +If 'Generate Info' was selected, then the following constants are defined: + +Const COG_X:Float +Const COG_Y:Float +Const COG_Z:Float + + Defines the COG of the model (always zeros if 'Force COG ...' was + selected). + + +Const MIN_X:Float +Const MAX_X:Float +Const MIN_Y:Float +Const MAX_Y:Float +Const MIN_Z:Float +Const MAX_Z:Float + + The maximum and minimum vertex values for each axis. + + +Const SIZE_X:Float +Const SIZE_Y:Float +Const SIZE_Z:Float + + The size of the model along each axis. + + +Const TEXTURED:Int + + Set to True if 'Use Textures' was selected. Otherwise False. + + +Const MATERIALS:Int + + + Set to True if 'Generate for lit scenes' was selected. Otherwise False. + + +------------------------------------------------------------------------------- +$Id$ diff --git a/docs/msGrpExplode.txt b/docs/msGrpExplode.txt new file mode 100644 index 0000000..85668f6 --- /dev/null +++ b/docs/msGrpExplode.txt @@ -0,0 +1,35 @@ + Milkshape Group Exploder + ------------------------ + +This tool simply allows you to explode a group so that all the triangles in +it are now in a group of their own. + +To use select 'Group Exploder' from the 'Tools' menu. When activated a dialog +is displayed with the following items: + + +Select Group to explode + + Simply select the group name to explode. + + +Remove original mesh + + If this is selected then the original group is removed. + + +Collate triangles with identical normals + + If this is selected then traingles where the vertex normals all match + (ie. they are on the same plane) are grouped together into a group. + + For instance, if exploding a cube then you end up with 6 new groups, + each containing two triangles that make up one face of the cube. + + +When OK is selected the group is exploded and new groups created. These new +groups will be assigned the same material as the original group. + + +---------------------------------------------------------------------------- +$Id$ diff --git a/opengl/dialog.rc b/opengl/dialog.rc index f0b6995..3a6fcae 100644 --- a/opengl/dialog.rc +++ b/opengl/dialog.rc @@ -13,7 +13,7 @@ GL_DIALOG DIALOG 100, 100, 340, 185 AUTOCHECKBOX "Use Textures", IDC_CHK_TEXTURE, 5,130,60,10 AUTOCHECKBOX "Generate Info", IDC_CHK_DEFINE, 110,130,85,10 AUTOCHECKBOX "Force COG to 0,0,0", IDC_CHK_FORCECOG, 215,130,75,10 - AUTOCHECKBOX "Generate for Blitz MAX", IDC_CHK_BLITZMAX, 5,145,85,10 + AUTOCHECKBOX "Generate for BlitzMax", IDC_CHK_BLITZMAX, 5,145,85,10 AUTOCHECKBOX "Generate for lit scenes", IDC_CHK_VERTNORM, 110,145,85,10 PUSHBUTTON "Cancel", IDC_BUT_CANCEL, 170,165,75,15 diff --git a/opengl/generate.cpp b/opengl/generate.cpp index 960fd7c..94da651 100644 --- a/opengl/generate.cpp +++ b/opengl/generate.cpp @@ -5,7 +5,9 @@ #include #include #include -#include +#include +#include + #include #include "generate.h" #include "msLib.h" @@ -13,9 +15,6 @@ #define INDENT " " #define EOL "\r\n" -#define FLT_MAX 10e35 -#define FLT_MIN -10e35 - ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -308,6 +307,10 @@ void Generate::GenerateC(HWND parent) Output(");\n\n"); } + Output("/* Returns true if a display list " + "could be created for the model */\n"); + Output("int %s_CreateList(void);\n\n",m_funcName.c_str()); + if (m_useInfo) { Output("#define %s_COG_X %f\n",def.c_str(),m_cogx-m_appcogx); @@ -331,6 +334,7 @@ void Generate::GenerateC(HWND parent) } Output("#define %s_TEXTURED %d\n\n",def.c_str(),m_useTexture?1:0); + Output("#define %s_MATERIALS %d\n\n",def.c_str(),m_normals?1:0); Output("%s","#ifdef _cplusplus\n}\n#endif\n\n"); @@ -352,6 +356,40 @@ void Generate::GenerateC(HWND parent) Output("%s","#include \n\n"); + Output("static GLuint list_id=GL_INVALID_VALUE;\n\n"); + + Output("static void Geometry(void)\n"); + Output("{\n"); + m_indent++; + + if (m_normals) + { + Output("GLfloat ambient[4];\n"); + Output("GLfloat diffuse[4];\n"); + Output("GLfloat specular[4];\n"); + Output("GLfloat emission[4];\n"); + Output("\n"); + } + + GenerateCommon(missing,";","/*","*/"); + + m_indent--; + + Output("}\n\n"); + + Output("int %s_CreateList(void)\n",m_funcName.c_str()); + Output("{\n"); + m_indent++; + Output("list_id=glGenLists(1);\n"); + Output("if (list_id==GL_INVALID_VALUE) return 0;\n"); + Output("glNewList(list_id,GL_COMPILE);\n"); + Output("Geometry();\n"); + Output("glEndList();\n"); + Output("return 1;\n"); + m_indent--; + Output("}\n\n"); + + Output("void %s(GLfloat x, GLfloat y, GLfloat z,\n", m_funcName.c_str()); Output("%sGLfloat rot_x, GLfloat rot_y, GLfloat rot_z", @@ -370,16 +408,35 @@ void Generate::GenerateC(HWND parent) m_indent++; - if (m_normals) + Output("glPushMatrix();\n"); + Output("glLoadIdentity();\n"); + Output("glTranslatef(x,y,z);\n"); + Output("glRotatef(rot_x,1,0,0);\n"); + Output("glRotatef(rot_y,0,1,0);\n"); + Output("glRotatef(rot_z,0,0,1);\n"); + + if (m_useTexture) { - Output("GLfloat ambient[4];\n"); - Output("GLfloat diffuse[4];\n"); - Output("GLfloat specular[4];\n"); - Output("GLfloat emission[4];\n"); - Output("\n"); + Output("glBindTexture(GL_TEXTURE_2D,texture_id);\n"); } - GenerateCommon(missing,";","/*","*/"); + Output("\n"); + + Output("if (list_id==GL_INVALID_VALUE)\n"); + Output("{\n"); + m_indent++; + Output("Geometry();\n"); + m_indent--; + Output("}\n"); + Output("else\n"); + Output("{\n"); + m_indent++; + Output("glCallList(list_id);\n"); + m_indent--; + Output("}\n"); + + Output("\n"); + Output("glPopMatrix();\n"); m_indent--; @@ -446,6 +503,7 @@ void Generate::GenerateBlitzMax(HWND parent) Output("Const SIZE_Z:Float=%f\n\n",sz); Output("const TEXTURED:Int=%s\n",m_useTexture ? "true":"false"); + Output("const MATERIALS:Int=%s\n",m_normals ? "true":"false"); Output("\n"); } @@ -460,6 +518,11 @@ void Generate::GenerateBlitzMax(HWND parent) Output("Field rot_z:Float\n"); Output("\n"); + Output("' This field should be considered private\n"); + Output("'\n"); + Output("Global list_id:Int=GL_INVALID_VALUE\n"); + Output("\n"); + Output("' Use this function to create an instance\n"); Output("'\n"); Output("Function Create:%s()\n",m_funcName.c_str()); @@ -476,6 +539,21 @@ void Generate::GenerateBlitzMax(HWND parent) Output("End Function\n"); Output("\n"); + Output("' Use this function to setup a display list.\n"); + Output("' Returns True it the display list is created.\n"); + Output("'\n"); + Output("Function CreateDisplayList:Int()\n"); + m_indent++; + Output("list_id=glGenLists(1)\n"); + Output("if (list_id=GL_INVALID_VALUE) then return False\n"); + Output("glNewList(list_id,GL_COMPILE)\n"); + Output("Geometry()\n"); + Output("glEndList()\n"); + Output("return True\n"); + m_indent--; + Output("End Function\n"); + Output("\n"); + Output("' Use this member to draw the object\n"); Output("'\n"); @@ -490,6 +568,44 @@ void Generate::GenerateBlitzMax(HWND parent) m_indent++; + Output("glPushMatrix()\n"); + Output("glLoadIdentity()\n"); + Output("glTranslatef(x,y,z)\n"); + Output("glRotatef(rot_x,1,0,0)\n"); + Output("glRotatef(rot_y,0,1,0)\n"); + Output("glRotatef(rot_z,0,0,1)\n"); + + if (m_useTexture) + { + Output("glBindTexture(GL_TEXTURE_2D,texture_id)\n"); + } + + Output("\n"); + + Output("If (list_id=GL_INVALID_VALUE)\n"); + m_indent++; + Output("Geometry()\n"); + m_indent--; + Output("Else\n"); + m_indent++; + Output("glCallList(list_id)\n"); + m_indent--; + Output("End If\n"); + Output("\n"); + Output("glPopMatrix()\n"); + + m_indent--; + + Output("End Method\n"); + + Output("\n"); + + Output("' This function should be considered private.\n"); + Output("'\n"); + Output("Function Geometry()\n"); + + m_indent++; + if (m_normals) { Output("Local ambient:Float[4]\n"); @@ -503,7 +619,7 @@ void Generate::GenerateBlitzMax(HWND parent) m_indent--; - Output("End Method\n"); + Output("End Function\n"); m_indent--; @@ -528,19 +644,6 @@ void Generate::GenerateCommon(std::string& missing, { int last_mat=-1; - 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) - { - Output("glBindTexture(GL_TEXTURE_2D,texture_id)%s\n",term); - } - - Output("\n"); Output("glBegin(GL_TRIANGLES)%s\n",term); Output("\n"); @@ -621,7 +724,6 @@ void Generate::GenerateCommon(std::string& missing, } Output("glEnd()%s\n",term); - Output("glPopMatrix()%s\n",term); } -- cgit v1.2.3