bestguigui_lab 0.11.0 → 0.12.0

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: bfea52cbbec246d0b78adb34f4ede81f0cd5316276fc53d2cf84ddd857222d8c
4
- data.tar.gz: c839294b885dcf881638371fbe529bfcf9603c62ed31190380e86ef23210e0e6
3
+ metadata.gz: 232fd8759bb525cb0e243e8fa4eccfb4fa94dc9b4a0f6fb7ce73a003f52d505d
4
+ data.tar.gz: 666da34d4cea8a5f3d2efec9564e6d610854a249ffd9bf484d3b1a41dce7cc3a
5
5
  SHA512:
6
- metadata.gz: 61c72285fb0e23ab24622812f98340501af9c46c8123230d444a36b6d1ae42503697c8c33519cf906254c15047ec5ad5f5f09bbe25853a26e625499ca1e669f8
7
- data.tar.gz: 0c61253a25f9e9d6b9cf91d46ad19bb1c6c095cd0d7847e396a9c18db25a1a4ce20a8d3f25e00ea76e924b5e26a802788a952af9e0fffa4cc0c2d827e04793a8
6
+ metadata.gz: 8950ebdc674b3141c96dd79872f55af0ac520c1e2bfc13270cffd887b337d7dc36c6890b7a28c86f6136bddd8c28aad565d274ef7830e97e2747e427e22c7752
7
+ data.tar.gz: '039120dc1ae9996040c279190835707d89ebdf935b7ffd6efc4cd5323b4ed0a2dd80f2e4b2796f2ee0c6ae4a517ea6ec6a1f349c77a820204e99d0ba1da02d8a'
@@ -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
@@ -18,6 +18,21 @@ module Bestguigui
18
18
  gluLookAt(*eye, *center, *up_vector)
19
19
  end
20
20
 
21
+ # Sol plat rapide (aucune texture) pour se repérer dans une scène en
22
+ # cours de préparation : un carré de size*2 de côté centré à l'origine.
23
+ def draw_ground(size: 50.0, color: Gosu::Color::FUCHSIA)
24
+ glColor4ub(color.red, color.green, color.blue, color.alpha)
25
+
26
+ glBegin(GL_QUADS)
27
+ glVertex3f(-size, 0, -size)
28
+ glVertex3f(-size, 0, size)
29
+ glVertex3f(size, 0, size)
30
+ glVertex3f(size, 0, -size)
31
+ glEnd
32
+
33
+ glColor4ub(255, 255, 255, 255) # remet le blanc : ObjModel module sa texture avec la couleur courante
34
+ end
35
+
21
36
  private
22
37
 
23
38
  # Gosu.gl isole déjà l'état (glPushAttrib/glPopAttrib) et remet sa
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bestguigui
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.0'
5
5
  end
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.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bestguigui