How do I draw a line in Forth with OpenGL?

Viewed 782

In the Gforth OpenGL tutorial I've found a codesnippet for drawing a triangle to the graphics-screen in 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
;

If I change one of the coordinates for example from “2e” to “1e”, the shape of the resulting object will become different. But how can I draw a single line, instead of triangle? Is this possible with OpenGL and Gforth too?

1 Answers

The code snippet you're showing is using the old-and-busted Fixed Function Pipeline. I know Forth, but I don't know the OpenGL bindings, so I let's stick with the FFP for the moment. Try this, which draws two lines:

: 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
;
Related