error :
i got a white screen
Code: Select all
''bluatigro 25 jan 2017
''opengl lib test
''rotating cube
#include "_OPEN-GL.bas"
dim as single hoek
do
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
glLoadIdentity
glTranslatef 0 , 0 , -5
glRotatef hoek , 0 , 1 , 0
material.diffuse = red
setMaterial GL_FRONT_AND_BACK , material
setbox 0,0,0 , 1,1,1
cube
hoek += 5
sleep 40
loop until inkey = chr( 27 )
Code: Select all
''bluatigro 25 jan 2017
''opengl lib
#ifndef OPENGL_H
#define OPENGL_H
''VECTOR3D
type t3d
x as single
y as single
z as single
declare constructor()
declare constructor ( x as single , y as single, z as single )
declare sub fill( x as single , y as single , z as single )
declare sub normalize
end type
constructor t3d()
this.x = 0
this.y = 0
this.z = 0
end constructor
constructor t3d( x as single , y as single , z as single )
this.x = x
this.y = y
this.z = z
end constructor
operator +( a as t3d , b as t3d ) as t3d
return type( a.x + b.x , a.y + b.y , a.z + b.z )
end operator
operator *( a as t3d , d as single ) as t3d
return type( a.x * d , a.y * d , a.z * d )
end operator
operator \( a as t3d , b as t3d ) as t3d
return type( a.y * b.z - a.z * b.y _
, a.z * b.x - a.x * b.z _
, a.x * b.y - a.y * b.x )
end operator
operator -( a as t3d , b as t3d ) as t3d
return type( a.x - b.x , a.y - b.y , a.z - b.z )
end operator
operator /( a as t3d , d as single ) as t3d
return type( a.x / d , a.y / d , a.z / d )
end operator
sub t3d.fill( x as single , y as single , z as single )
this.x = x
this.y = y
this.z = z
end sub
declare function dot( a as t3d , b as t3d ) as single
function dot( a as t3d , b as t3d ) as single
return a.x * b.x + a.y * b.y + a.z * b.z
end function
declare function length( q as t3d ) as single
function length( q as t3d ) as single
return sqr( q.x * q.x + q.y * q.y + q.z * q.z ) + 1e-7
end function
declare function anlge( a as t3d , b as t3d ) as single
function getangle( a as t3d , b as t3d ) as single
return acos( dot( a , b ) _
/ ( length( a ) * length( b ) ) )
end function
sub t3d.normalize
this /= length( this )
end sub
#include once "GL/gl.bi"
#include once "GL/glu.bi"
const as single PI = csng( atn( 1 ) * 4 )
screen 20, 32, , 2
'' ReSizeGLScene
glViewport 0, 0, 1024 , 768 '' Reset The Current Viewport
glMatrixMode GL_PROJECTION '' Select The Projection Matrix
glLoadIdentity '' Reset The Projection Matrix
gluPerspective 45.0, 1024.0/768.0, 0.1, 100.0 '' Calculate The Aspect Ratio Of The Window
glMatrixMode GL_MODELVIEW '' Select The Modelview Matrix
glLoadIdentity '' Reset The Modelview Matrix
'' All Setup For OpenGL Goes Here
glShadeModel GL_SMOOTH '' Enable Smooth Shading
glClearColor 0.0, 0.0, 0.0, 0.5 '' Black Background
glClearDepth 1.0 '' Depth Buffer Setup
glEnable GL_DEPTH_TEST '' Enables Depth Testing
glDepthFunc GL_LEQUAL '' The Type Of Depth Testing To Do
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST '' Really Nice Perspective Calculations
glEnable( gl_lighting )
dim as single lightpos( 3 ) = { 0 , 50 , 0 , 1 }
dim as single diffuse( 3 ) = { 1 , 1 , 1 , 1 }
glLightfv( gl_light0 , gl_position, @lightpos(0) )
glLightfv( gl_light0 , gl_diffuse , @diffuse(0) )
glEnable( gl_light0 )
''COLORS
type t_4d
dim as single x , y , z , w
declare sub fill( nx as single , ny as single , nz as single , nw as single )
end type
sub t_4d.fill( nx as single , ny as single , nz as single , nw as single )
x = nx
y = ny
z = nz
w = nw
end sub
dim shared as t_4d black , red , green , yellow _
, blue , magenta , cyan , white _
, orange , gray , pink
black.fill 0,0,0,1
red.fill 1,0,0,1
green.fill 0,1,0,1
yellow.fill 1,1,0,1
blue.fill 0,0,1,1
magenta.fill 1,0,1,1
cyan.fill 0,1,1,1
white.fill 1,1,1,1
orange.fill 1,.5, 0,1
gray.fill .5,.5,.5,1
pink.fill 1,.5,.5,1
''MATERIAL
type t_material
dim as t_4d ambient , diffuse , specular , emision
dim as single shininess
end type
dim shared as t_material material
sub setMaterial( a as long , m as t_material )
glMaterialfv a , GL_AMBIENT , @m.ambient.x
glMaterialfv a , GL_DIFFUSE , @m.diffuse.x
glMaterialfv a , GL_SPECULAR , @m.specular.x
glMaterialfv a , GL_EMISSION , @m.emision.x
glMaterialf a , GL_SHININESS , m.shininess
end sub
''PRIMATIVS
dim shared as t3d pnt( 256 )
sub setpoint( no as integer , x as single , y as single , z as single )
if no < 0 or no > 255 then exit sub
pnt( no ).x = x
pnt( no ).y = y
pnt( no ).z = z
end sub
sub tri( p1 as integer , p2 as integer , p3 as integer )
if p1 < 0 or p1 > 255 then exit sub
if p2 < 0 or p2 > 255 then exit sub
if p3 < 0 or p3 > 255 then exit sub
dim as t3d n = ( pnt( p2 ) - pnt( p1 ) ) _
\ ( pnt( p3 ) - pnt( p1 ) )
n.normalize()
glbegin gl_triangles
glnormal3f n.x , n.y , n.z
glvertex3f pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
glvertex3f pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
glvertex3f pnt( p3 ).x , pnt( p3 ).y , pnt( p3 ).z
glend
end sub
sub quad( p1 as integer , p2 as integer , p3 as integer , p4 as integer )
if p1 < 0 or p1 > 255 then exit sub
if p2 < 0 or p2 > 255 then exit sub
if p3 < 0 or p3 > 255 then exit sub
if p4 < 0 or p4 > 255 then exit sub
dim as t3d zp = ( pnt( p1 ) + pnt( p2 ) _
+ pnt( p3 ) + pnt( p4 ) ) / 4
dim as t3d n = ( pnt( p2 ) - zp ) _
\ ( pnt( p3 ) - zp )
n.normalize()
glbegin gl_quads
glnormal3f n.x , n.y , n.z
glvertex3f pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
glvertex3f pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
glvertex3f pnt( p3 ).x , pnt( p3 ).y , pnt( p3 ).z
glvertex3f pnt( p4 ).x , pnt( p4 ).y , pnt( p4 ).z
glend
end sub
''SHAPES
type Tbox
m as t3d
d as t3d
end type
dim shared box as Tbox
declare sub isoca( i as integer )
declare sub sphere( h as integer , r as integer _
, a as single , b as single )
declare sub torus( hsides as integer , rsides as integer )
declare sub cilinder( sides as integer _
, dx as single , dy as single , top as integer , bot as integer )
declare sub cube( )
declare sub hcube( )
declare sub setbox( mx as single , my as single _
, mz as single , dx as single , dy as single , dz as single )
declare sub geo( no as integer , p1 as integer _
, p2 as integer , p3 as integer )
sub geo( no as integer , p1 as integer _
, p2 as integer , p3 as integer )
if no < 1 then
tri p1 , p2 , p3
else
dim p12 as integer , p13 as integer , p23 as integer
p12 = 255 - no * 3
p13 = 255 - no * 3 - 1
p23 = 255 - no * 3 - 2
pnt( p12 ) = ( pnt( p1 ) + pnt( p2 ) ) / 2
pnt( p13 ) = ( pnt( p1 ) + pnt( p3 ) ) / 2
pnt( p23 ) = ( pnt( p2 ) + pnt( p3 ) ) / 2
pnt( p12 ).normalize
pnt( p13 ).normalize
pnt( p23 ).normalize
geo no - 1 , p1 , p12 , p13
geo no - 1 , p2 , p23 , p12
geo no - 1 , p3 , p13 , p23
geo no - 1 , p12 , p23 , p13
end if
end sub
sub isoca( i as integer )
if i < 0 then i = 0
if i > 5 then i = 5
glPushMatrix
glTranslatef box.m.x , box.m.y , box.m.z
glScalef box.d.x , box.d.y , box.d.z
setpoint 1 , 0 , 0 , 1.118034
setpoint 2 , 1 , 0 , .5
setpoint 3 , .309017 , .95105654 , .5
setpoint 4 , -.809017 , .58778524 , .5
setpoint 5 , -.809017 , -.58778524 , .5
setpoint 6 , .309017 , -.95105654 , .5
setpoint 7 , .809017 , .58778524 , -.5
setpoint 8 , -.309017 , .95105654 , -.5
setpoint 9 , -1 , 0 , -.5
setpoint 10 , -.309017 , -.95105654 , -.5
setpoint 11 , .809017 , -.58778524 , -.5
setpoint 12 , 0 , 0 , -1.118034
dim t as integer
for t = 1 to 12
pnt( t ).normalize
next t
geo i , 1 , 2 , 3
geo i , 1 , 3 , 4
geo i , 1 , 4 , 5
geo i , 1 , 5 , 6
geo i , 1 , 6 , 2
geo i , 2 , 7 , 3
geo i , 3 , 7 , 8
geo i , 3 , 8 , 4
geo i , 4 , 8 , 9
geo i , 4 , 9 , 5
geo i , 5 , 9 , 10
geo i , 5 , 10 , 6
geo i , 6 , 10 , 11
geo i , 6 , 11 , 2
geo i , 2 , 11 , 7
geo i , 12 , 8 , 7
geo i , 12 , 9 , 8
geo i , 12 , 10 , 9
geo i , 12 , 11 , 10
geo i , 12 , 7 , 11
glPopMatrix
end sub
sub sphere( a as integer , b as integer _
, da as single , db as single )
dim as single i , j , i2 , j2
dim as single x , y , z
if a < 3 then a = 3
if a > 64 then a = 64
if b < 3 then b = 3
if b > 64 then b = 64
glPushMatrix
glTranslatef box.m.x , box.m.y , box.m.z
glScalef box.d.x , box.d.y , box.d.z
for i = -PI to PI step PI / a * 2
i2 = i + PI / a * 2
for j = -PI / 2 to PI / 2 - pi / b * 2 step PI / b * 2
j2 = j + PI / b * 2
x = sin( i ) * cos( j )
y = sin( j )
z = cos( i ) * cos( j )
setpoint 0 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
x = sin( i2 ) * cos( j )
y = sin( j )
z = cos( i2 ) * cos( j )
setpoint 1 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
x = sin( i2 ) * cos( j2 )
y = sin( j2 )
z = cos( i2 ) * cos( j2 )
setpoint 2 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
x = sin( i ) * cos( j2 )
y = sin( j2 )
z = cos( i ) * cos( j2 )
setpoint 3 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
quad 0 , 1 , 2 , 3
next j
next i
glPopMatrix
end sub
sub torus( a as integer , b as integer )
dim i as single , j as single , i2 as single , j2 as single
if a < 3 then a = 3
if a > 64 then a = 643
if b < 3 then b = 3
if b > 64 then b = 64
dim mx as single , my as single , mz as single , dx as single , dy as single , dz as single
mx = box.m.x
my = box.m.y
mz = box.m.z
dx = box.d.x
dy = box.d.y
dz = box.d.z
for i = -PI to PI step PI / a * 2
i2 = i + PI / a * 2
for j = -PI to PI step PI / b * 2
j2 = j + PI / b * 2
setpoint 0 _
, mx + ( dx + dy * cos( i ) ) * cos( j ) _
, my + ( dx + dy * cos( i ) ) * sin( j ) _
, mz + sin( i ) * dz
setpoint 1 _
, mx + ( dx + dy * cos( i ) ) * cos( j2 ) _
, my + ( dx + dy * cos( i ) ) * sin( j2 ) _
, mz + sin( i ) * dz
setpoint 2 _
, mx + ( dx + dy * cos( i2 ) ) * cos( j2 ) _
, my + ( dx + dy * cos( i2 ) ) * sin( j2 ) _
, mz + sin( i2 ) * dz
setpoint 3 _
, mx + ( dx + dy * cos( i2 ) ) * cos( j ) _
, my + ( dx + dy * cos( i2 ) ) * sin( j ) _
, mz + sin( i2 ) * dz
quad 0 , 1 , 2 , 3
next j
next i
end sub
sub cilinder( sides as integer , dx as single , dy as single , top as integer , bot as integer )
dim f as single
if sides < 3 then sides = 3
if sides > 64 then sides = 64
for f = 0 to sides + 2
setpoint f , box.m.x + sin( f * pi * 2 / sides ) * box.d.x _
, box.m.y - box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * box.d.z
setpoint f + sides + 1 , box.m.x + sin( f * pi * 2 / sides ) * dx _
, box.m.y + box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * dy
next f
for f = 0 to sides + 1
quad f , f + 1 , f + 2 + sides , f + 1 + sides
next f
if top then
setpoint 255 , 0 , box.m.y + box.d.y , 0
for f = 0 to sides
setpoint f , box.m.x + sin( f * pi * 2 / sides ) * dx _
, box.m.y + box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * dy
next f
for f = 0 to sides
tri 255 , f , f + 1
next f
end if
if bot then
setpoint 255 , 0 , box.m.y - box.d.y , 0
for f = 0 to sides + 2
setpoint f , box.m.x - sin( f * pi * 2 / sides ) * box.d.x _
, box.m.y - box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * box.d.z
next f
for f = 0 to sides + 2
tri 255 , f , f + 1
next f
end if
end sub
sub cube()
setpoint 0 , box.m.x + box.d.x , box.m.y + box.d.y , box.m.z + box.d.z
setpoint 1 , box.m.x + box.d.x , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 2 , box.m.x + box.d.x , box.m.y - box.d.y , box.m.z + box.d.z
setpoint 3 , box.m.x + box.d.x , box.m.y - box.d.y , box.m.z - box.d.z
setpoint 4 , box.m.x - box.d.x , box.m.y + box.d.y , box.m.z + box.d.z
setpoint 5 , box.m.x - box.d.x , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 6 , box.m.x - box.d.x , box.m.y - box.d.y , box.m.z + box.d.z
setpoint 7 , box.m.x - box.d.x , box.m.y - box.d.y , box.m.z - box.d.z
quad 0 , 2 , 3 , 1 ''right
quad 7 , 6 , 4 , 5 ''left
quad 0 , 4 , 5 , 1 ''up
quad 7 , 3 , 2 , 6 ''down
quad 0 , 4 , 6 , 2 ''back
quad 7 , 5 , 1 , 3 ''front
end sub
sub hcube()
setpoint 1 , box.m.x + box.d.x , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 2 , box.m.x + box.d.x , box.m.y - box.d.y , box.m.z + box.d.z
setpoint 3 , box.m.x + box.d.x , box.m.y - box.d.y , box.m.z - box.d.z
setpoint 4 , box.m.x - box.d.x , box.m.y + box.d.y , box.m.z + box.d.z
setpoint 5 , box.m.x - box.d.x , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 6 , box.m.x - box.d.x , box.m.y - box.d.y , box.m.z + box.d.z
setpoint 7 , box.m.x - box.d.x , box.m.y - box.d.y , box.m.z - box.d.z
setpoint 0 , box.m.x + box.d.x , box.m.y - box.d.y , 0
setpoint 8 , box.m.x + box.d.x , 0 , box.m.z - box.d.z
setpoint 9 , 0 , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 10 , box.m.x - box.d.x , box.m.x + box.d.y , 0
setpoint 11 , box.m.x - box.d.x , 0 , box.m.z + box.d.z
setpoint 12, 0 , box.m.y - box.d.y , box.m.z + box.d.z
tri 7 , 6 , 3
tri 7 , 5 , 6
tri 7 , 3 , 5
quad 6 , 5 , 10 , 11
quad 5 , 3 , 8 , 9
quad 3 , 6 , 12 , 0
tri 6 , 12 , 11
tri 3 , 8 , 0
tri 5 , 9 , 10
end sub
sub setbox( mx as single , my as single , mz as single , dx as single , dy as single , dz as single )
box.m.x = mx
box.m.y = my
box.m.z = mz
box.d.x = dx
box.d.y = dy
box.d.z = dz
end sub
#endif