Easy GL2D

User projects written in or related to FreeBASIC.
fernando.inf
Posts: 28
Joined: Mar 10, 2009 1:41
Contact:

Postby fernando.inf » Sep 13, 2010 6:39

I have some doubts about that, as currently i use the datafile of the allegro, I load it in the beginning of the program and everything is in memory, only access the pointers of the images within of DAT.

I send the sample but tomorrow, I am now finishing a service here.

but you understand the concept: Do not keep waiting time to complete the frame to draw, draw after the time reaches the fps.

Within the update function of my object animation I have another function called nextFrame (), this function returns TRUE if the time passed the next frame or FALSE if it is not now, then do so:

Code: Select all

function Animation.update()
    if This.NextFrame() then
     '' Here I draw the sprite in screen buffer
    end if
end function


if not yet completed the frame time, it just keeps looping.
I use the same technique to LoopControl() function to draw the buffer on the screen
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 02, 2010 15:31

I tried compiling pixel_perfect_collision.bas and gl2d_test.bas from fbgl2d_v5.zip in Linux and getting a segmentation fault.

gl2d_test.bas:

Code: Select all

''=============================================================================

''

''    Easy GL2D (FB.IMAGE compatible version)

''    By Relminator (Richard Eric M. Lope)

''    http://rel.betterwebber.com

''   

''    An easy to use OpenGL 2d lib

''    As easy as fbgfx (easier IMHO if you use my Texture packer)

''   

''    Can automatically load BMP's supported by BLOAD

''    Adds alpha transparency if you want

''    No external dependencies (only uses OpenGL/GLU and FBGFX)

''    Source license is "use or abuse"

''

''=============================================================================



#pragma once







'' include needed libs

#include once "fbgfx.bi"

#include once "GL/gl.bi"

#include once "GL/glu.bi"   



#include once "fbgl2d.bi"   

#include once "fbgl2d.bas"



'' include headers automatically generated by

'' Rel's texture packer

#include once "uvcoord_texturepack.bi"

#include once "uvcoord_bg_8bit.bi"





'' just a simple sub to draw our BG tiles

declare sub draw_bg( images() as GL2D.IMAGE ptr )



#ifndef FALSE

const as integer FALSE = 0

const as integer TRUE = not FALSE

#endif



dim as integer limit_fps = FALSE



print "Limit FPS? Y/N"



dim as string k = ucase(input(1))



select case k

   case "Y"

      limit_fps = TRUE

   case "N"

      limit_fps = FALSE

End Select



const SCR_WIDTH = 640

const SCR_HEIGHT = 480



const as single PI = atn(1)*4

'' set up textures

dim as GLuint texture

dim as GLuint texture_bg





dim as single time_start = 0

dim demosecs as integer

demosecs = 0



'' initialize gl2d

gl2d.screen_init( SCR_WIDTH, SCR_HEIGHT )



