# Newlisp GLU context (the GL Utility). # # This file contains GLU constants and C-enumerations. # Created for GLU 1.3. # # Version 1.0 -Initial release (nov 13, 2004) # Version 1.01 -Some entrys are not found on Win32, commented (oct 13, 2005) # -Corrected Win32 library name (oct 13, 2005) # Version 1.02 -Re-implemented gluLookAt (nov 18, 2005) # Version 1.03 -Adapted for newLisp10 (jan 1, 2009) # #------------------------------------------------------------------ (context 'GLU) # Determine which library to use first. (if (= ostype "Win32") (begin (constant 'GLU_LIB "glu32.dll") (constant 'GL_LIB "opengl32.dll") ) (= ostype "OSX") (begin (constant 'GLU_LIB "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib")(constant 'GL_LIB "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib") ) (= ostype "Linux") (begin (constant 'GLU_LIB "libGLU.so") (constant 'GL_LIB "libGL.so") ) ) # glu.h (constant 'GLU_EXT_object_space_tess 1) (constant 'GLU_EXT_nurbs_tessellator 1) (constant 'GLU_FALSE 0) (constant 'GLU_TRUE 1) (constant 'GLU_VERSION_1_1 1) (constant 'GLU_VERSION_1_2 1) (constant 'GLU_VERSION_1_3 1) (constant 'GLU_VERSION 100800) (constant 'GLU_EXTENSIONS 100801) (constant 'GLU_INVALID_ENUM 100900) (constant 'GLU_INVALID_VALUE 100901) (constant 'GLU_OUT_OF_MEMORY 100902) (constant 'GLU_INVALID_OPERATION 100904) (constant 'GLU_OUTLINE_POLYGON 100240) (constant 'GLU_OUTLINE_PATCH 100241) (constant 'GLU_NURBS_ERROR 100103) (constant 'GLU_ERROR 100103) (constant 'GLU_NURBS_BEGIN 100164) (constant 'GLU_NURBS_BEGIN_EXT 100164) (constant 'GLU_NURBS_VERTEX 100165) (constant 'GLU_NURBS_VERTEX_EXT 100165) (constant 'GLU_NURBS_NORMAL 100166) (constant 'GLU_NURBS_NORMAL_EXT 100166) (constant 'GLU_NURBS_COLOR 100167) (constant 'GLU_NURBS_COLOR_EXT 100167) (constant 'GLU_NURBS_TEXTURE_COORD 100168) (constant 'GLU_NURBS_TEX_COORD_EXT 100168) (constant 'GLU_NURBS_END 100169) (constant 'GLU_NURBS_END_EXT 100169) (constant 'GLU_NURBS_BEGIN_DATA 100170) (constant 'GLU_NURBS_BEGIN_DATA_EXT 100170) (constant 'GLU_NURBS_VERTEX_DATA 100171) (constant 'GLU_NURBS_VERTEX_DATA_EXT 100171) (constant 'GLU_NURBS_NORMAL_DATA 100172) (constant 'GLU_NURBS_NORMAL_DATA_EXT 100172) (constant 'GLU_NURBS_COLOR_DATA 100173) (constant 'GLU_NURBS_COLOR_DATA_EXT 100173) (constant 'GLU_NURBS_TEXTURE_COORD_DATA 100174) (constant 'GLU_NURBS_TEX_COORD_DATA_EXT 100174) (constant 'GLU_NURBS_END_DATA 100175) (constant 'GLU_NURBS_END_DATA_EXT 100175) (constant 'GLU_NURBS_ERROR1 100251) (constant 'GLU_NURBS_ERROR2 100252) (constant 'GLU_NURBS_ERROR3 100253) (constant 'GLU_NURBS_ERROR4 100254) (constant 'GLU_NURBS_ERROR5 100255) (constant 'GLU_NURBS_ERROR6 100256) (constant 'GLU_NURBS_ERROR7 100257) (constant 'GLU_NURBS_ERROR8 100258) (constant 'GLU_NURBS_ERROR9 100259) (constant 'GLU_NURBS_ERROR10 100260) (constant 'GLU_NURBS_ERROR11 100261) (constant 'GLU_NURBS_ERROR12 100262) (constant 'GLU_NURBS_ERROR13 100263) (constant 'GLU_NURBS_ERROR14 100264) (constant 'GLU_NURBS_ERROR15 100265) (constant 'GLU_NURBS_ERROR16 100266) (constant 'GLU_NURBS_ERROR17 100267) (constant 'GLU_NURBS_ERROR18 100268) (constant 'GLU_NURBS_ERROR19 100269) (constant 'GLU_NURBS_ERROR20 100270) (constant 'GLU_NURBS_ERROR21 100271) (constant 'GLU_NURBS_ERROR22 100272) (constant 'GLU_NURBS_ERROR23 100273) (constant 'GLU_NURBS_ERROR24 100274) (constant 'GLU_NURBS_ERROR25 100275) (constant 'GLU_NURBS_ERROR26 100276) (constant 'GLU_NURBS_ERROR27 100277) (constant 'GLU_NURBS_ERROR28 100278) (constant 'GLU_NURBS_ERROR29 100279) (constant 'GLU_NURBS_ERROR30 100280) (constant 'GLU_NURBS_ERROR31 100281) (constant 'GLU_NURBS_ERROR32 100282) (constant 'GLU_NURBS_ERROR33 100283) (constant 'GLU_NURBS_ERROR34 100284) (constant 'GLU_NURBS_ERROR35 100285) (constant 'GLU_NURBS_ERROR36 100286) (constant 'GLU_NURBS_ERROR37 100287) (constant 'GLU_AUTO_LOAD_MATRIX 100200) (constant 'GLU_CULLING 100201) (constant 'GLU_SAMPLING_TOLERANCE 100203) (constant 'GLU_DISPLAY_MODE 100204) (constant 'GLU_PARAMETRIC_TOLERANCE 100202) (constant 'GLU_SAMPLING_METHOD 100205) (constant 'GLU_U_STEP 100206) (constant 'GLU_V_STEP 100207) (constant 'GLU_NURBS_MODE 100160) (constant 'GLU_NURBS_MODE_EXT 100160) (constant 'GLU_NURBS_TESSELLATOR 100161) (constant 'GLU_NURBS_TESSELLATOR_EXT 100161) (constant 'GLU_NURBS_RENDERER 100162) (constant 'GLU_NURBS_RENDERER_EXT 100162) (constant 'GLU_OBJECT_PARAMETRIC_ERROR 100208) (constant 'GLU_OBJECT_PARAMETRIC_ERROR_EXT 100208) (constant 'GLU_OBJECT_PATH_LENGTH 100209) (constant 'GLU_OBJECT_PATH_LENGTH_EXT 100209) (constant 'GLU_PATH_LENGTH 100215) (constant 'GLU_PARAMETRIC_ERROR 100216) (constant 'GLU_DOMAIN_DISTANCE 100217) (constant 'GLU_MAP1_TRIM_2 100210) (constant 'GLU_MAP1_TRIM_3 100211) (constant 'GLU_POINT 100010) (constant 'GLU_LINE 100011) (constant 'GLU_FILL 100012) (constant 'GLU_SILHOUETTE 100013) (constant 'GLU_SMOOTH 100000) (constant 'GLU_FLAT 100001) (constant 'GLU_NONE 100002) (constant 'GLU_OUTSIDE 100020) (constant 'GLU_INSIDE 100021) (constant 'GLU_TESS_BEGIN 100100) (constant 'GLU_BEGIN 100100) (constant 'GLU_TESS_VERTEX 100101) (constant 'GLU_VERTEX 100101) (constant 'GLU_TESS_END 100102) (constant 'GLU_END 100102) (constant 'GLU_TESS_ERROR 100103) (constant 'GLU_TESS_EDGE_FLAG 100104) (constant 'GLU_EDGE_FLAG 100104) (constant 'GLU_TESS_COMBINE 100105) (constant 'GLU_TESS_BEGIN_DATA 100106) (constant 'GLU_TESS_VERTEX_DATA 100107) (constant 'GLU_TESS_END_DATA 100108) (constant 'GLU_TESS_ERROR_DATA 100109) (constant 'GLU_TESS_EDGE_FLAG_DATA 100110) (constant 'GLU_TESS_COMBINE_DATA 100111) (constant 'GLU_CW 100120) (constant 'GLU_CCW 100121) (constant 'GLU_INTERIOR 100122) (constant 'GLU_EXTERIOR 100123) (constant 'GLU_UNKNOWN 100124) (constant 'GLU_TESS_WINDING_RULE 100140) (constant 'GLU_TESS_BOUNDARY_ONLY 100141) (constant 'GLU_TESS_TOLERANCE 100142) (constant 'GLU_TESS_ERROR1 100151) (constant 'GLU_TESS_ERROR2 100152) (constant 'GLU_TESS_ERROR3 100153) (constant 'GLU_TESS_ERROR4 100154) (constant 'GLU_TESS_ERROR5 100155) (constant 'GLU_TESS_ERROR6 100156) (constant 'GLU_TESS_ERROR7 100157) (constant 'GLU_TESS_ERROR8 100158) (constant 'GLU_TESS_MISSING_BEGIN_POLYGON 100151) (constant 'GLU_TESS_MISSING_BEGIN_CONTOUR 100152) (constant 'GLU_TESS_MISSING_END_POLYGON 100153) (constant 'GLU_TESS_MISSING_END_CONTOUR 100154) (constant 'GLU_TESS_COORD_TOO_LARGE 100155) (constant 'GLU_TESS_NEED_COMBINE_CALLBACK 100156) (constant 'GLU_TESS_WINDING_ODD 100130) (constant 'GLU_TESS_WINDING_NONZERO 100131) (constant 'GLU_TESS_WINDING_POSITIVE 100132) (constant 'GLU_TESS_WINDING_NEGATIVE 100133) (constant 'GLU_TESS_WINDING_ABS_GEQ_TWO 100134) (constant 'GLU_TESS_MAX_COORD 1.0e150) # glu.h (import GLU_LIB "gluBeginCurve") (import GLU_LIB "gluBeginPolygon") (import GLU_LIB "gluBeginSurface") (import GLU_LIB "gluBeginTrim") # (import GLU_LIB "gluBuild1DMipmapLevels") <--- Not found on Win32 (import GLU_LIB "gluBuild1DMipmaps") # (import GLU_LIB "gluBuild2DMipmapLevels") <--- Not found on Win32 (import GLU_LIB "gluBuild2DMipmaps") # (import GLU_LIB "gluBuild3DMipmapLevels") <--- Not found on Win32 # (import GLU_LIB "gluBuild3DMipmaps") <--- Not found on Win32 # (import GLU_LIB "gluCheckExtension") <--- Not found on Win32 (import GLU_LIB "gluCylinder") (import GLU_LIB "gluDeleteNurbsRenderer") (import GLU_LIB "gluDeleteQuadric") (import GLU_LIB "gluDeleteTess") (import GLU_LIB "gluDisk") (import GLU_LIB "gluEndCurve") (import GLU_LIB "gluEndPolygon") (import GLU_LIB "gluEndSurface") (import GLU_LIB "gluEndTrim") (import GLU_LIB "gluErrorString") (import GLU_LIB "gluGetNurbsProperty") (import GLU_LIB "gluGetString") (import GLU_LIB "gluGetTessProperty") (import GLU_LIB "gluLoadSamplingMatrices") # (import GLU_LIB "gluLookAt") <--- buggy implemented, workaround below (import GLU_LIB "gluNewNurbsRenderer") (import GLU_LIB "gluNewQuadric") (import GLU_LIB "gluNewTess") (import GLU_LIB "gluNextContour") (import GLU_LIB "gluNurbsCallback") # (import GLU_LIB "gluNurbsCallbackData") <--- Not found on Win32 # (import GLU_LIB "gluNurbsCallbackDataEXT") <--- Not found on Win32 (import GLU_LIB "gluNurbsCurve") (import GLU_LIB "gluNurbsProperty") (import GLU_LIB "gluNurbsSurface") (import GLU_LIB "gluOrtho2D") (import GLU_LIB "gluPartialDisk") (import GLU_LIB "gluPerspective") (import GLU_LIB "gluPickMatrix") (import GLU_LIB "gluProject") (import GLU_LIB "gluPwlCurve") (import GLU_LIB "gluQuadricCallback") (import GLU_LIB "gluQuadricDrawStyle") (import GLU_LIB "gluQuadricNormals") (import GLU_LIB "gluQuadricOrientation") (import GLU_LIB "gluQuadricTexture") (import GLU_LIB "gluScaleImage") (import GLU_LIB "gluSphere") (import GLU_LIB "gluTessBeginContour") (import GLU_LIB "gluTessBeginPolygon") (import GLU_LIB "gluTessCallback") (import GLU_LIB "gluTessEndContour") (import GLU_LIB "gluTessEndPolygon") (import GLU_LIB "gluTessNormal") (import GLU_LIB "gluTessProperty") (import GLU_LIB "gluTessVertex") (import GLU_LIB "gluUnProject") # (import GLU_LIB "gluUnProject4") <--- Not found on Win32 #-------------------------------------------------------------------------- # # Below, a re-implementation of the GLU function 'gluLookAt' follows. # # In the original GLU C-code floats and doubles are mixed up without # any casting, therefore newLisp calls to this function do not work. # #-------------------------------------------------------------------------- (import GL_LIB "glMultMatrixf") (import GL_LIB "glTranslated") (define (normalize v) (set 'r (sqrt (add (mul (v 0) (v 0)) (mul (v 1) (v 1)) (mul (v 2) (v 2)) ))) (when (!= r 0.0) (setf (v 0) (div (v 0) r)) (setf (v 1) (div (v 1) r)) (setf (v 2) (div (v 2) r)) v ) ) (define (cross v1 v2) (set 'result (array 3)) (setf (result 0) (sub (mul (nth 1 v1) (nth 2 v2)) (mul (nth 2 v1) (nth 1 v2))) ) (setf (result 1) (sub (mul (nth 2 v1) (nth 0 v2)) (mul (nth 0 v1) (nth 2 v2))) ) (setf (result 2) (sub (mul (nth 0 v1) (nth 1 v2)) (mul (nth 1 v1) (nth 0 v2))) ) result ) (define (__gluMakeIdentityd) (set 'm0 1.0) (set 'm4 0.0) (set 'm8 0.0) (set 'm12 0.0) (set 'm1 0.0) (set 'm5 1.0) (set 'm9 0.0) (set 'm13 0.0) (set 'm2 0.0) (set 'm6 0.0) (set 'm10 1.0) (set 'm14 0.0) (set 'm3 0.0) (set 'm7 0.0) (set 'm11 0.0) (set 'm15 1.0) ) (define (gluLookAt eyex eyey eyez centerx centery centerz upx upy upz) (set 'forward (array 3)) (set 'side (array 3)) (set 'up (array 3)) (setf (forward 0) (sub centerx eyex)) (setf (forward 1) (sub centery eyey)) (setf (forward 2) (sub centerz eyez)) (setf (up 0) upx) (setf (up 1) upy) (setf (up 2) upz) (set 'forward (normalize forward)) # Side = forward x up (set 'side (cross forward up)) (set 'side (normalize side)) # Recompute up as: up = side x forward (set 'up (cross side forward)) (__gluMakeIdentityd) (set 'm0 (side 0)) (set 'm1 (side 1)) (set 'm2 (side 2)) (set 'm4 (up 0)) (set 'm5 (up 1)) (set 'm6 (up 2)) (set 'm8 (mul -1.0 (forward 0))) (set 'm9 (mul -1.0 (forward 1))) (set 'm10 (mul -1.0 (forward 2))) (set 'tmp (pack "ffffffffffffffff" m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15)) (glMultMatrixf (address tmp)) (glTranslated (mul -1 eyex)(mul -1 eyey)(mul -1 eyez)) ) #-------------------------------------------------------------------------- (context 'MAIN)