diff options
27 files changed, 470 insertions, 84 deletions
diff --git a/bin/game/main.lua b/bin/game/main.lua index 0824509..c5f6095 100644 --- a/bin/game/main.lua +++ b/bin/game/main.lua @@ -10,8 +10,8 @@ local bitmap = nil local sprs = {} local animator = nil local spr = nil -local particle_sprite = nil local ps = nil +local mesh = nil local function createAnimation(path, count, r, c, w, h, loop, speed) local tex = jin.graphics.newTexture(path) local ssheet = jin.graphics.newSpriteSheet(tex) @@ -24,8 +24,13 @@ function jin.core.onLoad() -- bitmap = jin.graphics.newBitmap(200, 200, function(w, h, x, y) -- return {255*math.sin(x/w),255 - 255,255*math.cos(y/w),255} -- end) - local tex = jin.graphics.newTexture("particle.png") - particle_sprite = jin.graphics.newSprite(tex, jin.graphics.SpriteOrigin.MIDDLECENTER) + local tex = jin.graphics.newTexture("splash.png") + mesh = jin.graphics.newMesh() + mesh:setGraphic(tex) + mesh:pushVertex(-20, -20, 0, 0, {255, 0, 0, 255}) + mesh:pushVertex(20, -20, 1, 0, {255, 0, 255, 255}) + mesh:pushVertex(20, 20, 1, 1, {255, 255, 0, 255}) + mesh:pushVertex(-20, 120, 0, 1, {255, 255, 255, 255}) ps = jin.graphics.newParticleSystem() for i = 0, 10 do local t = jin.graphics.newTexture("dust/s_dust_A_" .. i .. ".png") @@ -45,7 +50,6 @@ function jin.core.onLoad() ps:setParticleLife(0.5, 2) ps:addParticleScalePoint(3, 0) ps:addParticleScalePoint(0, 1) - --ps:addParticleSprite(particle_sprite) local animation = createAnimation("anim2.png", 27, 3, 10, 200, 200, true, 50) animator = jin.graphics.newAnimator(animation) spr = animation:getFrame(1) @@ -99,5 +103,8 @@ function jin.core.onDraw() animator:render(350, 150, 1, 1, 0) jin.graphics.print("* Particle system test\n* Animation test", 10, 10) jin.graphics.draw(spr, 100, 200, 1, 1, 0) + jin.graphics.useShader(jin.graphics.Shaders.Mesh) + jin.graphics.draw(mesh, 200, 100) + jin.graphics.unuseShader(); ps:render() end
\ No newline at end of file diff --git a/bin/jin.exe b/bin/jin.exe Binary files differindex 4d5051d..9f0c28d 100644 --- a/bin/jin.exe +++ b/bin/jin.exe diff --git a/build/vc++/libjin-lua/libjin-lua.vcxproj b/build/vc++/libjin-lua/libjin-lua.vcxproj index 273d709..baba962 100644 --- a/build/vc++/libjin-lua/libjin-lua.vcxproj +++ b/build/vc++/libjin-lua/libjin-lua.vcxproj @@ -182,6 +182,7 @@ <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_animator.cpp" /> <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_bitmap.cpp" /> <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_canvas.cpp" /> + <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_mesh.cpp" /> <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_particle_system.cpp" /> <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_sprite.cpp" /> <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_spritesheet.cpp" /> @@ -230,6 +231,7 @@ <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_bitmap.h" /> <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_canvas.h" /> <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_graphics.h" /> + <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_mesh.h" /> <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_page.h" /> <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_particle_system.h" /> <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_shader.h" /> diff --git a/build/vc++/libjin-lua/libjin-lua.vcxproj.filters b/build/vc++/libjin-lua/libjin-lua.vcxproj.filters index f732707..f8a0c6c 100644 --- a/build/vc++/libjin-lua/libjin-lua.vcxproj.filters +++ b/build/vc++/libjin-lua/libjin-lua.vcxproj.filters @@ -207,6 +207,9 @@ <ClCompile Include="..\..\..\src\libjin-lua\je_lua_jin.cpp"> <Filter>source</Filter> </ClCompile> + <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_mesh.cpp"> + <Filter>source\modules\graphics</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\src\libjin-lua\resources\font.ttf.h"> @@ -350,6 +353,9 @@ <ClInclude Include="..\..\..\src\libjin-lua\je_lua_jin.h"> <Filter>source</Filter> </ClInclude> + <ClInclude Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_mesh.h"> + <Filter>source\modules\graphics</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\..\src\libjin-lua\embed\scripts\ai\state_machine.lua"> @@ -358,9 +364,6 @@ <None Include="..\..\..\src\libjin-lua\embed\scripts\ai\ai.lua"> <Filter>source\embed\scripts\ai</Filter> </None> - <None Include="..\..\..\src\libjin-lua\embed\scripts\graphics\graphics.lua"> - <Filter>source\embed\scripts\graphics</Filter> - </None> <None Include="..\..\..\src\libjin-lua\embed\scripts\keyboard\keyboard.lua"> <Filter>source\embed\scripts\keyboard</Filter> </None> @@ -378,5 +381,6 @@ <Text Include="..\..\..\src\libjin-lua\embed\scripts\app.lua"> <Filter>source\embed\scripts</Filter> </Text> + <Text Include="..\..\..\src\libjin-lua\embed\scripts\graphics\graphics.lua" /> </ItemGroup> </Project>
\ No newline at end of file diff --git a/build/vc++/libjin/libjin.vcxproj b/build/vc++/libjin/libjin.vcxproj index 0c12e0c..1eea6e7 100644 --- a/build/vc++/libjin/libjin.vcxproj +++ b/build/vc++/libjin/libjin.vcxproj @@ -182,6 +182,7 @@ <ClInclude Include="..\..\..\src\libjin\Graphics\je_shapes.h" /> <ClInclude Include="..\..\..\src\libjin\Graphics\je_sprite.h" /> <ClInclude Include="..\..\..\src\libjin\Graphics\je_texture.h" /> + <ClInclude Include="..\..\..\src\libjin\graphics\je_vertex.h" /> <ClInclude Include="..\..\..\src\libjin\Graphics\je_window.h" /> <ClInclude Include="..\..\..\src\libjin\graphics\particles\je_particle.h" /> <ClInclude Include="..\..\..\src\libjin\graphics\particles\je_particle_emitter.h" /> @@ -198,6 +199,7 @@ <ClInclude Include="..\..\..\src\libjin\Input\je_keyboard.h" /> <ClInclude Include="..\..\..\src\libjin\Input\je_mouse.h" /> <ClInclude Include="..\..\..\src\libjin\jin.h" /> + <ClInclude Include="..\..\..\src\libjin\math\je_bbox.h" /> <ClInclude Include="..\..\..\src\libjin\math\je_bezier_curve.h" /> <ClInclude Include="..\..\..\src\libjin\Math\je_constant.h" /> <ClInclude Include="..\..\..\src\libjin\math\je_ellipse.h" /> diff --git a/build/vc++/libjin/libjin.vcxproj.filters b/build/vc++/libjin/libjin.vcxproj.filters index b3c062d..a12fbca 100644 --- a/build/vc++/libjin/libjin.vcxproj.filters +++ b/build/vc++/libjin/libjin.vcxproj.filters @@ -315,6 +315,12 @@ <ClInclude Include="..\..\..\src\libjin\common\je_string.h"> <Filter>source\common</Filter> </ClInclude> + <ClInclude Include="..\..\..\src\libjin\graphics\je_vertex.h"> + <Filter>source\graphics</Filter> + </ClInclude> + <ClInclude Include="..\..\..\src\libjin\math\je_bbox.h"> + <Filter>source\math</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\..\src\libjin\README.md"> diff --git a/src/libjin-lua/embed/graphics.lua.h b/src/libjin-lua/embed/graphics.lua.h index ba80565..071d862 100644 --- a/src/libjin-lua/embed/graphics.lua.h +++ b/src/libjin-lua/embed/graphics.lua.h @@ -97,49 +97,65 @@ static unsigned char graphics_lua[] = { 10,9,32,32,32,32,123,13,10,9,9,32,32,32,32,114,101,116,117,114, 110,32,99,111,108,59,13,10,9,32,32,32,32,125,13,10,9,32,32,32, 32,35,69,78,68,95,70,82,65,71,77,69,78,84,95,83,72,65,68,69, -82,13,10,32,32,32,32,93,93,13,10,9,106,103,46,83,104,97,100,101, -114,115,46,68,101,102,97,117,108,116,32,61,32,106,103,46,110,101,119,83, -104,97,100,101,114,91,91,13,10,9,9,35,86,69,82,84,69,88,95,83, -72,65,68,69,82,13,10,9,9,86,101,114,116,101,120,32,118,101,114,116, -40,86,101,114,116,101,120,32,118,41,13,10,9,9,123,13,10,9,9,9, -114,101,116,117,114,110,32,118,59,13,10,9,9,125,13,10,9,9,35,69, -78,68,95,86,69,82,84,69,88,95,83,72,65,68,69,82,13,10,9,9, -35,70,82,65,71,77,69,78,84,95,83,72,65,68,69,82,13,10,9,9, -67,111,108,111,114,32,102,114,97,103,40,67,111,108,111,114,32,99,111,108, -44,32,84,101,120,116,117,114,101,32,116,101,120,44,32,86,101,114,116,101, +82,13,10,32,32,32,32,93,93,13,10,32,32,32,32,106,103,46,83,104, +97,100,101,114,115,46,77,101,115,104,32,61,32,106,103,46,110,101,119,83, +104,97,100,101,114,91,91,32,13,10,32,32,32,32,32,32,32,9,35,86, +69,82,84,69,88,95,83,72,65,68,69,82,13,10,32,32,32,32,32,32, +32,32,105,110,32,86,101,99,52,32,99,111,108,111,114,59,13,10,9,9, +86,101,114,116,101,120,32,118,101,114,116,40,86,101,114,116,101,120,32,118, +41,13,10,9,9,123,13,10,9,9,9,114,101,116,117,114,110,32,118,59, +13,10,9,9,125,13,10,9,9,35,69,78,68,95,86,69,82,84,69,88, +95,83,72,65,68,69,82,13,10,9,9,35,70,82,65,71,77,69,78,84, +95,83,72,65,68,69,82,13,10,9,9,67,111,108,111,114,32,102,114,97, +103,40,67,111,108,111,114,32,99,111,108,44,32,84,101,120,116,117,114,101, +32,116,101,120,44,32,86,101,114,116,101,120,32,118,41,13,10,9,9,123, +13,10,9,9,9,114,101,116,117,114,110,32,99,111,108,32,42,32,116,101, +120,101,108,40,116,101,120,44,32,118,46,117,118,41,32,42,32,118,46,99, +111,108,111,114,59,13,10,9,9,125,13,10,9,9,35,69,78,68,95,70, +82,65,71,77,69,78,84,95,83,72,65,68,69,82,32,13,10,32,32,32, +32,93,93,13,10,9,106,103,46,83,104,97,100,101,114,115,46,68,101,102, +97,117,108,116,32,61,32,106,103,46,110,101,119,83,104,97,100,101,114,91, +91,13,10,9,9,35,86,69,82,84,69,88,95,83,72,65,68,69,82,13, +10,9,9,86,101,114,116,101,120,32,118,101,114,116,40,86,101,114,116,101, 120,32,118,41,13,10,9,9,123,13,10,9,9,9,114,101,116,117,114,110, -32,99,111,108,32,42,32,116,101,120,101,108,40,116,101,120,44,32,118,46, -117,118,41,59,13,10,9,9,125,13,10,9,9,35,69,78,68,95,70,82, -65,71,77,69,78,84,95,83,72,65,68,69,82,13,10,9,93,93,13,10, -101,110,100,13,10,13,10,108,111,99,97,108,32,95,105,110,105,116,32,61, -32,106,103,46,105,110,105,116,13,10,108,111,99,97,108,32,105,110,105,116, -105,97,108,105,122,101,100,32,61,32,102,97,108,115,101,13,10,106,103,46, -105,110,105,116,32,61,32,102,117,110,99,116,105,111,110,40,115,101,116,116, -105,110,103,41,32,13,10,32,32,32,32,105,102,32,105,110,105,116,105,97, -108,105,122,101,100,32,116,104,101,110,32,13,10,32,32,32,32,32,32,32, -32,114,101,116,117,114,110,32,105,110,105,116,105,97,108,105,122,101,100,13, -10,32,32,32,32,101,110,100,13,10,32,32,32,32,105,110,105,116,105,97, -108,105,122,101,100,32,61,32,95,105,110,105,116,40,115,101,116,116,105,110, -103,41,13,10,32,32,32,32,105,102,32,105,110,105,116,105,97,108,105,122, -101,100,32,116,104,101,110,32,13,10,32,32,32,32,32,32,32,32,99,111, -109,112,105,108,101,66,117,105,108,116,73,110,83,104,97,100,101,114,115,40, -41,13,10,32,32,32,32,32,32,32,32,106,103,46,117,115,101,83,104,97, -100,101,114,40,106,103,46,83,104,97,100,101,114,115,46,70,111,110,116,41, -13,10,32,32,32,32,101,110,100,13,10,32,32,32,32,114,101,116,117,114, -110,32,105,110,105,116,105,97,108,105,122,101,100,32,13,10,101,110,100,13, -10,13,10,106,103,46,117,110,117,115,101,83,104,97,100,101,114,32,61,32, -102,117,110,99,116,105,111,110,40,41,13,10,32,32,32,32,106,103,46,117, -115,101,83,104,97,100,101,114,40,106,103,46,83,104,97,100,101,114,115,46, -70,111,110,116,41,13,10,101,110,100,13,10,13,10,45,45,32,82,101,115, -101,116,32,97,108,108,32,97,116,116,114,105,98,117,116,101,115,32,116,111, -32,100,101,102,97,117,108,116,32,118,97,108,117,101,46,13,10,106,103,46, -114,101,115,101,116,32,61,32,102,117,110,99,116,105,111,110,40,41,13,10, -32,32,32,32,106,103,46,115,101,116,67,111,108,111,114,40,50,53,53,44, -32,50,53,53,44,32,50,53,53,44,32,50,53,53,41,13,10,32,32,32, -32,106,103,46,115,101,116,67,108,101,97,114,67,111,108,111,114,40,48,44, -32,48,44,32,48,44,32,50,53,53,41,13,10,32,32,32,32,106,103,46, -99,108,101,97,114,40,41,13,10,32,32,32,32,106,103,46,117,110,115,101, -116,70,111,110,116,40,41,13,10,32,32,32,32,106,103,46,117,110,117,115, -101,83,104,97,100,101,114,40,41,13,10,101,110,100,13,10 +32,118,59,13,10,9,9,125,13,10,9,9,35,69,78,68,95,86,69,82, +84,69,88,95,83,72,65,68,69,82,13,10,9,9,35,70,82,65,71,77, +69,78,84,95,83,72,65,68,69,82,13,10,9,9,67,111,108,111,114,32, +102,114,97,103,40,67,111,108,111,114,32,99,111,108,44,32,84,101,120,116, +117,114,101,32,116,101,120,44,32,86,101,114,116,101,120,32,118,41,13,10, +9,9,123,13,10,9,9,9,114,101,116,117,114,110,32,99,111,108,32,42, +32,116,101,120,101,108,40,116,101,120,44,32,118,46,117,118,41,59,13,10, +9,9,125,13,10,9,9,35,69,78,68,95,70,82,65,71,77,69,78,84, +95,83,72,65,68,69,82,13,10,9,93,93,32,13,10,101,110,100,13,10, +13,10,108,111,99,97,108,32,95,105,110,105,116,32,61,32,106,103,46,105, +110,105,116,13,10,108,111,99,97,108,32,105,110,105,116,105,97,108,105,122, +101,100,32,61,32,102,97,108,115,101,13,10,106,103,46,105,110,105,116,32, +61,32,102,117,110,99,116,105,111,110,40,115,101,116,116,105,110,103,41,32, +13,10,32,32,32,32,105,102,32,105,110,105,116,105,97,108,105,122,101,100, +32,116,104,101,110,32,13,10,32,32,32,32,32,32,32,32,114,101,116,117, +114,110,32,105,110,105,116,105,97,108,105,122,101,100,13,10,32,32,32,32, +101,110,100,13,10,32,32,32,32,105,110,105,116,105,97,108,105,122,101,100, +32,61,32,95,105,110,105,116,40,115,101,116,116,105,110,103,41,13,10,32, +32,32,32,105,102,32,105,110,105,116,105,97,108,105,122,101,100,32,116,104, +101,110,32,13,10,32,32,32,32,32,32,32,32,99,111,109,112,105,108,101, +66,117,105,108,116,73,110,83,104,97,100,101,114,115,40,41,13,10,32,32, +32,32,32,32,32,32,106,103,46,117,115,101,83,104,97,100,101,114,40,106, +103,46,83,104,97,100,101,114,115,46,68,101,102,97,117,108,116,41,13,10, +32,32,32,32,101,110,100,13,10,32,32,32,32,114,101,116,117,114,110,32, +105,110,105,116,105,97,108,105,122,101,100,32,13,10,101,110,100,13,10,13, +10,106,103,46,117,110,117,115,101,83,104,97,100,101,114,32,61,32,102,117, +110,99,116,105,111,110,40,41,13,10,32,32,32,32,106,103,46,117,115,101, +83,104,97,100,101,114,40,106,103,46,83,104,97,100,101,114,115,46,68,101, +102,97,117,108,116,41,13,10,101,110,100,13,10,13,10,45,45,32,82,101, +115,101,116,32,97,108,108,32,97,116,116,114,105,98,117,116,101,115,32,116, +111,32,100,101,102,97,117,108,116,32,118,97,108,117,101,46,13,10,106,103, +46,114,101,115,101,116,32,61,32,102,117,110,99,116,105,111,110,40,41,13, +10,32,32,32,32,106,103,46,115,101,116,67,111,108,111,114,40,50,53,53, +44,32,50,53,53,44,32,50,53,53,44,32,50,53,53,41,13,10,32,32, +32,32,106,103,46,115,101,116,67,108,101,97,114,67,111,108,111,114,40,48, +44,32,48,44,32,48,44,32,50,53,53,41,13,10,32,32,32,32,106,103, +46,99,108,101,97,114,40,41,13,10,32,32,32,32,106,103,46,117,110,115, +101,116,70,111,110,116,40,41,13,10,32,32,32,32,106,103,46,117,110,117, +115,101,83,104,97,100,101,114,40,41,13,10,101,110,100,13,10 }; diff --git a/src/libjin-lua/embed/scripts/graphics/graphics.lua b/src/libjin-lua/embed/scripts/graphics/graphics.lua index a0efe03..8b16a35 100644 --- a/src/libjin-lua/embed/scripts/graphics/graphics.lua +++ b/src/libjin-lua/embed/scripts/graphics/graphics.lua @@ -103,6 +103,21 @@ local function compileBuiltInShaders() } #END_FRAGMENT_SHADER ]] + jg.Shaders.Mesh = jg.newShader[[ + #VERTEX_SHADER + in Vec4 color; + Vertex vert(Vertex v) + { + return v; + } + #END_VERTEX_SHADER + #FRAGMENT_SHADER + Color frag(Color col, Texture tex, Vertex v) + { + return col * texel(tex, v.uv) * v.color; + } + #END_FRAGMENT_SHADER + ]] jg.Shaders.Default = jg.newShader[[ #VERTEX_SHADER Vertex vert(Vertex v) @@ -116,7 +131,7 @@ local function compileBuiltInShaders() return col * texel(tex, v.uv); } #END_FRAGMENT_SHADER - ]] + ]] end local _init = jg.init @@ -128,13 +143,13 @@ jg.init = function(setting) initialized = _init(setting) if initialized then compileBuiltInShaders() - jg.useShader(jg.Shaders.Font) + jg.useShader(jg.Shaders.Default) end return initialized end jg.unuseShader = function() - jg.useShader(jg.Shaders.Font) + jg.useShader(jg.Shaders.Default) end -- Reset all attributes to default value. diff --git a/src/libjin-lua/modules/graphics/je_lua_graphics.cpp b/src/libjin-lua/modules/graphics/je_lua_graphics.cpp index fba77d7..aeb1921 100644 --- a/src/libjin-lua/modules/graphics/je_lua_graphics.cpp +++ b/src/libjin-lua/modules/graphics/je_lua_graphics.cpp @@ -9,6 +9,7 @@ #include "je_lua_sprite.h" #include "je_lua_spritesheet.h" #include "je_lua_bitmap.h" +#include "je_lua_mesh.h" #include "je_lua_ttf.h" #include "je_lua_ttf_data.h" #include "je_lua_texture.h" @@ -398,6 +399,22 @@ namespace JinEngine sprite->render(x, y, sx, sy, r); } + LUA_IMPLEMENT void l_draw_mesh(lua_State* L) + { + if (!luax_istype(L, 1, Jin_Lua_Mesh)) + return; + LuaObject* obj= (LuaObject*)luax_toudata(L, 1); + Mesh* mesh = obj->getObject<Mesh>(); + int x = luax_optnumber(L, 2, 0); + int y = luax_optnumber(L, 3, 0); + float sx = luax_optnumber(L, 4, 1); + float sy = luax_optnumber(L, 5, 1); + float r = luax_optnumber(L, 6, 0); + float ox = luax_optnumber(L, 7, 0); + float oy = luax_optnumber(L, 8, 0); + mesh->render(x, y, sx, sy, r, ox, oy); + } + LUA_IMPLEMENT int l_draw(lua_State* L) { if (luax_istype(L, 1, Jin_Lua_Texture)) @@ -410,6 +427,8 @@ namespace JinEngine l_draw_page(L); else if (luax_istype(L, 1, Jin_Lua_Sprite)) l_draw_sprite(L); + else if (luax_istype(L, 1, Jin_Lua_Mesh)) + l_draw_mesh(L); else { luax_typerror(L, 1, "texture or canvas"); @@ -455,7 +474,9 @@ namespace JinEngine else { luax_typerror(L, 1, "texture or canvas"); + return 1; } + return 0; } /* print(string, x, y, lineheight, spacing) */ @@ -900,6 +921,12 @@ namespace JinEngine return 1; } + LUA_IMPLEMENT int l_newMesh(lua_State* L) + { + LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Mesh, new Shared(new Mesh())); + return 1; + } + /* setFont(font) */ LUA_IMPLEMENT int l_setFont(lua_State* L) { @@ -981,6 +1008,7 @@ namespace JinEngine luaopen_Animation(L); luaopen_Animator(L); luaopen_ParticleSystem(L); + luaopen_Mesh(L); luaL_Reg methods[] = { /* window */ @@ -1006,6 +1034,7 @@ namespace JinEngine { "newAnimation", l_newAnimation }, { "newAnimator", l_newAnimator }, { "newParticleSystem", l_newParticleSystem }, + { "newMesh", l_newMesh }, /* render */ { "setClearColor", l_setClearColor }, { "clear", l_clear }, diff --git a/src/libjin-lua/modules/graphics/je_lua_mesh.cpp b/src/libjin-lua/modules/graphics/je_lua_mesh.cpp new file mode 100644 index 0000000..fc42096 --- /dev/null +++ b/src/libjin-lua/modules/graphics/je_lua_mesh.cpp @@ -0,0 +1,87 @@ +#include "common/je_lua_object.h" +#include "common/je_lua_common.h" +#include "libjin/jin.h" +#include "je_lua_mesh.h" +#include "je_lua_texture.h" + +using namespace JinEngine::Math; +using namespace JinEngine::Graphics; + +namespace JinEngine +{ + namespace Lua + { + + const char* Jin_Lua_Mesh = "Mesh"; + + LUA_IMPLEMENT inline Mesh* checkMesh(lua_State* L) + { + LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh); + return luaObj->getObject<Mesh>(); + } + + LUA_IMPLEMENT int l_getBound(lua_State* L) + { + Mesh* mesh = checkMesh(L); + BBox bbox = mesh->getBound(); + luax_pushnumber(L, bbox.l); + luax_pushnumber(L, bbox.r); + luax_pushnumber(L, bbox.t); + luax_pushnumber(L, bbox.b); + return 4; + } + + LUA_IMPLEMENT int l_setGraphic(lua_State* L) + { + LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh); + Mesh* mesh = luaObj->getObject<Mesh>(); + luaObj->removeDependency((int)MeshDependency::DEP_GRAPHIC); + LuaObject* obj = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Texture); + mesh->setGraphic(obj->getObject<Texture>()); + luaObj->setDependency((int)MeshDependency::DEP_GRAPHIC, obj); + return 0; + } + + // x, y, u, v, color_table + LUA_IMPLEMENT int l_pushVertex(lua_State* L) + { + Mesh* mesh = checkMesh(L); + float x = luax_checknumber(L, 2); + float y = luax_checknumber(L, 3); + float u = luax_checknumber(L, 4); + float v = luax_checknumber(L, 5); + if (!luax_istable(L, 6)) + { + luax_typerror(L, 6, "color table"); + return 1; + } + Color c; + c.r = luax_rawgetnumberthenpop(L, -1, 1); + c.g = luax_rawgetnumberthenpop(L, -1, 2); + c.b = luax_rawgetnumberthenpop(L, -1, 3); + c.a = luax_rawgetnumberthenpop(L, -1, 4); + mesh->pushVertex(x, y, u, v, c); + return 0; + } + + LUA_IMPLEMENT int l_gc(lua_State* L) + { + LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh); + luaObj->release(); + return 0; + } + + LUA_EXPORT void luaopen_Mesh(lua_State* L) + { + luaL_Reg methods[] = { + { "__gc", l_gc }, + { "getBound", l_getBound }, + { "setGraphic", l_setGraphic }, + { "pushVertex", l_pushVertex }, + { 0, 0 } + }; + luax_newtype(L, Jin_Lua_Mesh, methods); + } + + } // namespace Lua +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin-lua/modules/graphics/je_lua_mesh.h b/src/libjin-lua/modules/graphics/je_lua_mesh.h new file mode 100644 index 0000000..b3fa00e --- /dev/null +++ b/src/libjin-lua/modules/graphics/je_lua_mesh.h @@ -0,0 +1,21 @@ +#ifndef __JE_LUA_MESH_H__ +#define __JE_LUA_MESH_H__ + +namespace JinEngine +{ + namespace Lua + { + + enum class MeshDependency + { + DEP_GRAPHIC = 1, + }; + + extern const char* Jin_Lua_Mesh; + + void luaopen_Mesh(lua_State* L); + + } +} + +#endif
\ No newline at end of file diff --git a/src/libjin/graphics/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp index 4fd1af1..7737f90 100644 --- a/src/libjin/graphics/fonts/je_texture_font.cpp +++ b/src/libjin/graphics/fonts/je_texture_font.cpp @@ -281,8 +281,10 @@ namespace JinEngine for (int i = 0; i < glyphinfolist.size(); ++i) { const GlyphArrayDrawInfo& info = glyphinfolist[i]; + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x); shader->uploadUV(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u); + shader->endUploadAttributes(); gl.bindTexture(info.texture); gl.drawArrays(GL_QUADS, 0, info.count); gl.bindTexture(0); diff --git a/src/libjin/graphics/fonts/je_ttf.cpp b/src/libjin/graphics/fonts/je_ttf.cpp index 29bc834..904617a 100644 --- a/src/libjin/graphics/fonts/je_ttf.cpp +++ b/src/libjin/graphics/fonts/je_ttf.cpp @@ -300,8 +300,10 @@ namespace JinEngine for (int i = 0; i < glyphinfolist.size(); ++i) { const GlyphArrayDrawInfo& info = glyphinfolist[i]; + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x); shader->uploadUV(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u); + shader->endUploadAttributes(); gl.bindTexture(info.texture); gl.drawArrays(GL_QUADS, 0, info.count); gl.bindTexture(0); diff --git a/src/libjin/graphics/je_graphic.cpp b/src/libjin/graphics/je_graphic.cpp index a0c2257..1e18995 100644 --- a/src/libjin/graphics/je_graphic.cpp +++ b/src/libjin/graphics/je_graphic.cpp @@ -73,8 +73,10 @@ namespace JinEngine Shader* shader = gl.getShader(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_FLOAT, 0, vertexCoords); shader->uploadUV(2, GL_FLOAT, 0, textureCoords); + shader->endUploadAttributes(); gl.bindTexture(getGLTexture()); gl.drawArrays(GL_QUADS, 0, 4); @@ -106,8 +108,10 @@ namespace JinEngine Shader* shader = gl.getShader(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_FLOAT, 0, vertexCoords); shader->uploadUV(2, GL_FLOAT, 0, textureCoords); + shader->endUploadAttributes(); gl.bindTexture(getGLTexture()); gl.drawArrays(GL_QUADS, 0, 4); diff --git a/src/libjin/graphics/je_graphics.h b/src/libjin/graphics/je_graphics.h index 64f92a4..e8f06c1 100644 --- a/src/libjin/graphics/je_graphics.h +++ b/src/libjin/graphics/je_graphics.h @@ -12,6 +12,7 @@ #include "je_image.h" #include "je_sprite.h" #include "je_sprite_sheet.h" +#include "je_mesh.h" #include "shaders/je_shader.h" diff --git a/src/libjin/graphics/je_mesh.cpp b/src/libjin/graphics/je_mesh.cpp index a88abbd..4c27433 100644 --- a/src/libjin/graphics/je_mesh.cpp +++ b/src/libjin/graphics/je_mesh.cpp @@ -1,11 +1,77 @@ +#include "../math/je_math.h" + #include "je_mesh.h" +#include "shaders/je_shader.h" + +using namespace JinEngine::Math; +using namespace JinEngine::Graphics::Shaders; namespace JinEngine { namespace Graphics { - + Mesh::Mesh() + : mGraphic(nullptr) + { + } + + void Mesh::setGraphic(const Graphic* graphic) + { + mGraphic = graphic; + } + + void Mesh::pushVertex(float x, float y, float u, float v, Color color) + { + Vertex vert; + vert.x = x; vert.y = y; + vert.u = u; vert.v = v; + vert.color = color; + pushVertex(vert); + } + + void Mesh::pushVertex(const Vertex& vert) + { + mVertices.push_back(vert); + // Update bound + if (mVertices.size() == 2) + { + const Vertex& v0 = mVertices[0]; + mBound.l = min(v0.x, vert.x); + mBound.r = max(v0.x, vert.x); + mBound.t = min(v0.y, vert.y); + mBound.b = max(v0.y, vert.y); + } + else + { + float x = vert.x, y = vert.y; + mBound.l = x < mBound.l ? x : mBound.l; + mBound.r = x > mBound.r ? x : mBound.r; + mBound.t = y < mBound.t ? y : mBound.t; + mBound.b = y > mBound.b ? y : mBound.b; + } + } + + void Mesh::render(float x, float y, float sx, float sy, float r, float ox, float oy) const + { + if (mGraphic == nullptr || mVertices.size() == 0) + return; + + Math::Matrix modelViewMatrix = gl.getModelViewMatrix(x, y, sx, sy, r, ox, oy); + + Shader* shader = gl.getShader(); + shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); + shader->beginUploadAttributes(); + shader->uploadVertices(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].x)); + shader->uploadUV(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].u)); + shader->uploadColor(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &(mVertices[0].color), GL_TRUE); + shader->endUploadAttributes(); + + gl.bindTexture(mGraphic->getGLTexture()); + gl.drawArrays(GL_POLYGON, 0, mVertices.size()); + gl.bindTexture(0); + }; } // namespace Graphics } // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/graphics/je_mesh.h b/src/libjin/graphics/je_mesh.h index 5bcca2e..1dbf3a4 100644 --- a/src/libjin/graphics/je_mesh.h +++ b/src/libjin/graphics/je_mesh.h @@ -1,6 +1,11 @@ #ifndef __JE_MESH_H__ #define __JE_MESH_H__ +#include <vector> + +#include "../math/je_bbox.h" + +#include "je_vertex.h" #include "je_graphic.h" namespace JinEngine @@ -11,15 +16,34 @@ namespace JinEngine /// /// A 2D mesh. /// - class Mesh + class Mesh : public Renderable, public Object { public: + Mesh(); + void setGraphic(const Graphic* graphic); - void pushVertex(float x, float y, float u, float v); + void pushVertex(float x, float y, float u, float v, Color color = Color::WHITE); + void pushVertex(const Vertex& vertex); + inline Math::BBox getBound() { return mBound; } + + void render(float x, float y, float sx, float sy, float r, float ox = 0, float oy = 0) const; private: + /// + /// Graphic binded. + /// const Graphic* mGraphic; + /// + /// Bound box of mesh. + /// + Math::BBox mBound; + + /// + /// + /// + std::vector<Vertex> mVertices; + }; } // namespace Graphics diff --git a/src/libjin/graphics/je_shapes.cpp b/src/libjin/graphics/je_shapes.cpp index 96a4f76..9af031d 100644 --- a/src/libjin/graphics/je_shapes.cpp +++ b/src/libjin/graphics/je_shapes.cpp @@ -23,7 +23,9 @@ namespace JinEngine float verts[] = { x + 0.5f , y + 0.5f }; Shader* shader = gl.getShader(); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_FLOAT, 0, verts); + shader->endUploadAttributes(); Matrix modelMatrix = gl.getModelViewMatrix(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); @@ -34,7 +36,9 @@ namespace JinEngine void points(int n, GLshort* p) { Shader* shader = gl.getShader(); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_SHORT, 0, p); + shader->endUploadAttributes(); Matrix modelMatrix = gl.getModelViewMatrix(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); @@ -50,7 +54,9 @@ namespace JinEngine }; Shader* shader = gl.getShader(); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_FLOAT, 0, verts); + shader->endUploadAttributes(); Matrix modelMatrix = gl.getModelViewMatrix(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); @@ -101,7 +107,9 @@ namespace JinEngine Matrix modelMatrix = gl.getModelViewMatrix(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_FLOAT, 0, p); + shader->endUploadAttributes(); glDrawArrays(GL_LINE_LOOP, 0, count); } @@ -118,7 +126,9 @@ namespace JinEngine Matrix modelMatrix = gl.getModelViewMatrix(); shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); + shader->beginUploadAttributes(); shader->uploadVertices(2, GL_FLOAT, 0, p); + shader->endUploadAttributes(); glDrawArrays(GL_POLYGON, 0, count); } diff --git a/src/libjin/graphics/je_vertex.h b/src/libjin/graphics/je_vertex.h new file mode 100644 index 0000000..d149cfc --- /dev/null +++ b/src/libjin/graphics/je_vertex.h @@ -0,0 +1,21 @@ +#ifndef __JE_MATH_VERTEX_H__ +#define __JE_MATH_VERTEX_H__ + +#include "je_color.h" + +namespace JinEngine +{ + namespace Graphics + { + + struct Vertex + { + float x, y; // Coordinates + float u, v; // UV + Color color; // Color + }; + + } +} + +#endif
\ No newline at end of file diff --git a/src/libjin/graphics/shaders/je_jsl_compiler.cpp b/src/libjin/graphics/shaders/je_jsl_compiler.cpp index e04958c..74613ad 100644 --- a/src/libjin/graphics/shaders/je_jsl_compiler.cpp +++ b/src/libjin/graphics/shaders/je_jsl_compiler.cpp @@ -21,6 +21,7 @@ namespace JinEngine JinEngine::String SHADER_MAIN_TEXTURE = "jin_MainTexture"; JinEngine::String SHADER_VERTEX_COORDS = "jin_VertexCoords"; JinEngine::String SHADER_TEXTURE_COORDS = "jin_TextureCoords"; + JinEngine::String SHADER_VERTEX_COLOR = "jin_VertexColor"; JinEngine::String SHADER_VERSION = "#version 130 core \n"; JinEngine::String SHADER_DEFINITIONS = // Types @@ -38,6 +39,7 @@ namespace JinEngine "{ \n" " vec2 xy; \n" " vec2 uv; \n" + " vec4 color; \n" "}; \n" "\n"; JinEngine::String SHADER_UNIFORMS = @@ -52,20 +54,23 @@ namespace JinEngine SHADER_DEFINITIONS + SHADER_UNIFORMS + "in vec2 " + SHADER_VERTEX_COORDS + "; \n" - "in vec2 " + SHADER_TEXTURE_COORDS + "; \n"; + "in vec2 " + SHADER_TEXTURE_COORDS + "; \n" + "in vec4 " + SHADER_VERTEX_COLOR + "; \n"; // Color data in unsigned byte. static JinEngine::String vert_part2 = "\n" "out vec4 jin_Color; \n" "out vec2 jin_XY; \n" "out vec2 jin_UV; \n" + "out vec4 jin_COLOR; \n" "void main()\n" "{\n" " vec4 v = " + SHADER_MODELVIEW_MATRIX + " * vec4(" + SHADER_VERTEX_COORDS + ", 0, 1.0); \n" - " Vertex _v = vert(Vertex(v.xy, " + SHADER_TEXTURE_COORDS + ")); \n" + " Vertex _v = vert(Vertex(v.xy, " + SHADER_TEXTURE_COORDS + ", " + SHADER_VERTEX_COLOR + ")); \n" " gl_Position = " + SHADER_PROJECTION_MATRIX + " * vec4(_v.xy, 0, 1.0f); \n" " jin_Color = gl_Color; \n" " jin_XY = _v.xy; \n" " jin_UV = _v.uv; \n" + " jin_COLOR = _v.color; \n" "}"; return vert_part1 + vert + vert_part2; } @@ -78,13 +83,14 @@ namespace JinEngine SHADER_UNIFORMS + "in vec4 jin_Color; \n" "in vec2 jin_XY; \n" - "in vec2 jin_UV; \n"; + "in vec2 jin_UV; \n" + "in vec4 jin_COLOR; \n"; static JinEngine::String frag_part2 = "\n" "out vec4 jin_OutColor; \n" "void main() \n" "{ \n" - " jin_OutColor = frag(jin_Color, " + SHADER_MAIN_TEXTURE + ", Vertex(jin_XY, jin_UV)); \n" + " jin_OutColor = frag(jin_Color, " + SHADER_MAIN_TEXTURE + ", Vertex(jin_XY, jin_UV, jin_COLOR)); \n" "} \n"; return frag_part1 + frag + frag_part2; } diff --git a/src/libjin/graphics/shaders/je_jsl_compiler.h b/src/libjin/graphics/shaders/je_jsl_compiler.h index ed6775a..c34f8ec 100644 --- a/src/libjin/graphics/shaders/je_jsl_compiler.h +++ b/src/libjin/graphics/shaders/je_jsl_compiler.h @@ -21,6 +21,7 @@ namespace JinEngine extern JinEngine::String SHADER_MAIN_TEXTURE; extern JinEngine::String SHADER_VERTEX_COORDS; extern JinEngine::String SHADER_TEXTURE_COORDS; + extern JinEngine::String SHADER_VERTEX_COLOR; /// /// Compile JSL into GLSL. diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp index f752e99..16627d5 100644 --- a/src/libjin/graphics/shaders/je_shader.cpp +++ b/src/libjin/graphics/shaders/je_shader.cpp @@ -240,25 +240,36 @@ namespace JinEngine glUniformMatrix4fv(loc, 1, GL_FALSE, mat4->getElements()); } - void Shader::uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers) + void Shader::uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { - GLint loc = glGetAttribLocation(mPID, SHADER_VERTEX_COORDS); - glEnableVertexAttribArray(0); - glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers); + uploadAttribute(SHADER_VERTEX_COORDS, n, type, stride, pointers, normalized); } - void Shader::uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers) + void Shader::uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { - GLint loc = glGetAttribLocation(mPID, SHADER_TEXTURE_COORDS); - glEnableVertexAttribArray(1); - glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers); + uploadAttribute(SHADER_TEXTURE_COORDS, n, type, stride, pointers, normalized); } - void Shader::uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers) + void Shader::uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) + { + uploadAttribute(SHADER_VERTEX_COLOR, n, type, stride, pointers, normalized); + } + + void Shader::beginUploadAttributes() + { + mAttributeIndex = 0; + } + + void Shader::endUploadAttributes() + { + mAttributeIndex = 0; + } + + void Shader::uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { GLint loc = glGetAttribLocation(mPID, name); - glEnableVertexAttribArray(1); - glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers); + glEnableVertexAttribArray(mAttributeIndex++); + glVertexAttribPointer(loc, n, type, normalized, stride, pointers); } } // namespace Shaders diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h index 9056d51..6a2db9c 100644 --- a/src/libjin/graphics/shaders/je_shader.h +++ b/src/libjin/graphics/shaders/je_shader.h @@ -132,7 +132,7 @@ namespace JinEngine /// @param stride Byte offset between consecutive generic vertex attributes. /// @param pointers Pointer to the first component of the first generic vertex attribute in the array. /// - void uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers); + void uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); /// /// Set texture UV coordinates. @@ -142,12 +142,27 @@ namespace JinEngine /// @param stride Byte offset between consecutive generic vertex attributes. /// @param pointers Pointer to the first component of the first generic vertex attribute in the array. /// - void uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers); + void uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); + + /// + /// Upload vertex color array. + /// + void uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); /// /// Set attribute. /// - void uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers); + void uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); + + /// + /// Reset attribute index. + /// + void beginUploadAttributes(); + + /// + /// Reset attribute index. + /// + void endUploadAttributes(); /// /// Program ID. @@ -174,6 +189,7 @@ namespace JinEngine GLuint mPID; GLint mCurrentTextureUnit; std::map<std::string, GLint> mTextureUnits; + GLint mAttributeIndex; }; diff --git a/src/libjin/math/je_bbox.h b/src/libjin/math/je_bbox.h new file mode 100644 index 0000000..ce88080 --- /dev/null +++ b/src/libjin/math/je_bbox.h @@ -0,0 +1,30 @@ +#ifndef __JE_BBOX_H__ +#define __JE_BBOX_H__ + +namespace JinEngine +{ + namespace Math + { + + /// + /// + /// + struct BBox + { + BBox() + : l(0), r(0), t(0), b(0) + { + } + + BBox(float _l, float _r, float _t, float _b) + : l(+l), r(_r), t(_t), b(_b) + { + } + + float l, r, t, b; + }; + + } // namespace Math +} // namespace JinEngine + +#endif // __JE_BBOX_H__
\ No newline at end of file diff --git a/src/libjin/math/je_matrix.cpp b/src/libjin/math/je_matrix.cpp index f51ef5d..f422002 100644 --- a/src/libjin/math/je_matrix.cpp +++ b/src/libjin/math/je_matrix.cpp @@ -1,3 +1,5 @@ +#include "../graphics/je_vertex.h" + #include "je_matrix.h" #include <cstring> // memcpy @@ -177,7 +179,7 @@ namespace JinEngine // | e2 e6 e10 e14 | // | e3 e7 e11 e15 | - void Matrix::transform(vertex * dst, const vertex * src, int size) const + void Matrix::transform(Graphics::Vertex* dst, const Graphics::Vertex* src, int size) const { for (int i = 0; i<size; ++i) { diff --git a/src/libjin/math/je_matrix.h b/src/libjin/math/je_matrix.h index 65f080b..7955de1 100644 --- a/src/libjin/math/je_matrix.h +++ b/src/libjin/math/je_matrix.h @@ -3,21 +3,21 @@ namespace JinEngine { - namespace Math + + // Forward declarations. + namespace Graphics { + struct Vertex; + } - struct vertex - { - unsigned char r, g, b, a; - float x, y; - float s, t; - }; + namespace Math + { /// /// This class is the basis for all transformations in LOVE. Althought not /// really needed for 2D, it contains 4x4 elements to be compatible with /// OpenGL without conversions. - /// Ҫתõľ + /// ҪתõOpenGL /// https://blog.csdn.net/candycat1992/article/details/8830894 /// class Matrix @@ -150,7 +150,7 @@ namespace JinEngine /// @param src The source vertices. /// @param size The number of vertices. /// - void transform(vertex * dst, const vertex * src, int size) const; + void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const; }; diff --git a/src/libjin/math/je_quad.h b/src/libjin/math/je_quad.h index e62f370..5bda125 100644 --- a/src/libjin/math/je_quad.h +++ b/src/libjin/math/je_quad.h @@ -22,6 +22,7 @@ namespace JinEngine } float x, y, w, h; + }; } // namespace Math |