''' example of loading a BMP directly to a sprite   

dim as GL2D.IMAGE ptr sprite_sheet = gl2d.load_bmp_to_glsprite("images/texturepack.bmp")



'' set up dynamic array to hold our images

redim as GL2D.IMAGE ptr images(0)

redim as GL2D.IMAGE ptr bgs(0)



'' init spritesheets

gl2d.init_sprites(images(),texturepack_texcoords(),"images/texturepack.bmp")

gl2d.init_sprites(bgs(),bg_8bit_texcoords(),"images/bg_8bit.bmp")







using FB







screencontrol ( SET_WINDOW_TITLE  , "FB.IMAGE compatible Easy GL2D by Relminator" )



dim as integer frame = 0

dim as integer x, y, sprite_frame



sprite_frame = 0

dim as integer frames_per_sec = 0

dim as integer fps = 0



'' UNREM Enable antialias

'  GL2D.enable_antialias()







if limit_fps then

   gl2d.vsync_on()

end if





''===================== FB EXAMPLE FILE TEST ===============================================

'' Got this sprite in the CHM examples

   

   '' make a standard FB image

   dim as any ptr bg = imagecreate(SCR_WIDTH, SCR_HEIGHT, RGBA(0,0,0,255))

   

   dim img as fb.image ptr = imagecreate( 32, 32, rgb(255, 0, 255), 32 )

   circle img, (16, 16), 15, rgb(255, 255, 0),     ,     , 1, f

   circle img, (10, 10), 3,  rgb(  0,   0, 0),     ,     , 2, f

   circle img, (23, 10), 3,  rgb(  0,   0, 0),     ,     , 2, f

   circle img, (16, 18), 10, rgb(  0,   0, 0), 3.14, 6.28



   '' load the sprite to HW (SW data still remains for whatever purposes you want)

   '' Pixel perfect collision FTW!!!

   gl2d.load_image_to_HW(cast(gl2d.image ptr, img))

''================= END FB EXAMPLE FILE TEST ===============================================



do

   

   frames_per_sec += 1

   frame += 1

   if ( (frame and 7) = 0 ) then

      sprite_frame += 1

      if sprite_frame > 2 then sprite_frame = 0

   endif

   

   x = ( ((cos(frame/140) + sin(frame/110)) * (SCR_WIDTH\5)))

   y = ( ((sin(-frame/120) + sin(frame/60)) * (SCR_HEIGHT\5)))

   

   

   '' clear buffer

   gl2d.clear_screen()

   

   '' normal color

   glColor4ub(255,255,255,255)



   

   

   '' draw BG in solid mode

   gl2d.set_blend_mode(GL2D.E_SOLID)

   

   '' draw bg

   draw_bg(bgs())





   '' circle test

   gl2d.circle_2d_filled(100,100,150-abs(sin(frame/25)*150),GL2D_RGBA(0,255,0,255))

   gl2d.circle_2d(100,100,abs(sin(frame/25)*150),GL2D_RGBA(255,255,0,255))

   

   '' Draw black box

   gl2d.set_blend_mode(GL2D.E_SOLID)

   

   GL2D.box_filled(400,40,639,479,GL2D_RGBA(0,0,0,0))



   '' ellipse test

   gl2d.set_blend_mode(GL2D.E_BLENDED)   

   gl2d.ellipse(320, 240, 50, 200, PI/6*5, GL2D_RGBA(255, 128, 64, 255))

   gl2d.ellipse_filled(320, 240, 10+abs(sin(frame/25)*250), 10+250-abs(sin(frame/25)*250), frame/65, GL2D_RGBA(255, 128, 64, 255))



   ''===================== FB EXAMPLE FILE TEST ===============================================



   '' draw our FB example sprite (da happy face)

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite(500,0,cast(gl2d.image ptr,img))



   gl2d.set_blend_mode(GL2D.E_BLENDED)

   glColor4ub(255,255,255,128)

   gl2d.sprite(550,0,cast(gl2d.image ptr,img))

   

   gl2d.set_blend_mode(GL2D.E_SOLID)

   gl2d.sprite(600,0,cast(gl2d.image ptr,img))

   

   

   ''================= END FB EXAMPLE FILE TEST ===============================================



   glColor4ub(255,255,255,255)

   '' transparency drawing

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite(0,0,cast(gl2d.image ptr,sprite_sheet))

   

   dim as single scale = abs(sin(frame/20))

   gl2d.sprite_scale(310,30,scale*3,cast(gl2d.image ptr, images(81)))





   

   '' return to solid for kicks

   gl2d.set_blend_mode(GL2D.E_SOLID)      

   gl2d.sprite(280,30,cast(gl2d.image ptr, images(81)))

      

   

   ''' transparent again

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite(310,30,cast(gl2d.image ptr, images(81)))

   

   

   

   gl2d.sprite(230,300,cast(gl2d.image ptr, images(88)))

   

   

   '' flipped and shadow test

   dim as integer f = 82   

   gl2d.sprite_flip(50,400,GL2D.E_NONE,cast(gl2d.image ptr, images(87 + sprite_frame)))

   gl2d.sprite_flip(50+images(f)->width,400,GL2D.E_H,cast(gl2d.image ptr, images(87 + sprite_frame)))

   glColor4ub(255,255,255,64) '' blend with /14 opacity for shadow fx

   gl2d.set_blend_mode(GL2D.E_BLENDED)

   gl2d.sprite_flip(50,400+images(f)->height,GL2D.E_V,cast(gl2d.image ptr, images(87 + sprite_frame)))

   gl2d.sprite_flip(50+images(f)->width,400+images(f)->height,GL2D.E_VH,cast(gl2d.image ptr, images(87 + sprite_frame)))

   

   

   '' stretch_h test

   gl2d.set_blend_mode(GL2D.E_TRANS)      

   gl2d.sprite_stretch_h(10,290, images(14)->width + abs(sin(frame/30)*400), cast(gl2d.image ptr, images(14)) )

   

   ''' glow

   gl2d.set_blend_mode(GL2D.E_GLOW)

   gl2d.sprite(230,330,cast(gl2d.image ptr, images(88)))

   gl2d.sprite(230,330,cast(gl2d.image ptr, images(88)))

   gl2d.sprite(230,330,cast(gl2d.image ptr, images(88)))

   

   

   glColor4ub(255,255,255,200)  '' 200/256 translucency

   '' alpha blended

   gl2d.set_blend_mode(GL2D.E_BLENDED)

   gl2d.sprite(200,200,cast(gl2d.image ptr, images(32)))

   

   gl2d.sprite(200,400,cast(gl2d.image ptr, images(81)))

   

   

   '' transparent

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite_rotate(SCR_WIDTH\2,SCR_HEIGHT\2,frame*3,cast(gl2d.image ptr, images(30)))

      

   '' alpha blended

   gl2d.set_blend_mode(GL2D.E_BLENDED)

   gl2d.sprite_rotate_scale(SCR_WIDTH\2,SCR_HEIGHT\2,frame*3,5-scale*5,cast(gl2d.image ptr, images(30)))

   gl2d.sprite_rotate(SCR_WIDTH\2 + 30,SCR_HEIGHT\2,-frame*3,cast(gl2d.image ptr, images(30)))

   

   '' black mode

   glColor4ub(255,255,255,255)

   gl2d.set_blend_mode(GL2D.E_BLACK)

   gl2d.sprite(30,130,cast(gl2d.image ptr, images(81)))

   

   

   '' color mode

   glColor4ub(255,0,0,255)

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite(130,130,cast(gl2d.image ptr, images(81)))

   

   gl2d.set_blend_mode(GL2D.E_BLENDED)

   gl2d.sprite(230,130,cast(gl2d.image ptr, images(81)))

   

   glColor4ub(255,0,255,255)

   gl2d.set_blend_mode(GL2D.E_GLOW)

   gl2d.sprite(30,330,cast(gl2d.image ptr, images(32)))



   '' free stretching test

   dim as integer x1 = (SCR_WIDTH\2+200) + x\2

   dim as integer x2 = (SCR_WIDTH\2+200) - x\2

   dim as integer y1 = (SCR_HEIGHT\2) + y\2

   dim as integer y2 = (SCR_HEIGHT\2) - y\2

   glColor4ub(255,255,255,255)

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite_stretch(x1, y1, x2, y2,cast(gl2d.image ptr, images(81)))



   

   '' back to standard coloring

   '' and draw our animated sprite

   glColor4ub(255,255,255,128)      '' factor of 128 blending

   '' trans

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite((SCR_WIDTH\2) + x,(SCR_HEIGHT\2) + y,cast(gl2d.image ptr, images(87 + sprite_frame)))

   '' blended

   gl2d.set_blend_mode(GL2D.E_BLENDED)

   gl2d.sprite((SCR_WIDTH\2) - x,(SCR_HEIGHT\2) + y,cast(gl2d.image ptr, images(87 + sprite_frame)))

   '' green colored blended by 128/256

   glcolor4ub(0,255,0,128)

   gl2d.sprite((SCR_WIDTH\2) - x,(SCR_HEIGHT\2) - y,cast(gl2d.image ptr, images(87 + sprite_frame)))

   '' back to trans but colored

   gl2d.set_blend_mode(GL2D.E_TRANS)

   gl2d.sprite((SCR_WIDTH\2) + x,(SCR_HEIGHT\2) - y,cast(gl2d.image ptr, images(87 + sprite_frame)))

   

   

   '' test gradient box

   GL2D.box_filled_gradient(420,350,560,460,_

                           GL2D_RGBA(0,255,255,255),_

                      GL2D_RGBA(255,255,0,255),_

                      GL2D_RGBA(255,255,255,255),_

                      GL2D_RGBA(255,0,255,255))

   

   

   

    gl2d.set_blend_mode(GL2D.E_GLOW)

    ' draw 3 blended lines with decreasing widths to

    ' make the effect  better.

   gl2d.line_glow (320,290,620,290,20,GL2D_RGBA(128,32,225,128))

   gl2d.line_glow (320,290,620,290,15,GL2D_RGBA(128,32,225,200))

   gl2d.line_glow (320,290,620,290,10,GL2D_RGBA(128,32,225,255))



   ''  draw just a single glowline

   gl2d.line_glow (320,290,620,425,40,GL2D_RGBA(255,32,2,255))

   

   '' draw a solid line

   gl2d.line_2d (620,290,620,425,GL2D_RGBA(255,255,0,255))



   gl2d.set_blend_mode(GL2D.E_SOLID)

   

   '' box

   GL2D.box(400,40,639,479,GL2D_RGBA(220,255,55,0))

   

   '' triangle test

   gl2d.triangle(480,100,630,50,560,200,GL2D_RGBA(25,2,255,255))

   GL2D.Triangle_filled(490,105,610,60,590,135,GL2D_RGBA(255,255,255,255))

   

   glColor4ub(255,255,255,64)      '' factor of 64/256 blending

   gl2d.set_blend_mode(GL2D.E_BLENDED)

   GL2D.Triangle_filled_gradient(290,150,510,60,490,135,_

                          GL2D_RGBA(0,255,255,255),_

                          GL2D_RGBA(255,255,0,255),_

                          GL2D_RGBA(255,0,255,255))

   

   gl2d.set_blend_mode(GL2D.E_SOLID)  '' back to solid

   glColor4ub(255,255,255,255)      '' Opaque again

   '' pset test

   for i as integer = 0 to 359 step 10

      dim as integer px = 20 * cos(i*PI/180)

      dim as integer py = 20 * sin(i*PI/180)

      gl2d.put_pixel(430+px,70+py,GL2D_RGBA(255,2,255,255))

   next i

   

   

   gl2d.set_blend_mode(GL2D.E_GLOW)

   '' glow lines on steroids

   for i as integer = frame to 359+frame step 20

      dim as integer px = 120 * cos(i*PI/180)

      dim as integer py = 120 * sin(i*PI/180)

      dim as integer px2 = 120 * cos((i+20)*PI/180)

      dim as integer py2 = 120 * sin((i+20)*PI/180)

      dim as integer adder = abs(7*sin(frame/20))

      for j as integer= 0 to adder

         gl2d.line_glow (320+px,240+py,320+px2,240+py2,20-(adder*2),GL2D_RGBA(255+frame,255-frame,128+frame,255))

      next j

   next i



   

   dim as single timer_elapsed = (timer - demosecs)

   time_start =  timer

   if timer_elapsed > 1 then

      fps = frames_per_sec/timer_elapsed

      frames_per_sec = 0

       demosecs = timer

   end if

   

   

   '' Test print

   gl2d.set_blend_mode(GL2D.E_TRANS)   '' blended

   glColor4ub(255,255,255,255)  '' no transluceny

   gl2d.print_scale(40, 10,2, "Easy GL2D by Relminator    FPS = " + str(fps))





    flip

   

   

   sleep 1,1

Loop Until Multikey( FB.SC_ESCAPE )





gl2d.destroy_sprites(images())

gl2d.destroy_sprites(bgs())

'' destroy da happy face

gl2d.destroy_image(img)

gl2d.destroy()



end





'' A little sub to draw the BG

sub draw_bg( images() as GL2D.IMAGE ptr )

   

   const as integer index = 1

   dim as integer tiles_x = SCR_WIDTH\images(index)->width

   dim as integer tiles_Y = SCR_HEIGHT\images(index)->height

   

   gl2d.set_blend_mode(GL2D.E_SOLID)

         

   for y as integer = 0 to tiles_y

      for x as integer = 0 to tiles_x

         gl2d.sprite(x * images(index)->width,y * images(index)->height,cast(gl2d.image ptr, images(index)))

      next x

   next y

   

end sub



pixel_perfect_collision.bas:

Code: Select all

''=============================================================================

''

''    Easy GL2D (FB.IMAGE compatible version)

''    By Relminator (Richard Eric M. Lope)

''    http://rel.betterwebber.com

''   

''    An easy to use OpenGL 2d lib

''    As easy as fbgfx (easier IMHO if you use my Texture packer)

''   

''    Can automatically load BMP's supported by BLOAD

''    Adds alpha transparency if you want

''    No external dependencies (only uses OpenGL/GLU and FBGFX)

''    Source license is "use or abuse"

''

''=============================================================================



#pragma once







'' include needed libs

#include once "fbgfx.bi"

#include once "GL/gl.bi"

#include once "GL/glu.bi"   



#include once "fbgl2d.bi"   

#include once "fbgl2d.bas"



'' include headers automatically generated by

'' Rel's texture packer

#include once "uvcoord_texturepack.bi"

#include once "uvcoord_bg_8bit.bi"





'' just a simple sub to draw our BG tiles

declare sub draw_bg( images() as GL2D.IMAGE ptr )



#ifndef FALSE

const as integer FALSE = 0

const as integer TRUE = not FALSE

#endif



dim as integer limit_fps = FALSE



print "Limit FPS? Y/N"



dim as string k = ucase(input(1))



select case k

    case "Y"

        limit_fps = TRUE

    case "N"

        limit_fps = FALSE

End Select



const SCR_WIDTH = 640

const SCR_HEIGHT = 480



const as single PI = atn(1)*4

'' set up textures

dim as GLuint texture

dim as GLuint texture_bg





dim as single time_start = 0

dim demosecs as integer

demosecs = 0



'' initialize gl2d

gl2d.screen_init( SCR_WIDTH, SCR_HEIGHT )



''' example of loading a BMP directly to a sprite   

