Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3089 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Dec 4, 2004, 11:09:25 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/images: modularity improvement, loadTexToGL function, so that not each reader must implement it itself. (far from perfect)

Location:
orxonox/branches/images/importer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/images/importer/material.cc

    r3088 r3089  
    394394  if (map = SDL_LoadBMP(bmpName))
    395395    {
    396 
    397       glGenTextures( 1, texture );
    398       /* Typical Texture Generation Using Data From The Bitmap */
    399       glBindTexture( GL_TEXTURE_2D, *texture );
    400      
    401       /* Generate The Texture */
    402       glTexImage2D( GL_TEXTURE_2D, 0, 3, map->w,
    403                     map->h, 0, GL_BGR,
    404                     GL_UNSIGNED_BYTE, map->pixels );
    405      
    406       /* Linear Filtering */
    407       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );                   
    408       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
     396      loadTexToGL (map->w, map->h, map->pixels, texture);
    409397      if ( map )
    410398        SDL_FreeSurface( map );
     
    455443 
    456444
    457   if(pImage == NULL)                                                                    // If we can't load the file, quit!
     445  if(pImage == NULL)
    458446    exit(0);
    459 
    460   // Generate a texture with the associative texture ID stored in the array
    461   glGenTextures(1, texture);
    462  
    463   // Bind the texture to the texture arrays index and init the texture
    464   glBindTexture(GL_TEXTURE_2D, *texture);
    465  
    466   // Build Mipmaps (builds different versions of the picture for distances - looks better)
    467   gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX, pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
    468  
    469   // Lastly, we need to tell OpenGL the quality of our texture map.  GL_LINEAR_MIPMAP_LINEAR
    470   // is the smoothest.  GL_LINEAR_MIPMAP_NEAREST is faster than GL_LINEAR_MIPMAP_LINEAR,
    471   // but looks blochy and pixilated.  Good for slower computers though.
    472  
    473   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    474   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    475  
    476 
    477   // Now we need to free the image data that we loaded since OpenGL stored it as a texture
    478  
    479   if (pImage)                                                                           // If we loaded the image
    480     {
    481       if (pImage->data)                                                 // If there is texture data
     447 
     448  loadTexToGL (pImage->sizeX, pImage->sizeY, pImage->data, texture);
     449  if (pImage)
     450    {
     451      if (pImage->data)
    482452        {
    483           free(pImage->data);                                           // Free the texture data, we don't need it anymore
     453          free(pImage->data);
    484454        }
    485455     
    486       free(pImage);                                                             // Free the image structure
     456      free(pImage);
    487457    }
    488458  return true;
     
    528498}
    529499
     500bool Material::loadTexToGL (int hight, int width, void* rawImage, GLuint* texture)
     501{
     502  glGenTextures(1, texture);
     503  glBindTexture(GL_TEXTURE_2D, *texture);
     504  /* not Working, and not needed.
     505  glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
     506                height, 0, GL_BGR,
     507                GL_UNSIGNED_BYTE, map->pixels );
     508  */
     509  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, hight, GL_RGB, GL_UNSIGNED_BYTE, rawImage);
     510 
     511  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
     512  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
     513 
     514
     515}
  • orxonox/branches/images/importer/material.h

    r3087 r3089  
    7171    int sizeX;
    7272    int sizeY;
    73     unsigned char *data;
     73    GLubyte *data;
    7474  };
    7575
     
    9191  bool loadJPG (char* jpgName, GLuint* texture);
    9292  void decodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData);
     93
     94  bool loadTexToGL (int hight, int width, void* rawImage, GLuint* texture);
    9395};
    9496#endif
Note: See TracChangeset for help on using the changeset viewer.