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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 794326e97286d25be2eee9a66e661f554bba438bca9e595a93b76a74e54031c1
4
- data.tar.gz: b5544628293217d602f842f3f0151622f7b16ef9a9cfab0b25eed29954d3ca06
3
+ metadata.gz: 4f0acffb5e7c403045b16dae2a281058cfcc091897576667fcb5b8bad82eb9a7
4
+ data.tar.gz: 6e8eb4d084e2989dbb4287c2c00e5bab23d3991eda71a8c99af7f7071aab9d2e
5
5
  SHA512:
6
- metadata.gz: 192b71239f32d5f09ebe0bc993edde160aaeaf18bb0539a25e134bff220f5e2c24f0c165a7de4fb9baf351698e3888aa582ef8cf70a4a6775c7fc43794949615
7
- data.tar.gz: 3b8a34f3e8a72458d9d705ed4dadac63c779cc3faf5037b12710f3e54705905821275fe5fc0f243959943422a93d59b308a2e6775fa47339fe0dcb8288fbb10a
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
- def initialize(path)
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
- image = Gosu::Image.new(path, retro: true)
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 upload(image)
18
- name_buffer = "\x00" * 4
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, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
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
@@ -16,6 +16,7 @@ module Bestguigui
16
16
  @texture = nil
17
17
 
18
18
  parse_obj(obj_path)
19
+ @texture ||= GLTexture.blank
19
20
  @vertex_count = @faces.size
20
21
  @vbo = build_vertex_buffer
21
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bestguigui
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.1'
5
5
  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, fixe @scene
6
- # dans #initialize (et ajoute switch_scene si plusieurs écrans).
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bestguigui_lab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bestguigui