dim as GL2D.IMAGE ptr sprite_sheet = gl2d.load_bmp_to_glsprite("images/texturepack.bmp")



'' set up dynamic array to hold our images

redim as GL2D.IMAGE ptr images(0)

redim as GL2D.IMAGE ptr bgs(0)



'' init spritesheets

gl2d.init_sprites(images(),texturepack_texcoords(),"images/texturepack.bmp")

gl2d.init_sprites(bgs(),bg_8bit_texcoords(),"images/bg_8bit.bmp")







using FB







screencontrol ( SET_WINDOW_TITLE  , "FB.IMAGE compatible Easy GL2D by Relminator" )



dim as integer frame = 0

dim as integer x, y, sprite_frame



sprite_frame = 0

dim as integer frames_per_sec = 0

dim as integer fps = 0



'' UNREM Enable antialias

'  GL2D.enable_antialias()







if limit_fps then

    gl2d.vsync_on()

end if





''===================== FB EXAMPLE FILE TEST ===============================================

'' Got this sprite in the CHM examples

   

    '' make a standard FB image

    dim as any ptr bg = imagecreate(SCR_WIDTH, SCR_HEIGHT, RGBA(0,0,0,255))

   

    dim img as fb.image ptr = imagecreate( 32, 32, rgb(255, 0, 255), 32 )

    circle img, (16, 16), 15, rgb(255, 255, 0),     ,     , 1, f

    circle img, (10, 10), 3,  rgb(  0,   0, 0),     ,     , 2, f

    circle img, (23, 10), 3,  rgb(  0,   0, 0),     ,     , 2, f

    circle img, (16, 18), 10, rgb(  0,   0, 0), 3.14, 6.28



    '' load the sprite to HW (SW data still remains for whatever purposes you want)

    '' Pixel perfect collision FTW!!!

    gl2d.load_image_to_HW(cast(gl2d.image ptr, img))

