• Advertisement
Sign in to follow this  

gforth OpenGL Interface Coding Example

This topic is 2821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is an example of how to interface the OpenGL libraries to gforth. The gforth libcc interface code parses and writes the lines between the c-library/end-c-library lines to the mini_opengl_lib.c file and then calls the gcc compiler. The resulting .o file is then linked to the gforth system, allowing access to the OpenGL functions that have been defined.

Lines preceded by \c are copied verbatim to the mini_opengl_lib.c file.

c-library mini_opengl_lib

s" GL" add-lib
s" GLU" add-lib

\c #if defined(__APPLE__) && defined(__MACH__)
\c #include <OpenGL/gl.h>
\c #include <OpenGL/glu.h>
\c #else
\c #include <GL/gl.h>
\c #include <GL/glu.h>
\c #endif

c-function gl-clear glClear n -- void
c-function gl-clear-color glClearColor r r r r -- void
c-function gl-clear-depth glClearDepth r -- void
c-function gl-enable glEnable n -- void
c-function gl-depth-func glDepthFunc n -- void
c-function gl-hint glHint n n -- void
c-function gl-load-identity glLoadIdentity -- void
c-function gl-matrix-mode glMatrixMode n -- void
c-function gl-shade-model glShadeModel n -- void
c-function gl-viewport glViewport n n n n -- void
c-function glu-perspective gluPerspective r r r r -- void


<n> indicates a 32-bit integer value is passed.
<r> indicates a floating point value is passed.
<void> indicates there is no return value from this function call.

In the first c-function line, gl-clear is the name of the function that is created in the gforth dictionary, while glClear is the actual OpenGL library function accessed.

This gives gforth a portable cross-platform OpenGL implementation capability.

A similar interface is used for the SDL library functions.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement