OpenGL Library

PreviousNext

Functions and Constants

Functions

All OpenGL and GLU functions are wrapped by EWG. Thus to access the functions you have to inherit from the appropriate wrapper class. To access OpenGL functions inherit from GL_FUNCTIONS, to access GLU functions inherit from GLU_FUNCTIONS. This will provide you with gl_* and glu_* functions which correspond exactly to their counterparts.

Constants

To access OpenGL constants you can use EM_GL_CONSTANTS, EM_GLU_CONSTANTS or EM_CONSTANTS which inherits from the other two. All names have an additional Em_ prefix to their original OpenGL name.

Pointer Use

Some OpenGL functions depend on pointers as arguments to set and return data, most times arrays. Thus you have to provide a pointer to the array data of Eiffel arrays. To get such a pointer you can use the following code:

_   local
_   _   array: ARRAY [REAL]
_   _   pointer: POINTER
_   _   temp: ANY
_   do
_   _   create array.make (0, 2)
_   _   temp := array.to_c
_   _   pointer := $tmp
_   _   -- Now use `pointer' to pass to OpenGL functions
_   _   gl_vertex3fv (pointer)
	

Now you can use pointer as a pointer to the array which is here a 3-dimensional vector of reals, for example to pass as a vertex.

Because this is tedious it is easier to not use pointer functions but use OpenGL functions which take the single vector elements as arguments, like gl_vertex3f instead of gl_vertex3fv. But in some cases such functions don't exist and you have to use the workaround presented here.

Note: Never create a once pointer (class POINTER) for an Eiffel array since the garbage collector can change the location of the array but will not change the value of a once pointer.