Changeset 993 for GTP/trunk/Lib/Geom/shared/GeoTool/src
- Timestamp:
- 05/30/06 10:47:05 (19 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GeoTool/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
r985 r993 399 399 : fltk::GlWindow(x,y,w,h,l) 400 400 { 401 mStripColors 401 mStripColors = NULL; 402 402 mSharedPosArray = NULL; 403 403 mSharedNorArray = NULL; 404 mPosArray = NULL; 405 mNorArray = NULL; 406 mIndexArray = NULL; 407 vAng = 0.0; 404 mSharedTexCoordArray= NULL; 405 mPosArray = NULL; 406 mNorArray = NULL; 407 mTexCoordArray = NULL; 408 mIndexArray = NULL; 409 vAng = 0.0; 408 410 hAng = 0.0; 409 411 size = 0.0; … … 432 434 // Cross Reference. 433 435 mGeoMeshViewUI = geoMeshViewUI; 436 437 current_texture = 0; 438 use_texture_mapping = true; 434 439 } 435 440 … … 474 479 delete [] mNorArray[submesh]; 475 480 delete [] mIndexArray[submesh]; 481 delete [] mTexCoordArray[submesh]; 476 482 } 477 483 478 484 delete [] mSharedPosArray; 479 485 delete [] mSharedNorArray; 486 delete [] mSharedTexCoordArray; 480 487 delete [] mPosArray; 481 488 delete [] mNorArray; … … 491 498 mSharedPosArray = new GLfloat[vertex_buffer->mVertexCount * 3]; 492 499 mSharedNorArray = new GLfloat[vertex_buffer->mVertexCount * 3]; 500 mSharedTexCoordArray = new GLfloat[vertex_buffer->mVertexCount * 2]; 493 501 494 502 for (int vertex = 0; vertex < vertex_buffer->mVertexCount; vertex++) 495 503 { 496 mSharedPosArray[3 * vertex] 504 mSharedPosArray[3 * vertex] = vertex_buffer->mPosition[vertex].x; 497 505 mSharedPosArray[(3 * vertex) + 1] = vertex_buffer->mPosition[vertex].y; 498 506 mSharedPosArray[(3 * vertex) + 2] = vertex_buffer->mPosition[vertex].z; 499 507 500 mSharedNorArray[3 * vertex] 508 mSharedNorArray[3 * vertex] = vertex_buffer->mNormal[vertex].x; 501 509 mSharedNorArray[(3 * vertex) + 1] = vertex_buffer->mNormal[vertex].y; 502 510 mSharedNorArray[(3 * vertex) + 2] = vertex_buffer->mNormal[vertex].z; 511 512 mSharedTexCoordArray[2 * vertex] = vertex_buffer->mTexCoords[vertex].x; 513 mSharedTexCoordArray[(2 * vertex) + 1] = vertex_buffer->mTexCoords[vertex].y; 503 514 } 504 515 } … … 507 518 mPosArray = new GLfloat*[geomesh->mSubMeshCount]; 508 519 mNorArray = new GLfloat*[geomesh->mSubMeshCount]; 509 mIndexArray = new GLuint*[geomesh->mSubMeshCount]; 520 mTexCoordArray = new GLfloat*[geomesh->mSubMeshCount]; 521 mIndexArray = new GLuint*[geomesh->mSubMeshCount]; 510 522 511 523 // For each submesh. … … 532 544 mPosArray[submesh] = new GLfloat[vertex_buffer->mVertexCount * 3]; 533 545 mNorArray[submesh] = new GLfloat[vertex_buffer->mVertexCount * 3]; 546 mTexCoordArray[submesh] = new GLfloat[vertex_buffer->mVertexCount * 2]; 534 547 535 548 // For each one of the vertex. 536 549 for (int vertex = 0; vertex < vertex_buffer->mVertexCount; vertex++) 537 550 { 538 mPosArray[submesh][3 * vertex] 551 mPosArray[submesh][3 * vertex] = vertex_buffer->mPosition[vertex].x; 539 552 mPosArray[submesh][(3 * vertex) + 1] = vertex_buffer->mPosition[vertex].y; 540 553 mPosArray[submesh][(3 * vertex) + 2] = vertex_buffer->mPosition[vertex].z; 541 554 542 mNorArray[submesh][3 * vertex] 555 mNorArray[submesh][3 * vertex] = vertex_buffer->mNormal[vertex].x; 543 556 mNorArray[submesh][(3 * vertex) + 1] = vertex_buffer->mNormal[vertex].y; 544 557 mNorArray[submesh][(3 * vertex) + 2] = vertex_buffer->mNormal[vertex].z; 558 559 mTexCoordArray[submesh][2 * vertex] = vertex_buffer->mTexCoords[vertex].x; 560 mTexCoordArray[submesh][(2 * vertex) + 1] = vertex_buffer->mTexCoords[vertex].y; 545 561 }// End for each vertex. 546 562 } … … 550 566 mPosArray[submesh] = NULL; 551 567 mNorArray[submesh] = NULL; 568 mTexCoordArray[submesh] = NULL; 552 569 } 553 570 … … 633 650 Index position; 634 651 Vector3 vector3; 652 Vector2 vector2; 635 653 float x,y,z; 636 654 float r,g,b; … … 706 724 // Sets the vertex normal. 707 725 glNormal3f(x,y,z); 726 727 // set the texture coordinates if needed 728 if (current_texture && use_texture_mapping) 729 { 730 vector2 = geosubmesh->mVertexBuffer->mTexCoords[position]; 731 x = vector3[0]; 732 y = vector3[1]; 733 glTexCoord2f(x,y); 734 } 708 735 709 736 // Gets the vertex coordinates. … … 789 816 glEnableClientState(GL_VERTEX_ARRAY); 790 817 glEnableClientState(GL_NORMAL_ARRAY); 818 if (current_texture && use_texture_mapping) 819 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 820 else 821 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 791 822 792 823 // If the submesh is shared vertex. … … 795 826 glVertexPointer(3, GL_FLOAT, 0, mSharedPosArray); 796 827 glNormalPointer(GL_FLOAT, 0, mSharedNorArray); 828 if (current_texture && use_texture_mapping) 829 glTexCoordPointer(2, GL_FLOAT, 0, mSharedTexCoordArray); 797 830 } 798 831 else … … 800 833 glVertexPointer(3, GL_FLOAT, 0, mPosArray[submesh]); 801 834 glNormalPointer(GL_FLOAT, 0, mNorArray[submesh]); 835 if (current_texture && use_texture_mapping) 836 glTexCoordPointer(2, GL_FLOAT, 0, mTexCoordArray[submesh]); 802 837 } 803 838 … … 1044 1079 glMatrixMode(GL_PROJECTION); 1045 1080 glLoadIdentity(); 1081 1082 if (current_texture && use_texture_mapping) 1083 glEnable(GL_TEXTURE_2D); 1084 else 1085 glDisable(GL_TEXTURE_2D); 1046 1086 1047 1087 glEnable(GL_LIGHTING); … … 1144 1184 } 1145 1185 1186 1187 #include <IL/ILUT.h> 1188 1189 void GeoMeshView::LoadTexture(const char *imgfile) 1190 { 1191 ilInit(); 1192 ilutEnable(ILUT_OPENGL_CONV); 1193 ilutRenderer(ILUT_OPENGL); 1194 1195 current_texture = ilutGLLoadImage((const ILstring)imgfile); 1196 if (!current_texture) 1197 fltk::alert("Error loading texture!"); 1198 1199 ilShutDown(); 1200 } -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r990 r993 28 28 mMainWindow->redraw(); 29 29 } 30 31 inline void GeoMeshViewUI::cb_menuFileLoadTexture_i(fltk::Item*, void*) 32 { 33 fltk::FileChooser *fcho = new fltk::FileChooser("","*.jpg",fltk::FileChooser::CREATE,"Open image file"); 34 fcho->exec(); 35 if (fcho->value()) 36 geoMeshView->LoadTexture(fcho->value()); 37 } 38 39 void GeoMeshViewUI::cb_menuFileLoadTexture(fltk::Item *o, void *v) 40 { 41 ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) 42 -> 43 cb_menuFileLoadTexture_i(o,v); 44 } 45 30 46 31 47 //--------------------------------------------------------------------------- … … 539 555 // Repaint the main window. 540 556 mMainWindow->redraw(); 557 if (geoMeshView->isTextureMappingEnabled()) 558 geoMeshView->disableTextureMapping(); 559 else 560 geoMeshView->enableTextureMapping(); 541 561 } 542 562 … … 2771 2791 2772 2792 { 2793 fltk::Item* o = menuFileLoadTexture = new fltk::Item("Load texture"); 2794 o->callback((fltk::Callback*)cb_menuFileLoadTexture); 2795 } 2796 2797 { 2773 2798 fltk::Item* o = menuFileQuit = new fltk::Item("Quit"); 2774 2799 o->callback((fltk::Callback*)cb_menuFileQuit); … … 2880 2905 } 2881 2906 2882 //new fltk::Divider(); 2883 2884 //{ 2885 // fltk::Item* o = menuRenderTextures = new fltk::Item("Textures"); 2886 // o->callback((fltk::Callback*)cb_menuRenderTextures); 2887 //} 2907 new fltk::Divider(); 2908 2909 { 2910 fltk::Item* o = menuRenderTextures = new fltk::Item("Texture mapping"); 2911 o->type(fltk::Item::RADIO); 2912 o->set_value(); 2913 o->callback((fltk::Callback*)cb_menuRenderTextures); 2914 } 2888 2915 2889 2916 o->end();
Note: See TracChangeset
for help on using the changeset viewer.