Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '$stop_scan
  2. #include once "fbgfx.bi"
  3. #include once "gl/gl.bi"
  4. #include once "gl/glu.bi"
  5.  
  6. screenres 480, 480, 32, , fb.GFX_OPENGL
  7.  
  8. '' set up our viewport
  9. glMatrixMode(GL_PROJECTION)
  10. glLoadIdentity()
  11. glViewport(0, 0, 480, 480)
  12. glLoadIdentity ()
  13. glFrustum (-0.125/2.0, 0.125/2.0, -0.125/2.0, 0.125/2.0, 0.1, 100.0)
  14.  
  15. '' set up color properties
  16. glClearColor(.125, .125, .125, 0)
  17.  
  18. '' set up rendering
  19. glMatrixMode(GL_MODELVIEW)
  20. glLoadIdentity()
  21.  
  22. glEnable (GL_DEPTH_TEST)
  23. glEnable (GL_LINE_SMOOTH)
  24.  
  25. glShadeModel( GL_FLAT )
  26.  
  27. type vclr
  28.    r as ubyte
  29.    g as ubyte
  30.    b as ubyte
  31.    a as ubyte
  32. end type
  33.  
  34. dim as vclr vtest(0 to 15, 0 to 15, 0 to 15)
  35. const vsize = 0.05
  36.  
  37. dim as GLuint vlist
  38.  
  39. declare sub ren_vox ( v() as vclr )
  40.  
  41. sub gen_vox ( v() as vclr, l as GLuint )
  42.  
  43.    
  44.    
  45.    glNewList(l, GL_COMPILE)
  46.  
  47.    glTranslatef(-0.4, -0.4, -0.4)
  48.  
  49.     for i as integer = 0 to ubound(v, 0)
  50.         for j as integer = 0 to ubound(v, 1)
  51.             for k as integer = 0 to ubound(v, 2)
  52.  
  53.                 if v(i,j,k).a > 0 then
  54.  
  55.                     dim as double x, y, z
  56.                     x = cdbl(i) * vsize
  57.                     y = cdbl(j) * vsize
  58.                     z = cdbl(k) * vsize
  59.  
  60.                     glColor3ub(v(i,j,k).r, v(i,j,k).g, v(i,j,k).b)
  61.  
  62.                     if k = 0 orelse v(i,j,k-1).a = 0 then
  63.  
  64.                        glBegin(GL_QUADS)
  65.                             glVertex3f(x, y, z)
  66.                             glVertex3f(x+vsize, y, z)
  67.                             glVertex3f(x+vsize, y+vsize, z)
  68.                             glVertex3f(x, y+vsize, z)
  69.                        glEnd()
  70.  
  71.                     end if
  72.  
  73.                     if k = ubound(v,2) orelse v(i,j,k+1).a = 0 then
  74.  
  75.                         glBegin(GL_QUADS)
  76.                             glVertex3f(x, y, z+vsize)
  77.                             glVertex3f(x+vsize, y, z+vsize)
  78.                             glVertex3f(x+vsize, y+vsize, z+vsize)
  79.                             glVertex3f(x, y+vsize, z+vsize)
  80.                         glEnd()
  81.  
  82.                     end if
  83.  
  84.                     if j = 0 orelse v(i,j-1,k).a = 0 then
  85.  
  86.                         glBegin(GL_QUADS)
  87.                             glVertex3f(x, y, z)
  88.                             glVertex3f(x+vsize, y, z)
  89.                             glVertex3f(x+vsize, y, z+vsize)
  90.                             glVertex3f(x, y, z+vsize)
  91.                         glEnd()
  92.  
  93.                     end if
  94.  
  95.                     if j = ubound(v,1) orelse v(i,j+1,k).a = 0 then
  96.  
  97.                         glBegin(GL_QUADS)
  98.                             glVertex3f(x, y+vsize, z)
  99.                             glVertex3f(x+vsize, y+vsize, z)
  100.                             glVertex3f(x+vsize, y+vsize, z+vsize)
  101.                             glVertex3f(x, y+vsize, z+vsize)
  102.                         glEnd()
  103.  
  104.                     end if
  105.  
  106.                     if i = 0 orelse v(i-1,j,k).a = 0 then
  107.  
  108.                         glBegin(GL_QUADS)
  109.                             glVertex3f(x, y, z)
  110.                             glVertex3f(x, y+vsize, z)
  111.                             glVertex3f(x, y+vsize, z+vsize)
  112.                             glVertex3f(x, y, z+vsize)
  113.                         glEnd()
  114.  
  115.                     end if
  116.  
  117.                     if i = ubound(v,0) orelse v(i+1,j,k).a = 0 then
  118.  
  119.                         glBegin(GL_QUADS)
  120.                             glVertex3f(x+vsize, y, z)
  121.                             glVertex3f(x+vsize, y+vsize, z)
  122.                             glVertex3f(x+vsize, y+vsize, z+vsize)
  123.                             glVertex3f(x+vsize, y, z+vsize)
  124.                         glEnd()
  125.  
  126.                     end if
  127.  
  128.  
  129.                 end if
  130.  
  131.             next k
  132.         next j
  133.     next i
  134.  
  135.    glEndList()
  136.    
  137.  
  138. end sub
  139.  
  140. for i as integer = 0 to ubound(vtest, 0)
  141.     for j as integer = 0 to ubound(vtest, 1)
  142.         for k as integer = 0 to ubound(vtest, 2)
  143.             vtest(i,j,k).r = fix(rnd*255)
  144.             vtest(i,j,k).g = fix(rnd*255)
  145.             vtest(i,j,k).b = fix(rnd*255)
  146.             vtest(i,j,k).a = 255
  147.             if (rnd > 0.5) then vtest(i,j,k).a = 0
  148.         next k
  149.     next j
  150. next i
  151.  
  152. vlist = GLGenLists(1)
  153.  
  154. gen_vox(vtest(), vlist)
  155.  
  156. dim as double curT = timer(), lastT = timer()
  157. do
  158.          glFinish()
  159.         '' begin a new matrix for the polygon set so we can isolate our rendering
  160.         '' and not affect other matrices.
  161.         glPushMatrix()
  162.            
  163.             glTranslatef(0.0, 0.0, -2.0)
  164.             glRotatef(curT*100.0, 1.0, 1.0, 2.0)
  165.             glCallList(vlist)
  166.  
  167.         glPopMatrix()
  168.        
  169.        
  170.         '' render important information
  171.         'open cons for output as #1
  172.         '        print #1, 1/(curT - lastT)
  173.         'close #1
  174.        
  175.  
  176.         '' flip our screen
  177.         'glFlush()
  178.         flip()
  179.         glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
  180.        
  181.         'sleep(16, 1)      
  182.         lastT = curT
  183.         curT = timer()
  184.        
  185. loop until multikey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement