- Timestamp:
- 05/30/06 12:53:21 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GeoTool
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h
r993 r994 195 195 // load a image file as a texture 196 196 void LoadTexture(const char *); 197 void LoadTextureSubMesh(int isubmesh, const char *); 198 199 int getSubMeshCount(void) const { return mSubMeshCount; } 200 void resetTextures(void); 197 201 198 202 private: … … 237 241 // Current texture handle (OpenGL handle: 0=no texture) 238 242 GLuint current_texture; 243 GLuint *current_texture_submesh; 239 244 bool use_texture_mapping; // this flag enables texture mapping when a texture is loaded 240 245 -
GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h
r993 r994 52 52 #include "../resource.h" 53 53 54 //#include <IL/IL.h>55 56 54 // State of the button process. 57 55 enum ProcessState … … 117 115 118 116 MeshSimplificationSequence *oMeshSimpSequence; 119 LodStripsConstructor 120 GeoMeshLoader 117 LodStripsConstructor *oLodStrip; 118 GeoMeshLoader *geoMeshLoader; 121 119 122 120 inline void cb_menuFileOpen_i(fltk::Item*, void*); … … 128 126 inline void cb_menuFileLoadTexture_i(fltk::Item*, void*); 129 127 static void cb_menuFileLoadTexture(fltk::Item*, void*); 128 inline void cb_menuFileLoadTextureSubMesh_i(fltk::Item*, void*); 129 static void cb_menuFileLoadTextureSubMesh(fltk::Item*, void*); 130 130 131 131 inline void cb_menuMeshInfo_i(fltk::Item*, void*); … … 296 296 fltk::Item *menuMeshExportOBJ; 297 297 fltk::Item *menuFileTransformSharedVertex; 298 fltk::Item *menuFileLoadTexture; 298 fltk::ItemGroup *menuLoadTextures; 299 fltk::Item *menuFileLoadTexture; 299 300 300 301 fltk::Item *menuFileQuit; … … 380 381 float updateProgressBar(float); 381 382 383 void BuildLoadTextureSubMeshMenu(void); 384 int numSubMeshNames; 385 char **SubMeshNames; 386 382 387 }; 383 388 -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
r993 r994 436 436 437 437 current_texture = 0; 438 current_texture_submesh=NULL; 438 439 use_texture_mapping = true; 439 440 } … … 461 462 462 463 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 464 465 if (current_texture_submesh) 466 delete[] current_texture_submesh; 467 current_texture_submesh=new GLuint[getSubMeshCount()]; 468 for (int i=0; i<getSubMeshCount(); i++) 469 current_texture_submesh[i]=0; 463 470 } 464 471 … … 663 670 geosubmesh = &geoMesh->mSubMesh[submesh]; 664 671 672 // bind current texture to use 673 GLuint usetex = 0; 674 if (use_texture_mapping) 675 { 676 if (current_texture_submesh[submesh]) 677 usetex=current_texture_submesh[submesh]; 678 else if (current_texture) 679 usetex=current_texture; 680 } 681 glBindTexture(GL_TEXTURE_2D,usetex); 682 683 665 684 // For each one of the strips. 666 685 for (int strip = 0; strip < geosubmesh->mStripCount; strip++) … … 726 745 727 746 // set the texture coordinates if needed 728 if ( current_texture && use_texture_mapping)747 if (usetex) 729 748 { 730 749 vector2 = geosubmesh->mVertexBuffer->mTexCoords[position]; 731 x = vector 3[0];732 y = vector 3[1];750 x = vector2[0]; 751 y = vector2[1]; 733 752 glTexCoord2f(x,y); 734 753 } … … 812 831 } 813 832 } 833 834 // bind current texture to use 835 GLuint usetex = 0; 836 if (use_texture_mapping) 837 { 838 if (current_texture_submesh[submesh]) 839 usetex=current_texture_submesh[submesh]; 840 else if (current_texture) 841 usetex=current_texture; 842 } 843 glBindTexture(GL_TEXTURE_2D,usetex); 814 844 815 845 // Enable arrays. 816 846 glEnableClientState(GL_VERTEX_ARRAY); 817 847 glEnableClientState(GL_NORMAL_ARRAY); 818 if ( current_texture && use_texture_mapping)848 if (usetex) 819 849 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 820 850 else … … 826 856 glVertexPointer(3, GL_FLOAT, 0, mSharedPosArray); 827 857 glNormalPointer(GL_FLOAT, 0, mSharedNorArray); 828 if ( current_texture && use_texture_mapping)858 if (usetex) 829 859 glTexCoordPointer(2, GL_FLOAT, 0, mSharedTexCoordArray); 830 860 } … … 833 863 glVertexPointer(3, GL_FLOAT, 0, mPosArray[submesh]); 834 864 glNormalPointer(GL_FLOAT, 0, mNorArray[submesh]); 835 if ( current_texture && use_texture_mapping)865 if (usetex) 836 866 glTexCoordPointer(2, GL_FLOAT, 0, mTexCoordArray[submesh]); 837 867 } … … 848 878 //--------------------------------------------------------------------------- 849 879 void GeoMeshView::drawLodStrip() 880 { 881 SubMesh *geosubmesh; 882 Index position; 883 Vector3 vector3; 884 Vector2 vector2; 885 float x,y,z; 886 float r,g,b; 887 int color_index; 888 int current_strip; 889 890 // Initialize current strip. 891 current_strip = 0; 892 893 // For each submesh. 894 for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 895 { 896 // bind current texture to use 897 GLuint usetex = 0; 898 if (use_texture_mapping) 899 { 900 if (current_texture_submesh[submesh]) 901 usetex=current_texture_submesh[submesh]; 902 else if (current_texture) 903 usetex=current_texture; 904 } 905 glBindTexture(GL_TEXTURE_2D,usetex); 906 907 color_index = 0; 908 909 // Gets the actual submesh. 910 geosubmesh = &geoMesh->mSubMesh[submesh]; 911 912 // For each one of the strips. 913 for (int strip = 0; strip < geosubmesh->mStripCount; strip++) 914 { 915 // Paint the current strip. 916 glBegin(GL_TRIANGLE_STRIP); 917 918 if (getColorStrips()) 919 { 920 // Gets the color of the strip. 921 r = mStripColors[submesh][color_index].r; 922 g = mStripColors[submesh][color_index].g; 923 b = mStripColors[submesh][color_index].b; 924 925 // Change to the next color. 926 color_index++; 927 928 // Paint a new color. 929 glColor3f(r,g,b); 930 } 931 932 // For each index of the strip. 933 for (int index = 0; index < lodStripsLib->mStrips[current_strip].size(); index++) 934 { 935 position = lodStripsLib->mStrips[current_strip][index]; 936 937 // Gets the vertex normal. 938 vector3 = geosubmesh->mVertexBuffer->mNormal[position]; 939 940 x = vector3[0]; 941 y = vector3[1]; 942 z = vector3[2]; 943 944 // Sets the vertex normal. 945 glNormal3f(x,y,z); 946 947 // set the texture coordinates if needed 948 if (usetex) 949 { 950 vector2 = geosubmesh->mVertexBuffer->mTexCoords[position]; 951 x = vector2[0]; 952 y = vector2[1]; 953 glTexCoord2f(x,y); 954 } 955 956 // Gets the vertex coordinates. 957 vector3 = geosubmesh->mVertexBuffer->mPosition[position]; 958 959 x = vector3[0]; 960 y = vector3[1]; 961 z = vector3[2]; 962 963 // Sets the vertex position. 964 glVertex3f(x,y,z); 965 } 966 967 // Increments current strip. 968 current_strip++; 969 970 // A strip is generated. 971 glEnd(); 972 973 } 974 } 975 976 }//End drawTriangleStrip. 977 978 979 //--------------------------------------------------------------------------- 980 // Paint lodtree object. 981 //--------------------------------------------------------------------------- 982 void GeoMeshView::drawLodTree() 850 983 { 851 984 SubMesh *geosubmesh; … … 860 993 current_strip = 0; 861 994 862 // For each submesh.863 for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)864 {865 866 color_index = 0;867 868 // Gets the actual submesh.869 geosubmesh = &geoMesh->mSubMesh[submesh];870 871 // For each one of the strips.872 for (int strip = 0; strip < geosubmesh->mStripCount; strip++)873 {874 // Paint the current strip.875 glBegin(GL_TRIANGLE_STRIP);876 877 if (getColorStrips())878 {879 // Gets the color of the strip.880 r = mStripColors[submesh][color_index].r;881 g = mStripColors[submesh][color_index].g;882 b = mStripColors[submesh][color_index].b;883 884 // Change to the next color.885 color_index++;886 887 // Paint a new color.888 glColor3f(r,g,b);889 }890 891 // For each index of the strip.892 for (int index = 0; index < lodStripsLib->mStrips[current_strip].size(); index++)893 {894 position = lodStripsLib->mStrips[current_strip][index];895 896 // Gets the vertex normal.897 vector3 = geosubmesh->mVertexBuffer->mNormal[position];898 899 x = vector3[0];900 y = vector3[1];901 z = vector3[2];902 903 // Sets the vertex normal.904 glNormal3f(x,y,z);905 906 // Gets the vertex coordinates.907 vector3 = geosubmesh->mVertexBuffer->mPosition[position];908 909 x = vector3[0];910 y = vector3[1];911 z = vector3[2];912 913 // Sets the vertex position.914 glVertex3f(x,y,z);915 }916 917 // Increments current strip.918 current_strip++;919 920 // A strip is generated.921 glEnd();922 923 }924 }925 926 }//End drawTriangleStrip.927 928 929 //---------------------------------------------------------------------------930 // Paint lodtree object.931 //---------------------------------------------------------------------------932 void GeoMeshView::drawLodTree()933 {934 SubMesh *geosubmesh;935 Index position;936 Vector3 vector3;937 float x,y,z;938 float r,g,b;939 int color_index;940 int current_strip;941 942 // Initialize current strip.943 current_strip = 0;944 945 995 946 996 // DRAW THE TRUNK AS A LODSTRIP OBJECT … … 1098 1148 1099 1149 GLfloat light_ambient[] = {0.3,0.3,0.3,1.0}; 1100 GLfloat luzpos[] 1101 GLfloat luzcolor[] 1150 GLfloat luzpos[] = {0.0,0.0,1.0,0.0}; 1151 GLfloat luzcolor[] = {1.0,1.0,1.0,1.0}; 1102 1152 1103 1153 // glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_ambient); … … 1199 1249 ilShutDown(); 1200 1250 } 1251 1252 1253 void GeoMeshView::LoadTextureSubMesh(int isubmesh, const char *imgfile) 1254 { 1255 ilInit(); 1256 ilutEnable(ILUT_OPENGL_CONV); 1257 ilutRenderer(ILUT_OPENGL); 1258 1259 current_texture_submesh[isubmesh] = ilutGLLoadImage((const ILstring)imgfile); 1260 if (!current_texture_submesh[isubmesh]) 1261 fltk::alert("Error loading texture!"); 1262 1263 ilShutDown(); 1264 } 1265 1266 void GeoMeshView::resetTextures(void) 1267 { 1268 if (current_texture) 1269 { 1270 glDeleteTextures(1,¤t_texture); 1271 current_texture=0; 1272 } 1273 if (current_texture_submesh) 1274 { 1275 glDeleteTextures(getSubMeshCount(),current_texture_submesh); 1276 for (int i=0; i<getSubMeshCount(); i++) 1277 current_texture_submesh[i]=0; 1278 } 1279 } -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r993 r994 25 25 geoMeshView->deactiveLodTree(); 26 26 27 geoMeshView->resetTextures(); 28 BuildLoadTextureSubMeshMenu(); 29 27 30 // Repaint the window. 28 31 mMainWindow->redraw(); … … 33 36 fltk::FileChooser *fcho = new fltk::FileChooser("","*.jpg",fltk::FileChooser::CREATE,"Open image file"); 34 37 fcho->exec(); 38 char filename[256]=""; 35 39 if (fcho->value()) 36 geoMeshView->LoadTexture(fcho->value()); 40 { 41 strcpy(filename,fcho->value()); 42 geoMeshView->LoadTexture(filename); 43 } 37 44 } 38 45 39 46 void GeoMeshViewUI::cb_menuFileLoadTexture(fltk::Item *o, void *v) 40 47 { 41 ((GeoMeshViewUI*) (o->parent()->parent()->parent()-> user_data()))48 ((GeoMeshViewUI*) (o->parent()->parent()->parent()->parent()->user_data())) 42 49 -> 43 50 cb_menuFileLoadTexture_i(o,v); 44 51 } 52 53 inline void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh_i(fltk::Item *item, void *) 54 { 55 const char * label = item->label(); 56 int isubmesh = label[strlen(label)-1]-48; 57 58 fltk::FileChooser *fcho = new fltk::FileChooser("","*.jpg",fltk::FileChooser::CREATE,"Open image file"); 59 fcho->exec(); 60 char filename[256]=""; 61 if (fcho->value()) 62 { 63 strcpy(filename,fcho->value()); 64 geoMeshView->LoadTextureSubMesh(isubmesh,filename); 65 } 66 } 67 68 void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh(fltk::Item *o, void *v) 69 { 70 ((GeoMeshViewUI*) (o->parent()->parent()->parent()->parent()->user_data())) 71 -> 72 cb_menuFileLoadTextureSubMesh_i(o,v); 73 } 74 45 75 46 76 … … 2540 2570 // Initialize the menus application state. 2541 2571 mApplicationState = NONE; 2572 2573 SubMeshNames=NULL; 2542 2574 2543 2575 { … … 2791 2823 2792 2824 { 2793 fltk::Item* o = menuFileLoadTexture = new fltk::Item("Load texture");2794 o-> callback((fltk::Callback*)cb_menuFileLoadTexture);2825 menuLoadTextures = new fltk::ItemGroup("Load Textures"); 2826 o->add(menuLoadTextures); 2795 2827 } 2796 2828 … … 3097 3129 } 3098 3130 3131 3132 void GeoMeshViewUI::BuildLoadTextureSubMeshMenu(void) 3133 { 3134 if (SubMeshNames) 3135 { 3136 menuLoadTextures->clear(); 3137 for (int i=0; i<numSubMeshNames; i++) 3138 { 3139 delete[] SubMeshNames[i]; 3140 } 3141 delete[] SubMeshNames; 3142 } 3143 3144 menuFileLoadTexture = new fltk::Item("Entire model"); 3145 menuFileLoadTexture->callback((fltk::Callback*)cb_menuFileLoadTexture); 3146 menuLoadTextures->add(menuFileLoadTexture); 3147 3148 numSubMeshNames=geoMeshView->getSubMeshCount(); 3149 SubMeshNames=new char*[numSubMeshNames]; 3150 3151 for (int i=0; i<numSubMeshNames; i++) 3152 { 3153 SubMeshNames[i]=new char[10]; 3154 3155 sprintf(SubMeshNames[i],"submesh %d",i); 3156 fltk::Item *item = new fltk::Item(SubMeshNames[i]); 3157 item->callback((fltk::Callback*)cb_menuFileLoadTextureSubMesh); 3158 menuLoadTextures->add(item); 3159 } 3160 }
Note: See TracChangeset
for help on using the changeset viewer.