Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '$stop_scan
- #include once "fbgfx.bi"
- #include once "gl/gl.bi"
- #include once "gl/glu.bi"
- screenres 480, 480, 32, , fb.GFX_OPENGL
- '' set up our viewport
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- glViewport(0, 0, 480, 480)
- glLoadIdentity ()
- glFrustum (-0.125/2.0, 0.125/2.0, -0.125/2.0, 0.125/2.0, 0.1, 100.0)
- '' set up color properties
- glClearColor(.125, .125, .125, 0)
- '' set up rendering
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- glEnable (GL_DEPTH_TEST)
- glEnable (GL_LINE_SMOOTH)
- glShadeModel( GL_FLAT )
- type vclr
- r as ubyte
- g as ubyte
- b as ubyte
- a as ubyte
- end type
- dim as vclr vtest(0 to 15, 0 to 15, 0 to 15)
- const vsize = 0.05
- dim as GLuint vlist
- declare sub ren_vox ( v() as vclr )
- sub gen_vox ( v() as vclr, l as GLuint )
- glNewList(l, GL_COMPILE)
- glTranslatef(-0.4, -0.4, -0.4)
- for i as integer = 0 to ubound(v, 0)
- for j as integer = 0 to ubound(v, 1)
- for k as integer = 0 to ubound(v, 2)
- if v(i,j,k).a > 0 then
- dim as double x, y, z
- x = cdbl(i) * vsize
- y = cdbl(j) * vsize
- z = cdbl(k) * vsize
- glColor3ub(v(i,j,k).r, v(i,j,k).g, v(i,j,k).b)
- if k = 0 orelse v(i,j,k-1).a = 0 then
- glBegin(GL_QUADS)
- glVertex3f(x, y, z)
- glVertex3f(x+vsize, y, z)
- glVertex3f(x+vsize, y+vsize, z)
- glVertex3f(x, y+vsize, z)
- glEnd()
- end if
- if k = ubound(v,2) orelse v(i,j,k+1).a = 0 then
- glBegin(GL_QUADS)
- glVertex3f(x, y, z+vsize)
- glVertex3f(x+vsize, y, z+vsize)
- glVertex3f(x+vsize, y+vsize, z+vsize)
- glVertex3f(x, y+vsize, z+vsize)
- glEnd()
- end if
- if j = 0 orelse v(i,j-1,k).a = 0 then
- glBegin(GL_QUADS)
- glVertex3f(x, y, z)
- glVertex3f(x+vsize, y, z)
- glVertex3f(x+vsize, y, z+vsize)
- glVertex3f(x, y, z+vsize)
- glEnd()
- end if
- if j = ubound(v,1) orelse v(i,j+1,k).a = 0 then
- glBegin(GL_QUADS)
- glVertex3f(x, y+vsize, z)
- glVertex3f(x+vsize, y+vsize, z)
- glVertex3f(x+vsize, y+vsize, z+vsize)
- glVertex3f(x, y+vsize, z+vsize)
- glEnd()
- end if
- if i = 0 orelse v(i-1,j,k).a = 0 then
- glBegin(GL_QUADS)
- glVertex3f(x, y, z)
- glVertex3f(x, y+vsize, z)
- glVertex3f(x, y+vsize, z+vsize)
- glVertex3f(x, y, z+vsize)
- glEnd()
- end if
- if i = ubound(v,0) orelse v(i+1,j,k).a = 0 then
- glBegin(GL_QUADS)
- glVertex3f(x+vsize, y, z)
- glVertex3f(x+vsize, y+vsize, z)
- glVertex3f(x+vsize, y+vsize, z+vsize)
- glVertex3f(x+vsize, y, z+vsize)
- glEnd()
- end if
- end if
- next k
- next j
- next i
- glEndList()
- end sub
- for i as integer = 0 to ubound(vtest, 0)
- for j as integer = 0 to ubound(vtest, 1)
- for k as integer = 0 to ubound(vtest, 2)
- vtest(i,j,k).r = fix(rnd*255)
- vtest(i,j,k).g = fix(rnd*255)
- vtest(i,j,k).b = fix(rnd*255)
- vtest(i,j,k).a = 255
- if (rnd > 0.5) then vtest(i,j,k).a = 0
- next k
- next j
- next i
- vlist = GLGenLists(1)
- gen_vox(vtest(), vlist)
- dim as double curT = timer(), lastT = timer()
- do
- glFinish()
- '' begin a new matrix for the polygon set so we can isolate our rendering
- '' and not affect other matrices.
- glPushMatrix()
- glTranslatef(0.0, 0.0, -2.0)
- glRotatef(curT*100.0, 1.0, 1.0, 2.0)
- glCallList(vlist)
- glPopMatrix()
- '' render important information
- 'open cons for output as #1
- ' print #1, 1/(curT - lastT)
- 'close #1
- '' flip our screen
- 'glFlush()
- flip()
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
- 'sleep(16, 1)
- lastT = curT
- curT = timer()
- loop until multikey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement