我如何用 OpenGL 在 Forth 中画一条线?

How do I draw a line in Forth with OpenGL?

在 Gforth OpenGL 教程中,我找到了一个代码片段,用于在 Forth 的图形屏幕上绘制三角形:

: DrawGLScene
  GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT OR gl-clear
  gl-load-identity
  -1.5e 0e -6e gl-translate-f
  GL_TRIANGLES gl-begin
      0e 2e 0e gl-vertex-3f
    -1e -1e 0e gl-vertex-3f
     1e -1e 0e gl-vertex-3f
  gl-end
  sdl-gl-swap-buffers
  fps-frames 1+ to fps-frames
  Display-FPS
  TRUE
;

如果我将其中一个坐标从“2e”更改为“1e”,生成的对象的形状将变得不同。但是我怎样才能画一条线而不是三角形呢?这也适用于 OpenGL 和 Gforth 吗?

您显示的代码片段使用的是过时的固定函数管道。我知道 Forth,但我不知道 OpenGL 绑定,所以我暂时使用 FFP。试试这个,它画了两条线:

: DrawGLScene
  GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT OR gl-clear
  gl-load-identity
  -1.5e 0e -6e gl-translate-f
  GL_LINES gl-begin
      0e 2e 0e gl-vertex-3f
    -1e -1e 0e gl-vertex-3f
      1e 2e 0e gl-vertex-3f
     0e -1e 0e gl-vertex-3f
  gl-end
  sdl-gl-swap-buffers
  fps-frames 1+ to fps-frames
  Display-FPS
  TRUE
;