This repository has been archived by the owner on Aug 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lily
committed
Aug 25, 2022
1 parent
b5eddf8
commit fbe45e6
Showing
17 changed files
with
357 additions
and
211 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.