Commit 84c4dabe75a95fb2d23f30953a88a3a327763b4a

Thomas de Grivel 2022-02-24T19:12:31

bitmap fonts

diff --git a/README.md b/README.md
index 8eeafd2..fa3ba26 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,24 @@
 # Exterm
 
+## Screenshots
+### 2022-02
+![Exterm01](https://git.kmx.io/thodg/exterm/_blob/master/exterm01.png)
 ![Exterm](https://git.kmx.io/thodg/exterm/_blob/master/exterm.png)
 
-![Exterm01](https://git.kmx.io/thodg/exterm/_blob/master/exterm01.png)
+## TODO
+ - TTF
+   - Courier New failed glyphs :
+     - space (32)
+     - 2
+     - 6
+     - C
+     - G
+     - S
+     - g
+ - Shell
+   - environment
+   - path
+   - builtins
+   - exec
+ - Terminal control sequences
+   - xterm-256color
diff --git a/lib/exterm.ex b/lib/exterm.ex
index 7444b0f..402409b 100644
--- a/lib/exterm.ex
+++ b/lib/exterm.ex
@@ -135,28 +135,27 @@ defmodule Exterm do
     :gl.viewport(0, 0, width, height)
     :gl.matrixMode(:gl_const.gl_projection)
     :gl.loadIdentity()
-    :gl.ortho(0.0, width + 0.0, 0.0, height + 0.0, -1.0, 1.0)
+    :gl.ortho(0.0, width + 0.0, 0.0, height + 0.0, -1000.0, 1000.0)
     :gl.matrixMode(:gl_const.gl_modelview)
     :gl.loadIdentity()
     :ok
   end
 
   defp draw(font, lines) do
-    IO.inspect(:draw)
+    wrapped = lines |> wrap(80, 25)
+    lists = wrapped
+    |> Enum.map(fn line ->
+      Enum.map(line, fn c ->
+        Exterm.Font.load_glyph(font.regular, c)
+      end)
+    end)
+    :gl.clearColor(0.0, 0.0, 0.0, 0.0)
     :gl.clear(:gl_const.gl_color_buffer_bit)
-    :gl.loadIdentity()
-    lines
-    |> wrap(80, 25)
+    lists
     |> Enum.with_index()
     |> Enum.each(fn {line, i} ->
-      :gl.pushMatrix()
-      line
-      |> Enum.map(fn c ->
-        Exterm.Font.load_glyph(font.regular, c)
-      end)
-      |> :gl.callLists()
-      :gl.popMatrix()
-      :gl.translatef(0.0, 35.0, 0.0)
+      :gl.rasterPos2f(0.0, i * 32.0 + 64.0)
+      :gl.callLists(line)
     end)
   end
 
diff --git a/lib/exterm/font.ex b/lib/exterm/font.ex
index d36fb6d..5bab960 100644
--- a/lib/exterm/font.ex
+++ b/lib/exterm/font.ex
@@ -30,8 +30,17 @@ defmodule Exterm.Font do
     if :gl.isList(id) == :gl_const.gl_true do
       id
     else
-      :ok = :gl.newList(id, :gl_const.gl_compile)
+      :gl.clearColor(1.0, 1.0, 1.0, 0.0)
+      :gl.color4f(0.0, 0.0, 0.0, 1.0)
+      :gl.clear(:gl_const.gl_color_buffer_bit)
       :ok = render_glyph(font, codepoint)
+      w = 24
+      h = 32
+      size = w * h * 8
+      :ok = :gl.readPixels(0, 0, w, h, :gl_const.gl_red, :gl_const.gl_unsigned_byte, pixels = <<0::integer-size(size)>>)
+      :ok = :gl.newList(id, :gl_const.gl_compile)
+      :ok = :gl.drawPixels(w, h, :gl_const.gl_luminance, :gl_const.gl_unsigned_byte, pixels)
+      :ok = :gl.bitmap(0, 0, 0.0, 0.0, 18.0, 0.0, <<0>>)
       :ok = :gl.endList()
       id
     end
@@ -55,11 +64,10 @@ defmodule Exterm.Font do
     ttf = ttf(font.family)
     if glyph = TTF.glyph(ttf, codepoint) do
       :gl.pushMatrix()
-      :gl.translatef(0.0, 70.0, 0.0)
-      :gl.scalef(0.015, 0.015, 0.015)
+      :gl.translatef(3.0, 9.0, 0.0)
+      :gl.scalef(0.014, 0.014, 0.0)
       Enum.each(glyph.contours, fn contour ->
         :gl.begin(:gl_const.gl_line_loop)
-        :gl.color3f(0.0, 0.0, 0.0)
         Enum.each(TTF.Glyph.contour_segments(contour), fn control_point ->
           :gl.vertex2f(control_point.a.x + 0.0, control_point.a.y + 0.0)
           :gl.vertex2f(control_point.c.x + 0.0, control_point.c.y + 0.0)
@@ -67,7 +75,6 @@ defmodule Exterm.Font do
         :gl.end()
       end)
       :gl.popMatrix()
-      :gl.translatef(16.0, 0.0, 0.0)
     end
   end
 
diff --git a/src/gl_const.erl b/src/gl_const.erl
index 130d093..199b2f1 100644
--- a/src/gl_const.erl
+++ b/src/gl_const.erl
@@ -3,6 +3,7 @@
 
 -include_lib("wx/include/gl.hrl").
 
+gl_alpha() -> ?GL_ALPHA.
 gl_color_buffer_bit() -> ?GL_COLOR_BUFFER_BIT.
 gl_compile() -> ?GL_COMPILE.
 gl_compile_and_execute() -> ?GL_COMPILE_AND_EXECUTE.
@@ -11,11 +12,16 @@ gl_depth_test() -> ?GL_DEPTH_TEST.
 gl_lequal() -> ?GL_LEQUAL.
 gl_line_loop() -> ?GL_LINE_LOOP.
 gl_line_strip() -> ?GL_LINE_STRIP.
+gl_luminance() -> ?GL_LUMINANCE.
 gl_modelview() -> ?GL_MODELVIEW.
 gl_nicest() -> ?GL_NICEST.
 gl_perspective_correction_hint() -> ?GL_PERSPECTIVE_CORRECTION_HINT.
 gl_projection() -> ?GL_PROJECTION.
 gl_quad_strip() -> ?GL_QUAD_STRIP.
+gl_red() -> ?GL_RED.
 gl_smooth() -> ?GL_SMOOTH.
 gl_triangles() -> ?GL_TRIANGLES.
 gl_true() -> ?GL_TRUE.
+gl_unpack_image_height() -> ?GL_UNPACK_IMAGE_HEIGHT.
+gl_unpack_row_length() -> ?GL_UNPACK_ROW_LENGTH.
+gl_unsigned_byte() -> ?GL_UNSIGNED_BYTE.