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

  1.     dim xrot#, yrot#, zrot#                                ' X,Y and Z axis rotation
  2.     dim texture                                        ' OpenGL texture handle
  3.  
  4.     ' Load texture
  5.     ' 
  6.     ' There are a few of ways to load a texture in Basic4GL. The simplest one is used here.
  7.     ' Alternatively the texture can be loaded as an image, and then uploaded into OpenGL
  8.     ' using glTexImage2D or gluBuild2DMipmaps.
  9.     '
  10.     ' TextureDemo.gb demonstrates different methods for loading textures.
  11.     texture = LoadMipmapTexture ("Data/NeHe.bmp")
  12.     if texture = 0 then print "Failed to load texture": end: endif
  13.     
  14.     glEnable (GL_TEXTURE_2D)
  15.     glEnable (GL_CULL_FACE)
  16.  
  17.     while true
  18.         glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)        ' Clear screen and depth buffer
  19.         glLoadIdentity()                                       ' Reset the current modelview matrix
  20.  
  21.         glTranslatef(0.0,0.0,-5.0)                              ' Move into the screen 5 units
  22.  
  23.         glRotatef(xrot#,1.0,0.0,0.0)                        ' Rotate on the X axis
  24.         glRotatef(yrot#,0.0,1.0,0.0)                        ' Rotate on the Y axis
  25.         glRotatef(zrot#,0.0,0.0,1.0)                        ' Rotate on the Z axis
  26.  
  27.              glBindTexture(GL_TEXTURE_2D, texture)                   ' Select our texture
  28.  
  29.             glBegin(GL_QUADS)
  30.             ' Front face
  31.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)    ' Bottom left of the texture and quad
  32.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)    ' Bottom right of the texture and quad
  33.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)    ' Top right of the texture and quad
  34.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)    ' Top left of the texture and quad
  35.             ' Back face
  36.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)    ' Bottom right of the texture and quad
  37.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)    ' Top right of the texture and quad
  38.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)    ' Top left of the texture and quad
  39.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)    ' Bottom left of the texture and quad
  40.             ' Top face
  41.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)    ' Top left of the texture and quad
  42.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0,  1.0,  1.0)    ' Bottom left of the texture and quad
  43.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0,  1.0,  1.0)    ' Bottom right of the texture and quad
  44.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)    ' Top right of the texture and quad
  45.             ' Bottom face
  46.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0)    ' Top right of the texture and quad
  47.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0)    ' Top left of the texture and quad
  48.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)    ' Bottom left of the texture and quad
  49.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)    ' Bottom right of the texture and quad
  50.             ' Right face
  51.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)    ' Bottom right of the texture and quad
  52.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)    ' Top right of the texture and quad
  53.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)    ' Top left of the texture and quad
  54.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)    ' Bottom left of the texture and quad
  55.             ' Left face
  56.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)    ' Bottom left of the texture and quad
  57.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)    ' Bottom right of the texture and quad
  58.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)    ' Top right of the texture and quad
  59.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)    ' Top left of the texture and quad
  60.         glEnd()
  61.     
  62.         SwapBuffers ()
  63.  
  64.         xrot# = xrot# + 0.3                        ' X axis rotation
  65.         yrot# = yrot# + 0.2                        ' Y axis rotation
  66.         zrot# = zrot# + 0.4                        ' Z axis rotation
  67.     wend