aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-10 19:47:21 +0800
committerchai <chaifix@163.com>2018-09-10 19:47:21 +0800
commitd5cda5fddc078fa5fdb93805785fc707f050d8e7 (patch)
tree46224cbddb79959cbc26f045c757a9dde7ebb23b /src
parent435e17c1a81fa74a45465829bd42d36e7fa24406 (diff)
*update
Diffstat (limited to 'src')
-rw-r--r--src/libjin/Graphics/Bitmap.cpp2
-rw-r--r--src/libjin/Graphics/Bitmap.h2
-rw-r--r--src/libjin/Graphics/Drawable.cpp4
-rw-r--r--src/libjin/Graphics/Font.cpp4
-rw-r--r--src/libjin/Graphics/Shader.cpp21
-rw-r--r--src/libjin/Graphics/Shader.h1
-rw-r--r--src/libjin/Graphics/Shapes.cpp29
-rw-r--r--src/libjin/Graphics/Window.cpp4
-rw-r--r--src/lua/embed/boot.lua.h5
-rw-r--r--src/lua/embed/keyboard.lua.h2
-rw-r--r--src/lua/modules/event/event.cpp2
-rw-r--r--src/lua/modules/graphics/graphics.cpp4
12 files changed, 42 insertions, 38 deletions
diff --git a/src/libjin/Graphics/Bitmap.cpp b/src/libjin/Graphics/Bitmap.cpp
index 28b59af..acfde58 100644
--- a/src/libjin/Graphics/Bitmap.cpp
+++ b/src/libjin/Graphics/Bitmap.cpp
@@ -60,7 +60,7 @@ namespace graphics
stbi_image_free(pixels);
}
- void Bitmap::bindPixels(Color* p, int w, int h)
+ void Bitmap::bind(Color* p, int w, int h)
{
if (pixels != nullptr)
delete[] pixels;
diff --git a/src/libjin/Graphics/Bitmap.h b/src/libjin/Graphics/Bitmap.h
index 53b374b..ab84388 100644
--- a/src/libjin/Graphics/Bitmap.h
+++ b/src/libjin/Graphics/Bitmap.h
@@ -20,7 +20,7 @@ namespace graphics
~Bitmap();
/* init pixels */
- void bindPixels(Color* pixels, int w, int h);
+ void bind(Color* pixels, int w, int h);
void resetPixels(const Color* pixels, int w, int h);
void resetPixels(const Color& pixels, int w, int h);
/* modify pixels */
diff --git a/src/libjin/Graphics/Drawable.cpp b/src/libjin/Graphics/Drawable.cpp
index 008d54e..675c54d 100644
--- a/src/libjin/Graphics/Drawable.cpp
+++ b/src/libjin/Graphics/Drawable.cpp
@@ -42,9 +42,13 @@ namespace graphics
glPushMatrix();
glMultMatrixf((const GLfloat*)t.getElements());
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, textCoord);
glVertexPointer(2, GL_FLOAT, 0, vertCoord);
glDrawArrays(GL_QUADS, 0, 4);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
/* pop the model matrix */
glPopMatrix();
diff --git a/src/libjin/Graphics/Font.cpp b/src/libjin/Graphics/Font.cpp
index 4988702..b95f78b 100644
--- a/src/libjin/Graphics/Font.cpp
+++ b/src/libjin/Graphics/Font.cpp
@@ -133,9 +133,13 @@ namespace graphics
// forward to next character
xc += xadvance + spacing;
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
glVertexPointer(2, GL_FLOAT, 0, verCoord);
glDrawArrays(GL_QUADS, 0, 4);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/src/libjin/Graphics/Shader.cpp b/src/libjin/Graphics/Shader.cpp
index 7f849a6..12d4db0 100644
--- a/src/libjin/Graphics/Shader.cpp
+++ b/src/libjin/Graphics/Shader.cpp
@@ -11,9 +11,15 @@ namespace graphics
using namespace jin::filesystem;
+ /**
+ * default_texture
+ * base_shader
+ * SHADER_FORMAT_SIZE
+ * formatShader
+ */
#include "base.shader.h"
- /*
+ /**
* https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value
* The default value of a sampler variable is 0. From the GLSL 3.30 spec,
* section "4.3.5 Uniforms":
@@ -57,8 +63,7 @@ namespace graphics
JSLProgram::JSLProgram(const char* program)
: currentTextureUnit(DEFAULT_TEXTURE_UNIT)
{
- int size = strlen(program) + SHADER_FORMAT_SIZE;
- Buffer b = Buffer(size);
+ Buffer b = Buffer(strlen(program) + SHADER_FORMAT_SIZE);
formatShader((char*)b.data, program);
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader, 1, (const GLchar**)&b.data, NULL);
@@ -92,7 +97,9 @@ namespace graphics
{
glUseProgram(pid);
currentJSLProgram = this;
- bindDefaultTexture();
+ /* bind default texture */
+ int loc = glGetUniformLocation(pid, default_texture);
+ glUniform1i(loc, DEFAULT_TEXTURE_UNIT);
}
/*static*/ void JSLProgram::unuse()
@@ -101,12 +108,6 @@ namespace graphics
currentJSLProgram = nullptr;
}
- void JSLProgram::bindDefaultTexture()
- {
- int loc = glGetUniformLocation(pid, default_texture);
- glUniform1i(loc, DEFAULT_TEXTURE_UNIT);
- }
-
GLint JSLProgram::claimTextureUnit(const std::string& name)
{
std::map<std::string, GLint>::iterator unit = textureUnits.find(name);
diff --git a/src/libjin/Graphics/Shader.h b/src/libjin/Graphics/Shader.h
index 70e6c1d..83a2831 100644
--- a/src/libjin/Graphics/Shader.h
+++ b/src/libjin/Graphics/Shader.h
@@ -39,7 +39,6 @@ namespace graphics
GLint claimTextureUnit(const std::string& name);
JSLProgram(const char* program);
- void bindDefaultTexture();
GLuint pid;
GLint currentTextureUnit;
diff --git a/src/libjin/Graphics/Shapes.cpp b/src/libjin/Graphics/Shapes.cpp
index 13935d2..6cf0af1 100644
--- a/src/libjin/Graphics/Shapes.cpp
+++ b/src/libjin/Graphics/Shapes.cpp
@@ -14,14 +14,18 @@ namespace graphics
void point(int x, int y)
{
float vers[] = { x + 0.5f , y + 0.5f };
+ glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)vers);
glDrawArrays(GL_POINTS, 0, 1);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
void points(int n, GLshort* p)
{
+ glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_SHORT, 0, (GLvoid*)p);
glDrawArrays(GL_POINTS, 0, n);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
void line(int x1, int y1, int x2, int y2)
@@ -31,8 +35,10 @@ namespace graphics
x2, y2
};
- glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)verts);
glDrawArrays(GL_LINES, 0, 2);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
void circle(RenderMode mode, int x, int y, int r)
@@ -72,22 +78,13 @@ namespace graphics
polygon(mode, coords, 3);
}
+ /* TODO: 内存占用很多 */
void polygon_line(float* p, int count)
{
- float* verts = new float[count * 4];
- for (int i = 0; i < count; ++i)
- {
- // each line has two point n,n+1
- verts[i * 4] = p[i * 2];
- verts[i * 4 + 1] = p[i * 2 + 1];
- verts[i * 4 + 2] = p[(i + 1) % count * 2];
- verts[i * 4 + 3] = p[(i + 1) % count * 2 + 1];
- }
-
- glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts);
- glDrawArrays(GL_LINES, 0, count * 2);
-
- delete[] verts;
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p);
+ glDrawArrays(GL_LINE_LOOP, 0, count);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
void polygon(RenderMode mode, float* p, int count)
@@ -98,8 +95,10 @@ namespace graphics
}
else if (mode == FILL)
{
+ glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p);
glDrawArrays(GL_POLYGON, 0, count);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
}
diff --git a/src/libjin/Graphics/Window.cpp b/src/libjin/Graphics/Window.cpp
index 68ebe47..1fb60cc 100644
--- a/src/libjin/Graphics/Window.cpp
+++ b/src/libjin/Graphics/Window.cpp
@@ -73,8 +73,6 @@ namespace graphics
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
/* avoid white screen blink on windows */
swapBuffers();
/* bind to default canvas */
@@ -87,8 +85,6 @@ namespace graphics
/* disable opengl */
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
/* close window */
SDL_DestroyWindow(wnd);
SDL_Quit();
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
index f7ffc43..35bfdfc 100644
--- a/src/lua/embed/boot.lua.h
+++ b/src/lua/embed/boot.lua.h
@@ -45,9 +45,9 @@ function jin.core.run()
local current = previous
while jin.core.running() do
for _, e in pairs(jin.event.poll()) do
- if e.type == "keydown" then
+ if e.type == "KeyDown" then
jin.keyboard.set(e.key, true)
- elseif e.type == "keyup" then
+ elseif e.type == "KeyUp" then
jin.keyboard.set(e.key, false)
end
call(jin.core.onEvent, e)
@@ -78,6 +78,7 @@ jin.core.setHandler = function(handler)
jin.core.onDraw = handler.onDraw
end
+-- TODO: Ĭͼbase64
jin.nogame = {
cs = 64,
sw = jin.graphics.getWidth(),
diff --git a/src/lua/embed/keyboard.lua.h b/src/lua/embed/keyboard.lua.h
index 77bf3a9..ee8428f 100644
--- a/src/lua/embed/keyboard.lua.h
+++ b/src/lua/embed/keyboard.lua.h
@@ -4,7 +4,7 @@ jin.keyboard = jin.keyboard or {}
local keys = {}
-function jin.keyboard.isDown(k)
+function jin.keyboard.isPressed(k)
return keys[k]
end
diff --git a/src/lua/modules/event/event.cpp b/src/lua/modules/event/event.cpp
index be54cf4..71b4a33 100644
--- a/src/lua/modules/event/event.cpp
+++ b/src/lua/modules/event/event.cpp
@@ -36,7 +36,7 @@ namespace lua
case EventType::KEY_DOWN:
case EventType::KEY_UP:
- luax_setfieldstring(L, "type", EventType::KEY_DOWN ? "KeyDown" : "KeyUp");
+ luax_setfieldstring(L, "type", e.type == EventType::KEY_DOWN ? "KeyDown" : "KeyUp");
luax_setfieldstring(L, "key", getKeyName(e.key.keysym.sym));
break;
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index d374f51..679b820 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -260,7 +260,7 @@ namespace lua
return 0;
}
- static int l_palette(lua_State * L)
+ static int l_getColor(lua_State * L)
{
luax_pushnumber(L, context.curRenderColor.r);
luax_pushnumber(L, context.curRenderColor.g);
@@ -541,7 +541,7 @@ namespace lua
{ "clear", l_clear },
{ "draw", l_draw },
{ "setColor", l_setColor },
- { "palette", l_palette },
+ { "getColor", l_getColor },
{ "present", l_present },
/* font */
{ "box", l_box },