home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / nehe8.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  6.1 KB  |  150 lines

  1.  
  2. dim light                 ' Lighting ON/OFF
  3. dim blend                 ' Blending OFF/ON? ( NEW )
  4.  
  5. dim xrot#                 ' X Rotation
  6. dim yrot#                 ' Y Rotation
  7. dim xspeed#               ' X Rotation Speed
  8. dim yspeed#               ' Y Rotation Speed
  9. dim z#: z#=-5             ' Depth Into The Screen
  10.  
  11. dim LightAmbient#(3):  LightAmbient#  = vec4 ( 0.5, 0.5, 0.5, 1.0 )
  12. dim LightDiffuse#(3):  LightDiffuse#  = vec4 ( 1.0, 1.0, 1.0, 1.0 )
  13. dim LightPosition#(3): LightPosition# = vec4 ( 0.0, 0.0, 2.0, 1.0 )
  14.  
  15. dim filter                ' Which Filter To Use
  16. dim texture(2)            ' Storage For 3 Textures
  17. dim key$
  18.  
  19.     dim image
  20.     image = LoadImage ("Data/Glass.png")                  
  21.     glGenTextures (3, texture)
  22.     
  23.     glBindTexture (GL_TEXTURE_2D, texture (0))
  24.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
  25.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  26.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  27.     
  28.     glBindTexture (GL_TEXTURE_2D, texture (1))
  29.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  30.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
  31.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  32.     
  33.     glBindTexture (GL_TEXTURE_2D, texture (2))
  34.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  35.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)
  36.     gluBuild2DMipmaps (GL_TEXTURE_2D, 3, ImageWidth(image), ImageHeight(image), ImageFormat(image), ImageDataType(image), image)
  37.  
  38.     DeleteImage (image)
  39.     
  40.     ' Setup OpenGL
  41.                    
  42.     glEnable(GL_TEXTURE_2D)
  43.     glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient#)     ' Setup The Ambient Light
  44.     glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse#)     ' Setup The Diffuse Light
  45.     glLightfv(GL_LIGHT1, GL_POSITION,LightPosition#)    ' Position The Light
  46.     glEnable(GL_LIGHT1)                                 ' Enable Light One
  47.  
  48.     glColor4f(1.0, 1.0, 1.0, 0.5)                       ' Full Brightness.  50% Alpha
  49.     glBlendFunc(GL_SRC_ALPHA,GL_ONE)                    ' Set The Blending Function For Translucency
  50.  
  51.     ' Main loop
  52.  
  53.     while true              
  54.         glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)    ' Clear The Screen And The Depth Buffer
  55.         glLoadIdentity()                                       ' Reset The View
  56.         glTranslatef(0.0,0.0,z#)
  57.     
  58.         glRotatef(xrot#,1.0,0.0,0.0)
  59.         glRotatef(yrot#,0.0,1.0,0.0)
  60.     
  61.         glBindTexture(GL_TEXTURE_2D, texture(filter))
  62.     
  63.         glBegin(GL_QUADS)
  64.             ' Front Face
  65.             glNormal3f( 0.0, 0.0, 1.0)
  66.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  67.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  68.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  69.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  70.             ' Back Face
  71.             glNormal3f( 0.0, 0.0,-1.0)
  72.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  73.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  74.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  75.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  76.             ' Top Face
  77.             glNormal3f( 0.0, 1.0, 0.0)
  78.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  79.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0,  1.0,  1.0)
  80.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0,  1.0,  1.0)
  81.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  82.             ' Bottom Face
  83.             glNormal3f( 0.0,-1.0, 0.0)
  84.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0)
  85.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0)
  86.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  87.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  88.             ' Right face
  89.             glNormal3f( 1.0, 0.0, 0.0)
  90.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  91.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  92.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  93.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  94.             ' Left Face
  95.             glNormal3f(-1.0, 0.0, 0.0)
  96.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  97.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  98.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  99.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  100.         glEnd()
  101.  
  102.         xrot# = xrot# + xspeed#
  103.         yrot# = yrot# + yspeed#  
  104.         
  105.         SwapBuffers ()
  106.         
  107.         key$ = Inkey$ ()
  108.         if key$ = "L" or key$ = "l" then
  109.             light = not light
  110.             if not light then
  111.                 glDisable (GL_LIGHTING)
  112.             else
  113.                 glEnable (GL_LIGHTING)
  114.             endif
  115.         endif
  116.         if key$ = "F" or key$ = "f" then
  117.             filter = filter + 1
  118.             if filter > 2 then 
  119.                 filter = 0
  120.             endif
  121.         endif
  122.         if ScanKeyDown (VK_PRIOR) then
  123.             z# = z# - 0.02
  124.         endif
  125.         if ScanKeyDown (VK_NEXT) then
  126.             z# = z# + 0.02
  127.         endif
  128.         if ScanKeyDown (VK_UP) then
  129.             xspeed# = xspeed# - 0.01
  130.         endif
  131.         if ScanKeyDown (VK_DOWN) then
  132.             xspeed# = xspeed# + 0.01
  133.         endif
  134.         if ScanKeyDown (VK_RIGHT) then
  135.             yspeed# = yspeed# + 0.01
  136.         endif
  137.         if ScanKeyDown (VK_LEFT) then
  138.             yspeed# = yspeed# - 0.01
  139.         endif
  140.         if key$ = "B" or key$ = "b" then 
  141.             blend = not blend
  142.             if blend then 
  143.                 glEnable (GL_BLEND)
  144.                 glDisable (GL_DEPTH_TEST)
  145.             else
  146.                 glDisable (GL_BLEND)
  147.                 glEnable (GL_DEPTH_TEST)
  148.             endif
  149.         endif        
  150.     wend