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

  1. dim xrot#           ' X rotation
  2. dim yrot#           ' Y rotation
  3.  
  4. dim texture         ' Storage for one texture
  5. dim box             ' Storage for the display list
  6. dim top             ' Storage for the second display list
  7. dim xloop           ' Loop for X axis
  8. dim yloop           ' Loop for Y axis
  9.  
  10. dim boxcol#(4)(2)   ' Array for box colors
  11. boxcol#(0) = vec3 ( 1, 0, 0)                ' Bright:  Red, Orange, Yellow, Green, Blue
  12. boxcol#(1) = vec3 ( 1,.5, 0)
  13. boxcol#(2) = vec3 ( 1, 1, 0)
  14. boxcol#(3) = vec3 ( 0, 1, 0)
  15. boxcol#(4) = vec3 ( 0, 1, 1)
  16.  
  17. dim topcol#(4)(2)   ' Array for top colors
  18. topcol#(0) = vec3 ( .5,  0,  0)             ' Dark:  Red, Orange, Yellow, Green, Blue
  19. topcol#(1) = vec3 ( .5,.25,  0)
  20. topcol#(2) = vec3 ( .5, .5,  0)
  21. topcol#(3) = vec3 (  0, .5,  0)
  22. topcol#(4) = vec3 (  0, .5, .5)
  23.  
  24. ' Load a single texture
  25. texture = LoadMipmapTexture ("Data\Cube.bmp")
  26.  
  27. ' Build cube display lists
  28. box = glGenLists(2)                 ' Generate 2 different lists
  29. glNewList(box, GL_COMPILE)          ' Start with the box list
  30.     glBegin(GL_QUADS)
  31.  
  32.         ' Bottom Face
  33.         glNormal3f( 0.0,-1.0, 0.0)
  34.         glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0)
  35.         glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0)
  36.         glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  37.         glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  38.             
  39.         ' Front Face
  40.         glNormal3f( 0.0, 0.0, 1.0)
  41.         glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  42.         glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  43.         glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  44.         glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  45.  
  46.         ' Back Face
  47.         glNormal3f( 0.0, 0.0,-1.0)
  48.         glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  49.         glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  50.         glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  51.         glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  52.         
  53.         ' Right face
  54.         glNormal3f( 1.0, 0.0, 0.0)
  55.         glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  56.         glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  57.         glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  58.         glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  59.         
  60.         ' Left Face
  61.         glNormal3f(-1.0, 0.0, 0.0)
  62.         glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  63.         glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  64.         glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  65.         glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  66.     glEnd()
  67. glEndList()
  68. top = box + 1                       ' Storage for "Top" is "Box" plus one
  69. glNewList(top,GL_COMPILE)           ' Now the "Top" display list
  70.     glBegin(GL_QUADS)
  71.         ' Top Face
  72.         glNormal3f( 0.0, 1.0, 0.0)
  73.         glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  74.         glTexCoord2f(0.0, 0.0): glVertex3f(-1.0,  1.0,  1.0)
  75.         glTexCoord2f(1.0, 0.0): glVertex3f( 1.0,  1.0,  1.0)
  76.         glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  77.     glEnd()
  78. glEndList()
  79.  
  80. ' Setup OpenGL
  81. glEnable(GL_LIGHT0)                 ' Quick and dirty lighting (assumes Light0 is set up)
  82. glEnable(GL_LIGHTING)               ' Enable lighting
  83. glEnable(GL_COLOR_MATERIAL)         ' Enable material coloring
  84. glEnable(GL_TEXTURE_2D)
  85. glBindTexture(GL_TEXTURE_2D, texture)
  86.  
  87. ' Main loop
  88. while true
  89.     
  90.     ' Render
  91.     glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)     ' Clear screen and depth buffer
  92.     glBindTexture(GL_TEXTURE_2D, texture)
  93.     for yloop = 1 to 5
  94.         for xloop = 0 to yloop - 1
  95.             glLoadIdentity ()                               ' Reset the view
  96.             glTranslatef(1.4+xloop*2.8-yloop*1.4,(6.0-yloop)*2.4-7.0,-20.0)
  97.             glRotatef(45.0-2.0*yloop+xrot#,1.0,0.0,0.0)
  98.             glRotatef(45.0+yrot#,0.0,1.0,0.0)
  99.             glColor3fv(boxcol#(yloop-1))
  100.             glCallList(box)
  101.             glColor3fv(topcol#(yloop-1))
  102.             glCallList(top)
  103.         next
  104.     next
  105.     SwapBuffers ()
  106.  
  107.     ' Handle input
  108.     if ScanKeyDown (VK_LEFT) then
  109.         yrot# = yrot# - 0.2
  110.     endif
  111.     if ScanKeyDown (VK_RIGHT) then
  112.         yrot# = yrot# + 0.2
  113.     endif
  114.     if ScanKeyDown (VK_UP) then
  115.         xrot# = xrot# - 0.2
  116.     endif
  117.     if ScanKeyDown (VK_DOWN) then
  118.         xrot# = xrot# + 0.2
  119.     endif
  120.  
  121. wend