aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-02 10:47:18 +0800
committerchai <chaifix@163.com>2018-09-02 10:47:18 +0800
commit6d67345bd5ddea7a4ce37e6bbeda15d341b1ee82 (patch)
tree2d41b1ba3bd68ced24e11cb801a61d5417357229 /src
parentbbecfee3b69fd2d2015305f3d04c02f87d4924b0 (diff)
*update
Diffstat (limited to 'src')
-rw-r--r--src/libjin/Graphics/Drawable.cpp2
-rw-r--r--src/libjin/Graphics/Texture.cpp7
-rw-r--r--src/libjin/Graphics/Window.cpp6
-rw-r--r--src/libjin/Graphics/Window.h16
4 files changed, 15 insertions, 16 deletions
diff --git a/src/libjin/Graphics/Drawable.cpp b/src/libjin/Graphics/Drawable.cpp
index 799498e..d4fd1ad 100644
--- a/src/libjin/Graphics/Drawable.cpp
+++ b/src/libjin/Graphics/Drawable.cpp
@@ -9,6 +9,7 @@ namespace jin
{
namespace graphics
{
+
Drawable::Drawable(int w, int h)
: texture(0)
, size()
@@ -59,6 +60,7 @@ namespace graphics
glDisable(GL_TEXTURE_2D);
}
+
} // render
} // jin
diff --git a/src/libjin/Graphics/Texture.cpp b/src/libjin/Graphics/Texture.cpp
index f3c08fb..633eeac 100644
--- a/src/libjin/Graphics/Texture.cpp
+++ b/src/libjin/Graphics/Texture.cpp
@@ -71,17 +71,16 @@ namespace graphics
// ʹstbi_load_from_memory
int w;
int h;
- unsigned char* textureData = stbi_load_from_memory((unsigned char *)b, s, &w, &h, NULL, STBI_rgb_alpha);
- if (textureData == 0) return false;
+ pixels = (color*)stbi_load_from_memory((unsigned char *)b, s, &w, &h, NULL, STBI_rgb_alpha);
+ if (pixels == 0) return false;
size.x = w;
size.y = h;
- pixels = (color*)textureData;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
vertCoord[0] = 0; vertCoord[1] = 1;
vertCoord[2] = 0; vertCoord[3] = h;
diff --git a/src/libjin/Graphics/Window.cpp b/src/libjin/Graphics/Window.cpp
index f4ca9aa..4e168dc 100644
--- a/src/libjin/Graphics/Window.cpp
+++ b/src/libjin/Graphics/Window.cpp
@@ -24,8 +24,8 @@ namespace graphics
return false;
const Setting* setting = (Setting*)s;
- width = setting->width;
- height = setting->height;
+ size.x = setting->width;
+ size.y = setting->height;
fps = setting->fps;
bool vsync = setting->vsync;
const char* title = setting->title;
@@ -59,7 +59,7 @@ namespace graphics
if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
- wnd = SDL_CreateWindow(title, wx, wy, width, height, flag);
+ wnd = SDL_CreateWindow(title, wx, wy, size.x, size.y, flag);
if (wnd == NULL)
return false;
ctx = SDL_GL_CreateContext(wnd);
diff --git a/src/libjin/Graphics/Window.h b/src/libjin/Graphics/Window.h
index e4939f6..4617ef8 100644
--- a/src/libjin/Graphics/Window.h
+++ b/src/libjin/Graphics/Window.h
@@ -5,6 +5,7 @@
#include "SDL2/SDL.h"
#include "../utils/utils.h"
+#include "../math/Vector.h"
#include "../common/Subsystem.hpp"
namespace jin
@@ -15,7 +16,6 @@ namespace graphics
class Window : public Subsystem<Window>
{
public:
-
struct Setting : SettingBase
{
public:
@@ -27,25 +27,23 @@ namespace graphics
bool resizable; // resize
};
- inline int getW(){ return width; }
- inline int getH(){ return height; }
+ inline int getW(){ return size.x; }
+ inline int getH(){ return size.y; }
inline int getFPS(){ return fps; }
inline void swapBuffers();
private:
-
+ SINGLETON(Window);
Window() {};
virtual ~Window() {};
- SINGLETON(Window);
+ bool initSystem(const SettingBase* setting) override;
+ void quitSystem() override;
SDL_Window* wnd;
-
- int width, height;
+ jin::math::Vector2 size;
int fps;
- /*call only once*/ bool initSystem(const SettingBase* setting) override;
- /*call only once*/ void quitSystem() override;
};
} // render