''================= END FB EXAMPLE FILE TEST ===============================================



do

   

    frames_per_sec += 1

    frame += 1

    if ( (frame and 7) = 0 ) then

        sprite_frame += 1

        if sprite_frame > 2 then sprite_frame = 0

    endif

   

    x = ( ((cos(frame/140) + sin(frame/110)) * (SCR_WIDTH\5)))

    y = ( ((sin(-frame/120) + sin(frame/60)) * (SCR_HEIGHT\5)))

   

   

    '' clear buffer

    gl2d.clear_screen()

   

    '' normal color

    glColor4ub(255,255,255,255)



   

   

    '' draw BG in solid mode

    gl2d.set_blend_mode(GL2D.E_SOLID)

   

    '' draw bg

    draw_bg(bgs())





    '' circle test

    gl2d.circle_2d_filled(100,100,150-abs(sin(frame/25)*150),GL2D_RGBA(0,255,0,255))

    gl2d.circle_2d(100,100,abs(sin(frame/25)*150),GL2D_RGBA(255,255,0,255))

   

    '' Draw black box

    gl2d.set_blend_mode(GL2D.E_SOLID)

   

    GL2D.box_filled(400,40,639,479,GL2D_RGBA(0,0,0,0))



    '' ellipse test

    gl2d.set_blend_mode(GL2D.E_BLENDED)   

    gl2d.ellipse(320, 240, 50, 200, PI/6*5, GL2D_RGBA(255, 128, 64, 255))

    gl2d.ellipse_filled(320, 240, 10+abs(sin(frame/25)*250), 10+250-abs(sin(frame/25)*250), frame/65, GL2D_RGBA(255, 128, 64, 255))



    ''===================== FB EXAMPLE FILE TEST ===============================================



    '' draw our FB example sprite (da happy face)

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite(500,0,cast(gl2d.image ptr,img))



    gl2d.set_blend_mode(GL2D.E_BLENDED)

    glColor4ub(255,255,255,128)

    gl2d.sprite(550,0,cast(gl2d.image ptr,img))

   

    gl2d.set_blend_mode(GL2D.E_SOLID)

    gl2d.sprite(600,0,cast(gl2d.image ptr,img))

   

   

    ''================= END FB EXAMPLE FILE TEST ===============================================



    glColor4ub(255,255,255,255)

    '' transparency drawing

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite(0,0,cast(gl2d.image ptr,sprite_sheet))

   

    dim as single scale = abs(sin(frame/20))

    gl2d.sprite_scale(310,30,scale*3,cast(gl2d.image ptr, images(81)))





   

    '' return to solid for kicks

    gl2d.set_blend_mode(GL2D.E_SOLID)       

    gl2d.sprite(280,30,cast(gl2d.image ptr, images(81)))

       

   

    ''' transparent again

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite(310,30,cast(gl2d.image ptr, images(81)))

   

   

   

    gl2d.sprite(230,300,cast(gl2d.image ptr, images(88)))

   

   

    '' flipped and shadow test

    dim as integer f = 82   

    gl2d.sprite_flip(50,400,GL2D.E_NONE,cast(gl2d.image ptr, images(87 + sprite_frame)))

    gl2d.sprite_flip(50+images(f)->width,400,GL2D.E_H,cast(gl2d.image ptr, images(87 + sprite_frame)))

    glColor4ub(255,255,255,64) '' blend with /14 opacity for shadow fx

    gl2d.set_blend_mode(GL2D.E_BLENDED)

    gl2d.sprite_flip(50,400+images(f)->height,GL2D.E_V,cast(gl2d.image ptr, images(87 + sprite_frame)))

    gl2d.sprite_flip(50+images(f)->width,400+images(f)->height,GL2D.E_VH,cast(gl2d.image ptr, images(87 + sprite_frame)))

   

   

    '' stretch_h test

    gl2d.set_blend_mode(GL2D.E_TRANS)       

    gl2d.sprite_stretch_h(10,290, images(14)->width + abs(sin(frame/30)*400), cast(gl2d.image ptr, images(14)) )

   

    ''' glow

    gl2d.set_blend_mode(GL2D.E_GLOW)

    gl2d.sprite(230,330,cast(gl2d.image ptr, images(88)))

    gl2d.sprite(230,330,cast(gl2d.image ptr, images(88)))

    gl2d.sprite(230,330,cast(gl2d.image ptr, images(88)))

   

   

    glColor4ub(255,255,255,200)  '' 200/256 translucency

    '' alpha blended

    gl2d.set_blend_mode(GL2D.E_BLENDED)

    gl2d.sprite(200,200,cast(gl2d.image ptr, images(32)))

   

    gl2d.sprite(200,400,cast(gl2d.image ptr, images(81)))

   

   

    '' transparent

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite_rotate(SCR_WIDTH\2,SCR_HEIGHT\2,frame*3,cast(gl2d.image ptr, images(30)))

       

    '' alpha blended

    gl2d.set_blend_mode(GL2D.E_BLENDED)

    gl2d.sprite_rotate_scale(SCR_WIDTH\2,SCR_HEIGHT\2,frame*3,5-scale*5,cast(gl2d.image ptr, images(30)))

    gl2d.sprite_rotate(SCR_WIDTH\2 + 30,SCR_HEIGHT\2,-frame*3,cast(gl2d.image ptr, images(30)))

   

    '' black mode

    glColor4ub(255,255,255,255)

    gl2d.set_blend_mode(GL2D.E_BLACK)

    gl2d.sprite(30,130,cast(gl2d.image ptr, images(81)))

   

   

    '' color mode

    glColor4ub(255,0,0,255)

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite(130,130,cast(gl2d.image ptr, images(81)))

   

    gl2d.set_blend_mode(GL2D.E_BLENDED)

    gl2d.sprite(230,130,cast(gl2d.image ptr, images(81)))

   

    glColor4ub(255,0,255,255)

    gl2d.set_blend_mode(GL2D.E_GLOW)

    gl2d.sprite(30,330,cast(gl2d.image ptr, images(32)))



    '' free stretching test

    dim as integer x1 = (SCR_WIDTH\2+200) + x\2

    dim as integer x2 = (SCR_WIDTH\2+200) - x\2

    dim as integer y1 = (SCR_HEIGHT\2) + y\2

    dim as integer y2 = (SCR_HEIGHT\2) - y\2

    glColor4ub(255,255,255,255)

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite_stretch(x1, y1, x2, y2,cast(gl2d.image ptr, images(81)))



   

    '' back to standard coloring

    '' and draw our animated sprite

    glColor4ub(255,255,255,128)        '' factor of 128 blending

    '' trans

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite((SCR_WIDTH\2) + x,(SCR_HEIGHT\2) + y,cast(gl2d.image ptr, images(87 + sprite_frame)))

    '' blended

    gl2d.set_blend_mode(GL2D.E_BLENDED)

    gl2d.sprite((SCR_WIDTH\2) - x,(SCR_HEIGHT\2) + y,cast(gl2d.image ptr, images(87 + sprite_frame)))

    '' green colored blended by 128/256

    glcolor4ub(0,255,0,128)

    gl2d.sprite((SCR_WIDTH\2) - x,(SCR_HEIGHT\2) - y,cast(gl2d.image ptr, images(87 + sprite_frame)))

    '' back to trans but colored

    gl2d.set_blend_mode(GL2D.E_TRANS)

    gl2d.sprite((SCR_WIDTH\2) + x,(SCR_HEIGHT\2) - y,cast(gl2d.image ptr, images(87 + sprite_frame)))

   

   

    '' test gradient box

    GL2D.box_filled_gradient(420,350,560,460,_

                                  GL2D_RGBA(0,255,255,255),_

                             GL2D_RGBA(255,255,0,255),_

                             GL2D_RGBA(255,255,255,255),_

                             GL2D_RGBA(255,0,255,255))

   

   

   

    gl2d.set_blend_mode(GL2D.E_GLOW)

    ' draw 3 blended lines with decreasing widths to

    ' make the effect  better.

    gl2d.line_glow (320,290,620,290,20,GL2D_RGBA(128,32,225,128))

    gl2d.line_glow (320,290,620,290,15,GL2D_RGBA(128,32,225,200))

    gl2d.line_glow (320,290,620,290,10,GL2D_RGBA(128,32,225,255))



    ''  draw just a single glowline

    gl2d.line_glow (320,290,620,425,40,GL2D_RGBA(255,32,2,255))

   

    '' draw a solid line

    gl2d.line_2d (620,290,620,425,GL2D_RGBA(255,255,0,255))



    gl2d.set_blend_mode(GL2D.E_SOLID)

   

    '' box

    GL2D.box(400,40,639,479,GL2D_RGBA(220,255,55,0))

   

    '' triangle test

    gl2d.triangle(480,100,630,50,560,200,GL2D_RGBA(25,2,255,255))

    GL2D.Triangle_filled(490,105,610,60,590,135,GL2D_RGBA(255,255,255,255))

   

    glColor4ub(255,255,255,64)        '' factor of 64/256 blending

    gl2d.set_blend_mode(GL2D.E_BLENDED)

    GL2D.Triangle_filled_gradient(290,150,510,60,490,135,_

                                  GL2D_RGBA(0,255,255,255),_

                                  GL2D_RGBA(255,255,0,255),_

                                  GL2D_RGBA(255,0,255,255))

   

    gl2d.set_blend_mode(GL2D.E_SOLID)  '' back to solid

    glColor4ub(255,255,255,255)        '' Opaque again

    '' pset test

    for i as integer = 0 to 359 step 10

        dim as integer px = 20 * cos(i*PI/180)

        dim as integer py = 20 * sin(i*PI/180)

        gl2d.put_pixel(430+px,70+py,GL2D_RGBA(255,2,255,255))

    next i

   

   

    gl2d.set_blend_mode(GL2D.E_GLOW)

    '' glow lines on steroids

    for i as integer = frame to 359+frame step 20

        dim as integer px = 120 * cos(i*PI/180)

        dim as integer py = 120 * sin(i*PI/180)

        dim as integer px2 = 120 * cos((i+20)*PI/180)

        dim as integer py2 = 120 * sin((i+20)*PI/180)

        dim as integer adder = abs(7*sin(frame/20))

        for j as integer= 0 to adder

            gl2d.line_glow (320+px,240+py,320+px2,240+py2,20-(adder*2),GL2D_RGBA(255+frame,255-frame,128+frame,255))

        next j

    next i



   

    dim as single timer_elapsed = (timer - demosecs)

    time_start =  timer

    if timer_elapsed > 1 then

        fps = frames_per_sec/timer_elapsed

        frames_per_sec = 0

        demosecs = timer

    end if

   

   

    '' Test print

    gl2d.set_blend_mode(GL2D.E_TRANS)   '' blended

    glColor4ub(255,255,255,255)  '' no transluceny

    gl2d.print_scale(40, 10,2, "Easy GL2D by Relminator    FPS = " + str(fps))





    flip

   

   

    sleep 1,1

