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 --- opengl/dialog.rc | 2 +- opengl/generate.cpp | 154 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 129 insertions(+), 27 deletions(-) (limited to 'opengl') 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