Jump to content

  • Log In with Google      Sign In   
  • Create Account


gforth OpenGL Interface Coding Example


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Timoteo2010   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 July 2010 - 02:11 PM

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

end-c-library

<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.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS