Browse Source

- fixed cropped pixels in GenericAtlas
- single tiling texture in <atlas> broken

dmuratshin 10 years ago
parent
commit
a2d1719cba
3 changed files with 18 additions and 19 deletions
  1. 11 14
      oxygine/src/res/ResAtlas.cpp
  2. 5 2
      oxygine/src/utils/AtlasTool.cpp
  3. 2 3
      oxygine/src/utils/ImageUtils.h

+ 11 - 14
oxygine/src/res/ResAtlas.cpp

@@ -37,15 +37,17 @@ namespace oxygine
     };
 
 
-    void apply_atlas(atlas_data& ad)
+    void apply_atlas(atlas_data& ad, bool linear)
     {
         if (!ad.texture)
             return;
 
         MemoryTexture mt;
-        const Rect& bounds = ad.atlas.getBounds();
-        int w = nextPOT(bounds.getWidth());
-        int h = nextPOT(bounds.getHeight());
+        Rect bounds = ad.atlas.getBounds();
+
+        int w = nextPOT(bounds.getRight());
+        int h = nextPOT(bounds.getBottom());
+
         mt.init(ad.mt.lock().getRect(Rect(0, 0, w, h)));
 
         ImageData image_data = mt.lock();
@@ -53,15 +55,10 @@ namespace oxygine
         ad.mt.unlock();
 
         ad.texture->apply();
-
-        /*
-        char str[255];
-        sprintf(str, "%d.png", ad.texture.get());
-        saveImage(image_data, str, "png");
-        */
+        ad.texture->setLinearFilter(linear);
     }
 
-    void next_atlas(int w, int h, TextureFormat tf, atlas_data& ad, const char* name = 0)
+    void next_atlas(int w, int h, TextureFormat tf, atlas_data& ad, const char* name)
     {
         ad.mt.init(w, h, tf);
         ad.mt.fill_zero();
@@ -518,7 +515,7 @@ namespace oxygine
                         bool s = ad.atlas.add(&ad.mt, src, dest);
                         if (s == false)
                         {
-                            apply_atlas(ad);
+                            apply_atlas(ad, _linearFilter);
                             next_atlas(w, h, tf, ad, walker.getCurrentFolder().c_str());
                             s = ad.atlas.add(&ad.mt, src, dest);
                             OX_ASSERT(s);
@@ -579,7 +576,7 @@ namespace oxygine
 
         }
 
-        apply_atlas(ad);
+        apply_atlas(ad, _linearFilter);
 
         for (std::vector<ResAnim*>::iterator i = anims.begin(); i != anims.end(); ++i)
         {
@@ -804,4 +801,4 @@ namespace oxygine
             }
         }
     }
-}
+}

+ 5 - 2
oxygine/src/utils/AtlasTool.cpp

@@ -180,7 +180,10 @@ namespace oxygine
                 srcRect.pos = rect.pos + offset;
                 srcRect.size = Point(src.w, src.h);
 
-                _bounds.unite(srcRect);
+                if (_bounds.isEmpty())
+                    _bounds = srcRect;
+                else
+                    _bounds.unite(srcRect);
 
                 if (dest)
                     dest->updateRegion(srcRect.pos.x, srcRect.pos.y, src);
@@ -334,4 +337,4 @@ namespace oxygine
         return true;
         ///Rect a = re
     }
-}
+}

+ 2 - 3
oxygine/src/utils/ImageUtils.h

@@ -5,10 +5,9 @@ namespace oxygine
 {
     class ImageData;
     /**
-    ImageData should be TF_R8G8B8A8
-    supported formats = "jpg", "png", "tga"
+    supported formats = "tga"
     */
-    void saveImage(const ImageData& im, const char* path, const char* format);
+    void saveImage(const ImageData& im, const char* path, const char* format = "tga");
 
     /**
     supported formats = "jpg"