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 +4 -4
- data/lib/bestguigui_lab/gl_texture.rb +18 -8
- data/lib/bestguigui_lab/obj_model.rb +1 -0
- data/lib/bestguigui_lab/render_3d.rb +15 -0
- data/lib/bestguigui_lab/version.rb +1 -1
- 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: 232fd8759bb525cb0e243e8fa4eccfb4fa94dc9b4a0f6fb7ce73a003f52d505d
|
|
4
|
+
data.tar.gz: 666da34d4cea8a5f3d2efec9564e6d610854a249ffd9bf484d3b1a41dce7cc3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
|
@@ -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
|