Changeset 4157 in orxonox.OLD for orxonox/branches
- Timestamp:
- May 11, 2005, 12:14:54 AM (20 years ago)
- Location:
- orxonox/branches/md2_loader/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/md2_loader/src/lib/graphics/importer/abstract_model.h
r4156 r4157 26 26 #include <vector> 27 27 #include <math.h> 28 #include <SDL_image.h> 28 29 29 30 using namespace std; … … 184 185 { 185 186 186 static createTexture(UINT textureArray[], LPSTR strFileName, int textureID) 187 { 188 AUX_RGBImageRec *pBitmap = NULL; 187 public: 188 189 static void createTexture(unsigned int textureArray[], char* strFileName, int textureID) 190 { 191 SDL_Surface *image = NULL; 192 193 if(!strFileName) 194 return; 195 196 image = IMG_Load(strFileName); 197 if( !image) 198 PRINTF(0)("IMG_Load: %s\n", IMG_GetError()); 189 199 190 if(!strFileName) // Return from the function if no file name was passed in 191 return; 192 193 pBitmap = auxDIBImageLoad(strFileName); // Load the bitmap and store the data 194 195 if(pBitmap == NULL) // If we can't load the file, quit! 196 exit(0); 197 198 // Generate a texture with the associative texture ID stored in the array 199 glGenTextures(1, &textureArray[textureID]); 200 201 // This sets the alignment requirements for the start of each pixel row in memory. 202 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 203 204 // Bind the texture to the texture arrays index and init the texture 205 glBindTexture(GL_TEXTURE_2D, textureArray[textureID]); 206 207 // Build Mipmaps (builds different versions of the picture for distances - looks better) 208 gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); 209 210 // Lastly, we need to tell OpenGL the quality of our texture map. GL_LINEAR_MIPMAP_LINEAR 211 // is the smoothest. GL_LINEAR_MIPMAP_NEAREST is faster than GL_LINEAR_MIPMAP_LINEAR, 212 // but looks blochy and pixilated. Good for slower computers though. 213 214 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 215 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); 216 217 // Now we need to free the bitmap data that we loaded since openGL stored it as a texture 218 219 if (pBitmap) // If we loaded the bitmap 220 { 221 if (pBitmap->data) // If there is texture data 222 { 223 free(pBitmap->data); // Free the texture data, we don't need it anymore 224 } 225 226 free(pBitmap); // Free the bitmap structure 227 } 228 } 200 glGenTextures(1, &textureArray[textureID]); 201 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 202 glBindTexture(GL_TEXTURE_2D, textureArray[textureID]); 203 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 204 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); 205 gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); 206 207 SDL_FreeSurface(image); 208 } 229 209 230 210 }; -
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc
r4150 r4157 146 146 return true; 147 147 } 148 148 149 149 150 /** … … 191 192 } 192 193 194 193 195 /** 194 196 \brief this function fills in the animation list for each animation by name and frame … … 239 241 } 240 242 } 243 241 244 242 245 /** -
orxonox/branches/md2_loader/src/world_entities/test_entity.cc
r4155 r4157 28 28 TestEntity::TestEntity () : WorldEntity() 29 29 { 30 //This is for md2 test purposes only! if this is seen in the trunk: hit me :) 30 this->textureArray = new unsigned int[100]; 31 memset(this->textureArray, 0, 100*sizeof(unsigned int)); 32 31 33 MD2Loader* md2loader = new MD2Loader(); 32 34 this->model = new t3DModel; 33 35 this->md2Model = new MD2Model(); 34 36 35 md2loader->importMD2(model, "../data/models/tris.md2", "test.bmp"); 37 md2loader->importMD2(this->model, "../data/models/tris.md2", "../data/models/tris.pcx"); 38 39 for(int i = 0; i < this->model->numOfMaterials; i++) 40 { 41 if( strlen(this->model->materialList[i].strFile) > 0) 42 { 43 Helper::createTexture(textureArray, this->model->materialList[i].strFile, i); 44 } 45 this->model->materialList[i].texureId = i; 46 } 36 47 } 37 48 -
orxonox/branches/md2_loader/src/world_entities/test_entity.h
r4152 r4157 27 27 t3DModel* model; 28 28 MD2Model* md2Model; 29 30 unsigned int* textureArray; 31 29 32 }; 30 33
Note: See TracChangeset
for help on using the changeset viewer.