aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libjin/Graphics/Drawable.cpp4
-rw-r--r--src/libjin/Graphics/Shader.cpp3
-rw-r--r--src/libjin/Graphics/base.shader.h2
-rw-r--r--src/lua/modules/graphics/graphics.cpp26
4 files changed, 24 insertions, 11 deletions
diff --git a/src/libjin/Graphics/Drawable.cpp b/src/libjin/Graphics/Drawable.cpp
index d4fd1ad..53b4f85 100644
--- a/src/libjin/Graphics/Drawable.cpp
+++ b/src/libjin/Graphics/Drawable.cpp
@@ -12,8 +12,8 @@ namespace graphics
Drawable::Drawable(int w, int h)
: texture(0)
- , size()
- , anchor()
+ , size(w, h)
+ , anchor(0, 0)
{
}
diff --git a/src/libjin/Graphics/Shader.cpp b/src/libjin/Graphics/Shader.cpp
index 45ad3d6..1af861f 100644
--- a/src/libjin/Graphics/Shader.cpp
+++ b/src/libjin/Graphics/Shader.cpp
@@ -45,7 +45,7 @@ namespace graphics
JSLProgram::JSLProgram(const char* program)
: currentTextureUnit(DEFAULT_TEX_UNIT)
{
- char* fs = (char*)alloca(strlen(program) + strlen(base_shader));
+ char* fs = (char*)calloc(1, strlen(program) + base_size);
formatShader(fs, program);
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader, 1, (const GLchar**)&fs, NULL);
@@ -53,6 +53,7 @@ namespace graphics
pid = glCreateProgram();
glAttachShader(pid, shader);
glLinkProgram(pid);
+ free(fs);
}
JSLProgram::~JSLProgram()
diff --git a/src/libjin/Graphics/base.shader.h b/src/libjin/Graphics/base.shader.h
index 109d791..0b8eca9 100644
--- a/src/libjin/Graphics/base.shader.h
+++ b/src/libjin/Graphics/base.shader.h
@@ -23,6 +23,8 @@ void main()
)";
#define formatShader(buf, program)\
sprintf(buf, base_shader, default_tex, program, default_tex)
+
+#define base_size (strlen(base_shader) + strlen(default_tex)*2)
/*
* https://stackoverflow.com/questions/10868958/what-does-sampler2d-store
* The sampler2D is bound to a texture unit. The glUniform call binds it to texture
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index 909e70c..573392d 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -79,17 +79,27 @@ namespace lua
static int l_newBitmap(lua_State* L)
{
- Filesystem* fs = Filesystem::get();
- const char* f = luax_checkstring(L, 1);
- if (!fs->exists(f))
+ Bitmap* bitmap = nullptr;
+ if (luax_gettop(L) == 2)
{
- printf("Error: no such texture %s\n", f);
- exit(1);
+ int w = luax_checkinteger(L, 1);
+ int h = luax_checkinteger(L, 2);
+ bitmap = Bitmap::createBitmap(w, h);
+ }
+ else
+ {
+ const char* f = luax_checkstring(L, 1);
+ Filesystem* fs = Filesystem::get();
+ if (!fs->exists(f))
+ {
+ printf("Error: no such texture %s\n", f);
+ exit(1);
+ }
+ Buffer b;
+ fs->read(f, &b);
+ bitmap = Bitmap::createBitmap(b.data, b.size);
}
- Buffer b;
- fs->read(f, &b);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- Bitmap* bitmap = Bitmap::createBitmap(b.data, b.size);
proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
return 1;
}