ソースを参照

Implemented the basis of Texture, the main functions like loading, destroying and the getters. It needs loadPNG to be done

Eiyeron Fulmincendii 10 年 前
コミット
e9dccc11cc
共有3 個のファイルを変更した30 個の追加11 個の削除を含む
  1. 8 1
      platform/include/Texture.h
  2. 18 10
      platform/nspire/Texure.cpp
  3. 4 0
      platform/nspire/public/platform.h

+ 8 - 1
platform/include/Texture.h

@@ -7,6 +7,8 @@
  */
 
 #include "utility/Rect.h"
+#include "platform.h"
+#include "render/Pixel.h"
 //#include "PLATFORM/texture_type.h"
 
 namespace WalrusRPG
@@ -17,13 +19,18 @@ namespace WalrusRPG
         class Texture
         {
           private:
-            // texture_type_t texture;
+            texture_data_t texture;
+            unsigned width;
+            unsigned height;
+
           public:
             // The get function is implemented by the child
             // TextureHolder &get_texture();
             Texture(char *data);
             ~Texture();
+            // Getters
             WalrusRPG::Utils::Rect get_dimensions();
+            const WalrusRPG::Graphics::Pixel get_pixel(unsigned x, unsigned y);
         };
     }
 }

+ 18 - 10
platform/nspire/Texure.cpp

@@ -1,31 +1,39 @@
 #include "Texture.h"
 #include "utility/Rect.h"
+#include "render/Pixel.h"
 #include <cstdint>
 
+using WalrusRPG::Graphics::Black;
+using WalrusRPG::Graphics::Pixel;
 using WalrusRPG::Graphics::Texture;
 using WalrusRPG::Utils::Rect;
 
-namespace {
-    /*texture_type_t*/ char* loadPNG(char *data) {
+namespace
+{
+    texture_data_t loadPNG(char *data)
+    {
         // stuff
         return nullptr;
     }
 }
 
-Texture::Texture(char *data)
+Texture::Texture(char *data) : texture(loadPNG(data))
 {
-    // TODO
-    // load data from texture
-    // texture = loadPNG(data);
+    width = texture[0];
+    height = texture[1];
 }
 
 Texture::~Texture()
 {
-    // destroy(texture);
+    delete (texture);
+}
+
+Rect Texture::get_dimensions()
+{
+    return Rect(0, 0, width, height);
 }
 
-WalrusRPG::Utils::Rect Texture::get_dimensions()
+const Pixel Texture::get_pixel(unsigned x, unsigned y)
 {
-    // return Rect(0, 0, texture[0], texture[1]);
-    return Rect(0, 0, 0, 0);
+    return Pixel(texture[2 + width*y + x]);
 }

+ 4 - 0
platform/nspire/public/platform.h

@@ -1,6 +1,10 @@
 #ifndef INCLUDE_PLATFORM_H
 #define INCLUDE_PLATFORM_H
 
+#include <cstdint>
+
 #define TIMER_FREQ 32768
 
+typedef uint16_t *texture_data_t;
+
 #endif