Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
There was an attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily committed Aug 25, 2022
1 parent b5eddf8 commit fbe45e6
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 211 deletions.
13 changes: 13 additions & 0 deletions .idea/LuminolFXRuby.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ gemspec
gem "gtk3"
gem "opengl-bindings2"
gem "rake"
gem "optparse"
gem "optparse"
gem 'rubocop', group: 'development'
gem 'ruby-vips'
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
atk (3.5.1)
glib2 (= 3.5.1)
cairo (1.17.5)
Expand All @@ -15,6 +16,7 @@ GEM
cairo-gobject (3.5.1)
cairo (>= 1.16.2)
glib2 (= 3.5.1)
ffi (1.12.2)
fiddle (1.1.0)
gdk3 (3.5.1)
cairo-gobject (= 3.5.1)
Expand All @@ -36,17 +38,40 @@ GEM
gdk_pixbuf2 (= 3.5.1)
gio2 (= 3.5.1)
pango (= 3.5.1)
json (2.6.2)
matrix (0.4.2)
native-package-installer (1.1.4)
opengl-bindings2 (2.0.0)
optparse (0.2.0)
pango (3.5.1)
cairo-gobject (= 3.5.1)
gobject-introspection (= 3.5.1)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
pkg-config (1.4.7)
rainbow (3.1.1)
rake (13.0.6)
red-colors (0.3.0)
matrix
regexp_parser (2.5.0)
rexml (3.2.5)
rubocop (1.35.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
ruby-vips (2.1.4)
ffi (~> 1.12)
unicode-display_width (2.2.0)

PLATFORMS
x64-mingw-ucrt
Expand All @@ -58,6 +83,8 @@ DEPENDENCIES
opengl-bindings2
optparse
rake
rubocop
ruby-vips

BUNDLED WITH
2.3.14
4 changes: 2 additions & 2 deletions lib/luminol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def self.start

app = Application.new
puts app.run
rescue Exception => e
raise e
rescue StandardError => e
# raise e
dialog = Gtk::MessageDialog.new(
buttons: :ok_cancel,
message_type: :error
Expand Down
10 changes: 10 additions & 0 deletions lib/luminol/core/shader/GeometryRenderer.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330 core

uniform sampler2D texture0;
in vec2 texCoord;
out vec4 FragColor;

void main()
{
FragColor = texture(texture0, texCoord);
}
39 changes: 39 additions & 0 deletions lib/luminol/core/shader/GeometryRenderer.geom
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#version 330 core

uniform mat4 projection;

in VS_OUT {
uint tileId;
} gs_in[];

out vec2 texCoord;

layout (points) in;
layout (triangle_strip, max_vertices = 4) out;

void main() {
uint tileId = gs_in[0].tileId & 255u;
float tileX = float(tileId & 15u) / 16.0;
float tileY = float((tileId >> 4u) & 15u) / 16.0;

const float B = 1 / 256.0;
const float S = 1 / 16.0;

gl_Position = projection * gl_in[0].gl_Position;
texCoord = vec2(tileX + B, tileY + B);
EmitVertex();

gl_Position = projection * (gl_in[0].gl_Position + vec4(1.0, 0.0, 0.0, 0.0));
texCoord = vec2(tileX + S - B, tileY + B);
EmitVertex();

gl_Position = projection * (gl_in[0].gl_Position + vec4(0.0, 1.0, 0.0, 0.0));
texCoord = vec2(tileX + B, tileY + S - B);
EmitVertex();

gl_Position = projection * (gl_in[0].gl_Position + vec4(1.0, 1.0, 0.0, 0.0));
texCoord = vec2(tileX + S - B, tileY + S - B);
EmitVertex();

EndPrimitive();
}
20 changes: 20 additions & 0 deletions lib/luminol/core/shader/GeometryRenderer.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#version 330 core

uniform mat4 projection;
uniform ivec2 mapSize;

layout (location = 0) in uint aTileId;

out VS_OUT {
uint tileId;
} vs_out;

void main()
{
int i = gl_VertexID;
float x = float(i / mapSize.y); //float(i & 15);
float y = float(i % mapSize.y); //float((i >> 4) & 15);
gl_Position = vec4(x, y, 0, 1);

vs_out.tileId = aTileId;
}
43 changes: 43 additions & 0 deletions lib/luminol/core/texture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'opengl'

class Texture

attr_reader :id, :height, :width

def initialize(*paths)
pixbuf = System::Cache.load_image(*paths)

@width, @height = pixbuf.width, pixbuf.height
pixels = pixbuf.pixels

id_buf = ' ' * 4
GL.GenTextures(1, id_buf)
@id = id_buf.unpack1('L')

bind
GL.TexImage2D(
GL::TEXTURE_2D,
0,
GL::RGB,
@width,
@height,
0,
GL::RGB,
GL::UNSIGNED_BYTE,
pixels.pack("C#{pixels.size}")
)
unbind
end

def bind
GL.BindTexture(GL::TEXTURE_2D, @id)
end

def unbind
GL.BindTexture(GL::TEXTURE_2D, 0)
end

def delete
GL.DeleteTextures(1, [@id].pack('L'))
end
end
16 changes: 16 additions & 0 deletions lib/luminol/core/tileatlas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'opengl'
require_relative '../core/texture'

class TileAtlas
def initialize
@tileset_tex = Texture.new 'Graphics', 'Tilesets', System.tileset.tileset_name
end

def bind
@tileset_tex.bind
end

def dispose
@tileset_tex.delete
end
end
Loading

0 comments on commit fbe45e6

Please sign in to comment.