Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FBEXT_NO_LIBJPG
- #define fbext_NoBuiltinInstanciations() 1
- '#define FBEXT_BUILD_NO_GFX_LOADERS 1
- #include once "fbgfx.bi"
- '#include once "ext/graphics/png.bi"
- #include once "ext/graphics/image.bi"
- #include once "ext/graphics/sprite.bi"
- #include once "ext/graphics/manip.bi"
- #include once "ext/math/vectors.bi"
- #include once "ext/math/matrix.bi"
- #include once "GL/gl.bi"
- #include once "GL/glu.bi"
- using ext.math
- using ext.gfx
- type triangle_struct
- as integer point_id(2)
- as uinteger tex_id
- end type
- type model_struct
- as uinteger max_vertices
- as vector3d ptr vertex
- as uinteger max_triangles
- as triangle_struct ptr triangle
- end type
- declare function load_texture( byref filename as string, texture as gluint, byref force_clamp as integer ) as integer
- declare function outline( byref filename as string, byval skcol as uinteger ) as integer
- declare function outline_2verts( byref filename as string, byval skcol as uinteger, byref verts as vector2d ptr ) as uinteger
- declare function make_ccw( byref vrets as vector2d ptr, byref max_verts as uinteger ) as uinteger
- dim as integer scr_w = 640, scr_h = 480
- screenres scr_w, scr_h, 32
- dim as vector2d ptr tverts
- dim as uinteger max_tverts = outline_2verts( "res/img/madscience.png", &hffff00ff, tverts )
- print "finish outline!"
- make_ccw( tverts, max_tverts)
- print "finish make_ccw!"
- sleep
- screenres scr_w, scr_h, 32, 0, FB.GFX_OPENGL
- screencontrol FB.SET_GL_DEPTH_BITS, 24
- glViewport(0, 0, scr_w, scr_h)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- gluPerspective( 60, scr_w/scr_h, .01, 10000 )
- glDepthFunc( GL_LEQUAL )
- glEnable( GL_COLOR_MATERIAL )
- glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST )
- glPolygonMode ( GL_FRONT, GL_FILL )
- glPolygonMode ( GL_BACK, GL_LINE )
- glEnable( GL_LIGHTING )
- glEnable( GL_LIGHT0 )
- glEnable( GL_CULL_FACE )
- dim as vector3d campos=vector3d(0,0,3), camlook=vector3d(0,0,0)
- dim as gluint texture
- load_texture( "res/img/madscience.png", texture, 0 )
- do
- if multikey( FB.SC_LEFT ) then
- campos.x-=1.1
- end if
- if multikey( FB.SC_RIGHT ) then
- campos.x+=1.1
- end if
- if multikey( FB.SC_UP ) then
- campos.z+=1.1
- end if
- if multikey( FB.SC_DOWN ) then
- campos.z-=1.1
- end if
- glClear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT )
- glMatrixMode( GL_MODELVIEW )
- glLoadIdentity()
- gluLookat( campos.x, campos.y, campos.z, camlook.x, camlook.y, camlook.z, 0,1,0 )
- glColor3f(1,1,1)
- glrotatef(timer*50,7,2,3)
- glBegin(GL_QUADS)
- glNormal3f(0f,0f,1f)
- gltexcoord2f(0f,1f)
- glVertex3f(-.5,.5,0f)
- gltexcoord2f(0f,0f)
- glVertex3f(-.5,-.5,0f)
- gltexcoord2f(1f,0f)
- glVertex3f(.5,-.5,0f)
- gltexcoord2f(1f,1f)
- glVertex3f(.5,.5,0f)
- glEnd
- 'if max_tverts>0 then
- '
- ' glDisable( GL_CULL_FACE )
- ' glDisable( GL_LIGHTING )
- ' glDisable( GL_TEXTURE_2D )
- ' glColor3f(1,1,1)
- '
- ' glBegin( GL_POLYGON )
- ' for i as integer = 0 to max_tverts-1
- ' glvertex3f( tverts[i].x, tverts[i].y, 0 )
- ' next
- ' glEnd()
- '
- '
- ' glEnable( GL_TEXTURE_2D )
- '
- 'end if
- flip
- print #1, campos
- loop until multikey(FB.SC_ESCAPE)
- deallocate( tverts )
- close #1
- function make_ccw( byref verts as vector2d ptr, byref max_verts as uinteger ) as uinteger
- dim as double angle(max_verts-1)
- dim as vector2d center
- for i as integer = 0 to max_verts-1
- center+=verts[i]
- next
- center/=max_verts
- for i as integer = 0 to max_verts-1
- angle(i) = atan2(center.y-verts[i].y, center.x-verts[i].x)'center.AngleBetween(verts[i])
- next
- for i as integer = 0 to max_verts-1
- for i2 as integer = 0 to max_verts-1
- if i2<>i then
- if angle(i2)<angle(i) then
- swap verts[i], verts[i2]
- swap angle(i), angle(i2)
- end if
- end if
- next
- next
- for i as integer = 0 to max_verts-1
- pset( (verts[i].x*342)+(342/2), (verts[i].y*320)+(320/2) )
- next
- return 0
- end function
- function outline( byref filename as string, byval skcol as uinteger = &hffff00ff ) as integer
- 'draws only the outline of a fb.image ptr
- dim as ext.gfx.image ptr temp = ext.gfx.loadimage( filename )
- 'if temp = 0 then
- ' return 0
- 'end if
- dim mySprite as ext.gfx.Sprite
- mySprite.Init( 1 )
- mySprite.SetImage(0, *temp)
- var bw = mysprite.getcolmap(0)
- put(0,0),temp,alpha,16
- for y1 as integer = 0 To temp->height - 2
- For x1 as integer = 0 To temp->width - 2
- dim as uinteger dif
- dim as uinteger col1 = point(x1,y1,bw)
- dim as ubyte r1 = (col1 shr 24) and 255
- dim as ubyte g1 = (col1 shr 16) and 255
- dim as ubyte b1 = (col1 shr 8) and 255
- for y2 as integer = 0 To 1
- for x2 as integer = 0 To 1
- dim as uinteger col2 = point(x1+x2,y1+y2, bw)
- if dif <> skcol then
- dif+=abs(r1-((col2 shr 24) and 255)) + abs(g1-((col2 shr 16) and 255)) + abs(b1-((col2 shr 8 ) and 255))
- end if
- next
- next
- if dif > 0 then
- pset (x1,y1), rgba( dif, dif, dif, dif )
- end if
- next
- next
- 'imagedestroy( temp )
- return 0
- end function
- function outline_2verts( byref filename as string, byval skcol as uinteger, byref verts as vector2d ptr ) as uinteger
- 'draws only the outline of a fb.image ptr
- dim as uinteger vcnt
- dim as ext.gfx.image ptr temp = ext.gfx.loadimage( filename )
- 'if temp = 0 then
- ' return 0
- 'end if
- dim mySprite as Sprite
- mySprite.Init( 1 )
- mySprite.SetImage(0, *temp)
- var bw = mysprite.getcolmap(0)
- put(0,0),temp,alpha,16
- for y1 as integer = 0 To temp->height - 2
- For x1 as integer = 0 To temp->width - 2
- dim as uinteger dif
- dim as uinteger col1 = point(x1,y1,bw)
- dim as ubyte r1 = (col1 shr 24) and 255
- dim as ubyte g1 = (col1 shr 16) and 255
- dim as ubyte b1 = (col1 shr 8) and 255
- for y2 as integer = 0 To 1
- for x2 as integer = 0 To 1
- dim as uinteger col2 = point(x1+x2,y1+y2, bw)
- if dif <> skcol then
- dif+=abs(r1-((col2 shr 24) and 255)) + abs(g1-((col2 shr 16) and 255)) + abs(b1-((col2 shr 8 ) and 255))
- end if
- next
- next
- if dif > 0 then
- pset (x1,y1), rgba( dif, dif, dif, dif )
- verts = reallocate( verts, (vcnt+1)*sizeof(vector2d) )
- verts[vcnt] = vector2d(x1-(temp->width/2) ,y1-(temp->height/2) )
- verts[vcnt]/=vector2d(temp->width, temp->height)
- 'pset( (verts[vcnt].x)+(temp->width/2), (verts[vcnt].y)+(temp->height/2)), rgba(dif, dif, dif, dif)
- 'print #1, verts[vcnt]
- vcnt+=1
- end if
- next
- next
- 'imagedestroy( temp )
- print #1, vcnt
- return vcnt
- end function
- function load_texture( byref filename as string, texture as gluint, byref force_clamp as integer ) as integer
- glenable( GL_TEXTURE_2D )
- glbindtexture( GL_TEXTURE_2D, texture )
- dim SprWidth as integer
- dim SprHeight as integer
- dim as ext.gfx.image ptr temp = ext.gfx.loadimage( filename)', ext.gfx.TARGET_OPENGL )
- 'if temp = 0 then
- ' return 0
- 'end if
- sprWidth = temp->width
- sprHeight = temp->height
- glteximage2d( GL_TEXTURE_2D, 0, GL_RGBA, SprWidth, SprHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels )
- glubuild2dmipmaps( GL_TEXTURE_2D, GL_RGBA, SprWidth, SprHeight, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels )
- if force_clamp then
- gltexparameterf GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
- gltexparameterf GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
- else
- gltexparameterf GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT
- gltexparameterf GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT
- end if
- gltexparameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR )
- gltexparameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR )
- gltexenvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
- return 0
- end function
Add Comment
Please, Sign In to add comment