Loop Until Multikey( FB.SC_ESCAPE )





gl2d.destroy_sprites(images())

gl2d.destroy_sprites(bgs())

'' destroy da happy face

gl2d.destroy_image(img)

gl2d.destroy()



end





'' A little sub to draw the BG

sub draw_bg( images() as GL2D.IMAGE ptr )

   

    const as integer index = 1

    dim as integer tiles_x = SCR_WIDTH\images(index)->width

    dim as integer tiles_Y = SCR_HEIGHT\images(index)->height

   

    gl2d.set_blend_mode(GL2D.E_SOLID)

           

    for y as integer = 0 to tiles_y

        for x as integer = 0 to tiles_x

            gl2d.sprite(x * images(index)->width,y * images(index)->height,cast(gl2d.image ptr, images(index)))

        next x

    next y

   

end sub



Tried debugging pixel_perfect_collision:

Code: Select all

galeon@galeon-desktop:~$ cd /home/galeon/Downloads/fb_image_compatible
galeon@galeon-desktop:~/Downloads/fb_image_compatible$ fbc -g pixel_perfect_collision.bas
galeon@galeon-desktop:~/Downloads/fb_image_compatible$ gdb pixel_perfect_collision
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/galeon/Downloads/fb_image_compatible/pixel_perfect_collision...done.
(gdb) r
Starting program: /home/galeon/Downloads/fb_image_compatible/pixel_perfect_collision
[Thread debugging using libthread_db enabled]
[New Thread 0x1793b70 (LWP 12276)]
Limit FPS? Y/N

