bestguigui_lab 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bestguigui_lab/gl_texture.rb +18 -8
- data/lib/bestguigui_lab/obj_model.rb +1 -0
- data/lib/bestguigui_lab/version.rb +1 -1
- data/lib/bestguigui_lab/window.rb +20 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f0acffb5e7c403045b16dae2a281058cfcc091897576667fcb5b8bad82eb9a7
|
|
4
|
+
data.tar.gz: 6e8eb4d084e2989dbb4287c2c00e5bab23d3991eda71a8c99af7f7071aab9d2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0dc2145307122a75f4c3c8a47693f0fe973d074f7db344a45324f3ffd7c75258f5b30c92e37d6285504937339ecfe795f7c82eac95580ec6e6596d23e8a93272
|
|
7
|
+
data.tar.gz: 9705572b39ce73084543c616f27caa45b340719cf5b2e659b54735852f92bb1d2e7d0818bc37439d07b892ac21ac7ece978ea42b3d43685dd94b16eba2340576
|
|
@@ -6,28 +6,38 @@ module Bestguigui
|
|
|
6
6
|
class GLTexture
|
|
7
7
|
attr_reader :tex_name
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
# path: nil construit une texture blanche 1x1 (repli pour un modèle
|
|
10
|
+
# sans map_Kd dans son .mtl) — voir GLTexture.blank.
|
|
11
|
+
def initialize(path = nil)
|
|
10
12
|
super()
|
|
11
|
-
|
|
12
|
-
@tex_name = upload(image)
|
|
13
|
+
@tex_name = path ? upload_image(path) : upload_blank
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
def self.blank = new
|
|
17
|
+
|
|
15
18
|
private
|
|
16
19
|
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
glGenTextures(1, name_buffer)
|
|
20
|
-
tex_name = name_buffer.unpack1('L')
|
|
20
|
+
def upload_image(path)
|
|
21
|
+
image = Gosu::Image.new(path, retro: true)
|
|
21
22
|
|
|
22
23
|
# Garder les pixels dans une variable (pas `image.to_blob` inline
|
|
23
24
|
# en argument) : sinon Ruby peut libérer la String pendant
|
|
24
25
|
# l'appel FFI, avant qu'OpenGL l'ait lue (texture à zéro, sans
|
|
25
26
|
# erreur OpenGL).
|
|
26
27
|
pixels = image.to_blob
|
|
28
|
+
upload_pixels(image.width, image.height, pixels)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def upload_blank = upload_pixels(1, 1, "\xFF\xFF\xFF\xFF".b)
|
|
32
|
+
|
|
33
|
+
def upload_pixels(width, height, pixels)
|
|
34
|
+
name_buffer = "\x00" * 4
|
|
35
|
+
glGenTextures(1, name_buffer)
|
|
36
|
+
tex_name = name_buffer.unpack1('L')
|
|
27
37
|
|
|
28
38
|
glBindTexture(GL_TEXTURE_2D, tex_name)
|
|
29
39
|
configure_wrapping
|
|
30
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
|
40
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
|
|
31
41
|
|
|
32
42
|
tex_name
|
|
33
43
|
end
|
|
@@ -2,9 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
module Bestguigui
|
|
4
4
|
# Fenêtre de base qui calcule le delta-time et délègue update/draw/
|
|
5
|
-
# button_down à la scène courante (@scene). Hérite-en
|
|
6
|
-
#
|
|
5
|
+
# button_down à la scène courante (@scene). Hérite-en et implémente
|
|
6
|
+
# switch_scene(scene_type) pour construire tes scènes ; le constructeur
|
|
7
|
+
# se charge de lancer le splash screen du kit avant scene, sauf si
|
|
8
|
+
# splash_screen: false.
|
|
9
|
+
#
|
|
10
|
+
# Bestguigui::Window.new(640, 480, scene: :main, title: 'Mon jeu')
|
|
11
|
+
# Bestguigui::Window.new(640, 480, scene: :main, splash_screen: false)
|
|
7
12
|
class Window < Gosu::Window
|
|
13
|
+
def initialize(width, height, scene:, splash_screen: true, title: nil)
|
|
14
|
+
super(width, height)
|
|
15
|
+
if splash_screen
|
|
16
|
+
@scene = SplashScene.new(self, title: title, next_scene: scene)
|
|
17
|
+
else
|
|
18
|
+
switch_scene(scene)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def switch_scene(scene_type)
|
|
23
|
+
raise NotImplementedError, "implémente switch_scene(#{scene_type.inspect}) dans ta sous-classe"
|
|
24
|
+
end
|
|
25
|
+
|
|
8
26
|
def update
|
|
9
27
|
@last_update ||= Gosu.milliseconds
|
|
10
28
|
dt = Gosu.milliseconds - @last_update
|