#!/usr/bin/newlisp # # Copyright (c) Mark J. Kilgard, 1994. # This program is freely distributable without licensing fees # and is provided without guarantee or warrantee expressed or # implied. This program is -not- in the public domain. # blender renders two spinning icosahedrons (red and green). # The blending factors for the two icosahedrons vary sinusoidally # and slightly out of phase. blender also renders two lines of # text in a stroke font: one line antialiased, the other not. #------------------------------------------------------------------- # Ported to newLisp by Peter van Eerten. # # This is a 1-to-1 port of the original program. # November 18, 2005. # Adapted for newLisp 10, january 6 2009 - PvE. #------------------------------------------------------------------- (load "GL.lsp" "GLU.lsp" "freeglut.lsp") (set 'light0_ambient (pack "ffff" 0.2 0.2 0.2 1.0)) (set 'light0_diffuse (pack "ffff" 0.0 0.0 0.0 1.0)) (set 'light1_diffuse (pack "ffff" 1.0 0.0 0.0 1.0)) (set 'light1_position (pack "ffff" 1.0 1.0 1.0 0.0)) (set 'light2_diffuse (pack "ffff" 0.0 1.0 0.0 1.0)) (set 'light2_position (pack "ffff" -1.0 -1.0 1.0 0.0)) (set 's 0.0) (set 'angle1 0.0) (set 'angle2 0.0) (define (output x y text) (GL:glPushMatrix) (GL:glTranslatef (flt x) (flt y) (flt 0)) (for (p 0 (- (length text) 1)) (GLUT:glutStrokeCharacter GLUT:GLUT_STROKE_ROMAN (char (nth p text)) )) (GL:glPopMatrix) ) (define (display) (GL:glClear (| GL:GL_COLOR_BUFFER_BIT GL:GL_DEPTH_BUFFER_BIT)) (GL:glEnable GL:GL_LIGHT1) (GL:glDisable GL:GL_LIGHT2) (set '_amb (pack "ffff" 0.4 0.4 0.4 (add (div (cos s) 2.0) 0.5))) (set 'dif (pack "ffff" 1.0 1.0 1.0 (add (div (cos s) 2.0) 0.5))) (GL:glMaterialfv GL:GL_FRONT GL:GL_AMBIENT _amb) (GL:glMaterialfv GL:GL_FRONT GL:GL_DIFFUSE dif) (GL:glPushMatrix) (GL:glTranslatef (flt -0.3) (flt -0.3) (flt 0.0)) (GL:glRotatef (flt angle1) (flt 1.0) (flt 5.0) (flt 0.0)) (GL:glCallList 1) # render ico display list (GL:glPopMatrix) (GL:glClear GL:GL_DEPTH_BUFFER_BIT) (GL:glEnable GL:GL_LIGHT2) (GL:glDisable GL:GL_LIGHT1) (set '_amb (pack "ffff" 0.4 0.4 0.4 (sub 0.5 (div (cos (mul s 0.95)) 2.0)) )) (set 'dif (pack "ffff" 1.0 1.0 1.0 (sub 0.5 (div (cos (mul s 0.95)) 2.0)) )) (GL:glMaterialfv GL:GL_FRONT GL:GL_AMBIENT _amb) (GL:glMaterialfv GL:GL_FRONT GL:GL_DIFFUSE dif) (GL:glPushMatrix) (GL:glTranslatef (flt 0.3) (flt 0.3) (flt 0.0)) (GL:glRotatef (flt angle2) (flt 1.0) (flt 0.0) (flt 5.0)) (GL:glCallList 1) # render ico display list (GL:glPopMatrix) (GL:glPushAttrib GL:GL_ENABLE_BIT) (GL:glDisable GL:GL_DEPTH_TEST) (GL:glDisable GL:GL_LIGHTING) (GL:glMatrixMode GL:GL_PROJECTION) (GL:glPushMatrix) (GL:glLoadIdentity) (GLU:gluOrtho2D 0.0 1500.0 0.0 1500.0) (GL:glMatrixMode GL:GL_MODELVIEW) (GL:glPushMatrix) (GL:glLoadIdentity) # Rotate text slightly to help show jaggies. (GL:glRotatef (flt 4) (flt 0.0) (flt 0.0) (flt 1.0)) (output 200 225 "This is antialiased.") (GL:glDisable GL:GL_LINE_SMOOTH) (GL:glDisable GL:GL_BLEND) (output 160 100 "This text is not.") (GL:glPopMatrix) (GL:glMatrixMode GL:GL_PROJECTION) (GL:glPopMatrix) (GL:glPopAttrib) (GL:glMatrixMode GL:GL_MODELVIEW) (GLUT:glutSwapBuffers) ) (define (idle) (set 'angle1 (mod (add angle1 0.8) 360.0)) (set 'angle2 (mod (add angle2 1.1) 360.0)) (set 's (add s 0.05)) (sleep 1) (GLUT:glutPostRedisplay) ) (define (visible vis) (if (= vis GLUT:GLUT_VISIBLE) (GLUT:glutIdleFunc 'idle) (GLUT:glutIdleFunc 'NULL) ) ) (define (main argc argv) (GLUT:glutInit (address argc) (address argv)) (GLUT:glutInitDisplayMode (| GLUT:GLUT_DOUBLE GLUT:GLUT_RGB GLUT:GLUT_DEPTH)) (GLUT:glutCreateWindow "blender") (GLUT:glutDisplayFunc 'display) (GLUT:glutVisibilityFunc 'visible) (GL:glNewList 1 GL:GL_COMPILE) # create ico display list (GLUT:glutSolidIcosahedron) (GL:glEndList) (GL:glEnable GL:GL_LIGHTING) (GL:glEnable GL:GL_LIGHT0) (GL:glLightfv GL:GL_LIGHT0 GL:GL_AMBIENT light0_ambient) (GL:glLightfv GL:GL_LIGHT0 GL:GL_DIFFUSE light0_diffuse) (GL:glLightfv GL:GL_LIGHT1 GL:GL_DIFFUSE light1_diffuse) (GL:glLightfv GL:GL_LIGHT1 GL:GL_POSITION light1_position) (GL:glLightfv GL:GL_LIGHT2 GL:GL_DIFFUSE light2_diffuse) (GL:glLightfv GL:GL_LIGHT2 GL:GL_POSITION light2_position) (GL:glEnable GL:GL_DEPTH_TEST) (GL:glEnable GL:GL_CULL_FACE) (GL:glEnable GL:GL_BLEND) (GL:glBlendFunc GL:GL_SRC_ALPHA GL:GL_ONE_MINUS_SRC_ALPHA) (GL:glEnable GL:GL_LINE_SMOOTH) (GL:glLineWidth (flt 2.0)) (GL:glMatrixMode GL:GL_PROJECTION) (GLU:gluPerspective 40.0 # field of view in degree 1.0 # aspect ratio 1.0 # Z near 10.0 # Z far ) (GL:glMatrixMode GL:GL_MODELVIEW) (GLU:gluLookAt 0.0 0.0 5.0 # eye is at (0,0,5) 0.0 0.0 0.0 # center is at (0,0,0) 0.0 1.0 0.0 # up is in positive Y direction ) (GL:glTranslatef (flt 0.0) (flt 0.6) (flt -1.0)) (GLUT:glutMainLoop) ) (main 0 0) (exit)