Program received signal SIGSEGV, Segmentation fault.
0x0804e3e5 in GL2D::LOAD_IMAGE_24BIT_ALPHA (SPR=<error reading variable>, FILTER_MODE=<error reading variable>)
    at /home/galeon/Downloads/fb_image_compatible/fbgl2d.bas:1531
1531               for y as integer = 0 to temp->height-1
(gdb) bt
#0  0x0804e3e5 in GL2D::LOAD_IMAGE_24BIT_ALPHA (SPR=<error reading variable>, FILTER_MODE=<error reading variable>)
    at /home/galeon/Downloads/fb_image_compatible/fbgl2d.bas:1531
#1  0x0804ffbb in GL2D::FONT_INIT () at /home/galeon/Downloads/fb_image_compatible/fbgl2d.bas:112
#2  0x0804c0e3 in GL2D::SCREEN_INIT (SCREEN_WID=<error reading variable>, SCREEN_HEI=<error reading variable>,
    FLAGS=<error reading variable>) at /home/galeon/Downloads/fb_image_compatible/fbgl2d.bas:252
#3  0x0804f9b0 in main (__FB_ARGC__=<error reading variable>, __FB_ARGV__=<error reading variable>)
    at pixel_perfect_collision.bas:283
(gdb)


System Info:
OS: Ubuntu Linux 10.04.1 (x86)
CPU: Pentium IV, 2.8 GHz
Video Card: GeForce4 Ti 4200 with AGP8X (64 MB)
NVIDIA Driver Version: 96.43.17 (from Ubuntu)
FBC: v0.21.1, standalone

Note: I think my driver works correctly because I use compiz.
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 05, 2010 15:42

Rel, are you online?!
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Postby relsoft » Oct 05, 2010 16:10

Yep. Wow! I didn't notice you made some tests.

Thanks! This would be useful. Though I haven't been coding since I got hospitalized with food poisoning (red-tide).

*I'm going to undergo some blood test and an ultrasound tomorrow morning since the toxins apparently messed my digestion.
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 06, 2010 1:43

Oh,
I have asked in the IRC and Dr_D and yetifoot said that they don't think it is something to do with my OpenGL libraries, the problem is that ScreenCreate returns NULL. I will try to compile it using different FBC versions later.
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Postby relsoft » Oct 06, 2010 2:24

Thanks!
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 06, 2010 4:48

I tried it in 0.21.1, 0.21.0 and 0.20.0b, both in prefix and standalone:

In versions 0.21.1 and 0.21.0, both in prefix and standalone, gl2d_test.bas and pixel_perfect_collision.bas have segmentation fault.

In version 0.20.0b, both in prefix and standalone, gl2d_test.bas works while pixel_perfect_collision.bas have segmentation fault when it reached the time when "Back in FBGFX" should be shown.

The compiled ones included in fbgl2d_v5.zip, tested using Wine, didn't caused any segmentation faults.

FPS (0.20.0b) in Linux:
gl2d_test.bas - ~425 (highest: 440)
pixel_perfect_collision.bas - ~585 (highest: 732)

FPS (included with fbgl2d_v5.zip) using Wine 1.3.4-0ubuntu1~lucidppa1 in Ubuntu Linux:
gl2d_test.bas - ~298 (highest: 303)
pixel_perfect_collision - ~570 (highest: 610)

Note that I am currently using Compiz Fusion (Visual Effects). It might go higher, not sure though, I don't want to turn it off :).

In Windows XP (with drivers), I only get ~60 FPS :(.

So it seems that it is a FreeBASIC bug that only affects Linux target since version 0.21.0.

This is where the real problem happens:

fbgl2d.bas:

Code: Select all

103    dim as any ptr image = imagecreate(128,128,RGBA(255,0,255,0))

It seems that it returns NULL, which causes segmentation fault in function load_image_24bit_alpha.
Last edited by Galeon on Oct 06, 2010 5:11, edited 1 time in total.
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 06, 2010 4:50

Debugging pixel_perfect_collision.bas:

Code: Select all

galeon@galeon-desktop:~/Downloads/fb_image_compatible$ fbc -g pixel_perfect_collision.bas
galeon@galeon-desktop:~/Downloads/fb_image_compatible$ gdb pixel_perfect_collision
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/galeon/Downloads/fb_image_compatible/pixel_perfect_collision...done.
(gdb) r
Starting program: /home/galeon/Downloads/fb_image_compatible/pixel_perfect_collision
[Thread debugging using libthread_db enabled]
[New Thread 0x1793b70 (LWP 3326)]
Limit FPS? Y/N
[New Thread 0x25ddb70 (LWP 3327)]
[Thread 0x25ddb70 (LWP 3327) exited]
[New Thread 0x25ddb70 (LWP 3328)]

Program received signal SIGSEGV, Segmentation fault.
0x0805be44 in trans4_x_loop ()
(gdb) bt
#0  0x0805be44 in trans4_x_loop ()
#1  0x0000021c in ?? ()
#2  0x08117940 in ?? ()
#3  0x080582fa in fb_GfxPut ()
#4  0x0804fd94 in main (__FB_ARGC__=<error reading variable>,
    __FB_ARGV__=<error reading variable>) at pixel_perfect_collision.bas:403
(gdb)


This is what causes the problem:
pixel_perfect_collision.bas:

Code: Select all

403 put(100,100), img, trans
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 06, 2010 13:02

Seems to be already fixed in SVN! Both of the bugs!
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Oct 06, 2010 22:48

Any chance for a glow_circle function?
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Postby relsoft » Oct 08, 2010 3:20

Galeon wrote:Seems to be already fixed in SVN! Both of the bugs!


Pre, what do you mean? FB had the bug and not GL2D?


Dean: You could emulate glowcircle by a bunch of glowlines. Or you could use the glowsprite technique I wrote for back2basic2.

I haven't been coding these past weeks since I got hit by food poisoning. What I've been doing now is going back and forth to the labs for tests.
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Postby Galeon » Oct 08, 2010 14:22

relsoft wrote:
Galeon wrote:Seems to be already fixed in SVN! Both of the bugs!


Pre, what do you mean? FB had the bug and not GL2D?



Yes, it seems that its a bug in FBGFX, but the smiley in "Back to FBGFX" screen in pixel_perfect_collision is not showing up, both in Ubuntu Linux and Wine. Maybe it is also a bug in FBGFX.

Also, the FPS in Ubuntu and Wine is very far from the one I get in Windows XP, 750 vs. 60, and it has the latest drivers for nVidia GeForce 4.
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Postby relsoft » Oct 09, 2010 0:52

Galeon wrote:
relsoft wrote:
Galeon wrote:Seems to be already fixed in SVN! Both of the bugs!


Pre, what do you mean? FB had the bug and not GL2D?



Yes, it seems that its a bug in FBGFX, but the smiley in "Back to FBGFX" screen in pixel_perfect_collision is not showing up, both in Ubuntu Linux and Wine. Maybe it is also a bug in FBGFX.

Also, the FPS in Ubuntu and Wine is very far from the one I get in Windows XP, 750 vs. 60, and it has the latest drivers for nVidia GeForce 4.


No, it's not an FBGFX bug but a bug from my own code. I deleted the image before going back to fbgfx so it's not even supposed to be legal code.

It seems that the HW vsynch function does not work on *nix. It should cap at 60 FPS on both linux and windows.

Thanks for the test pre.
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Postby mrToad » Oct 09, 2010 1:57

Thanks for this awesome work with GL, relsoft. I'm sure I will be using it! How are you doing with the poisoning? Sounds painful. Hope you feel better soon.
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Postby relsoft » Oct 09, 2010 2:17

I'm getting better. I still get stomach cramps after eating but it's tolerable. I just can't sit for long that's why I'm typing standing-up right now.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 7 guests