Author Topic: Bmax Framebuffer Lib[BMAX]  (Read 7884 times)

0 Members and 1 Guest are viewing this topic.

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Bmax Framebuffer Lib[BMAX]
« on: September 27, 2006 »
Ok here is my first attempt at getting a opengl based framebuffer lib working, it seems to be functioning as expected so I will attempt to convert a couple of examples over from Freebasic.

First the include. Save it as bmaxptc.bmx

Code: [Select]
'-----------------------------------------------------------------------------------------------------
'
' OpenGL Frame Buffer Lib By Joncom2000 of The Tin Dragons
'
' Based on code by Jim Shaw & Rbaz, Inspired by TinyPTC by Gaffer.
'
'-----------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------
' Globals used by the lib to store screen size
'----------------------------------------------------------------------------------------------
Global g_w:Int
Global g_h:Int
'-----------------------------------------------------------------------------------------------------
' Place Functions after this
'-----------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------
' NAME : ptc_open()
' PURPOSE : This function opens the display
' INPUTS : Title, width and height for screen Also hertz
' RETURNS : nothing
' NOTES : N/A
'------------------------------------------------------------------------
Function ptc_open(Title$,width=640,height=480,Hertz=60)
'Set globals
g_w=width
g_h=height
'open screen
GLGraphics(g_w,g_h,32,Hertz, GRAPHICS_BACKBUFFER)
AppTitle$=Title$
glViewport(0, 0, g_w,g_h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0,g_w,g_h,0,0,1)
glPixelZoom(1,-1)
glRasterPos2i(0,0)
End Function
'------------------------------------------------------------------------
' NAME : ptc_update()
' PURPOSE : This function updates the display
' INPUTS : pixel buffer pointer
' RETURNS : nothing
' NOTES : N/A
'------------------------------------------------------------------------
Function ptc_update(pBuffer:Byte Ptr)
glDrawPixels(g_w,g_h,GL_BGRA_EXT,GL_UNSIGNED_BYTE,pBuffer)
Flip
End Function
'------------------------------------------------------------------------
' NAME : ptc_close()
' PURPOSE : This function closes the display
' INPUTS : none
' RETURNS : update
' NOTES : N/A
'------------------------------------------------------------------------
Function ptc_close()
' Doesnt seem needed but I might add cleanup code at some point if needed
End Function

And a small demo of how to use it, note that I am using an array to store the buffer info it may work with other types of storage like banks but I have not tested that as I like to keep things simple :)

Code: [Select]
'-----------------------------------------------------------------------------------------------------
'
' The Tin Dragons - OpenGL Frame Buffer test By Joncom2000
'
'-----------------------------------------------------------------------------------------------------
Include "bmaxptc.bmx"

ptc_open("Test",640,480,60)

Global pixels:Int[640*480]

Repeat
For p=0 To 640*480
col=Rand(255)
pixels[p]=col Shl 16+col Shl 8 + col
Next
ptc_update(Varptr(Pixels[0]))
Until KeyDown(KEY_ESCAPE)
End

Oh and one final note, the info is passed to opengl in BGRA format, not the RGB format that most blitzers will be use to but this is to keep the lib inline with the one developed by Jim & Rbaz for use with FB. Also the ptc_update function automaticly flips the screen so none of the standard gl commands will work with it. This can all be changed should anyone want to or ask me if you want a custom version and I will see what I can do ;)

« Last Edit: July 21, 2007 by Shockwave »

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Bmax Framebuffer Lib
« Reply #1 on: September 27, 2006 »
Here's a Rotozoom style example for the framebuffer lib.

Code: [Select]
'-----------------------------------------------------------------------------------------------------
'
' Rotozoom Example for framebuffer lib
'
'-----------------------------------------------------------------------------------------------------
Include "bmaxptc.bmx"

ptc_open("Rotozoom",640,480,60)
HideMouse
Global pixels:Int[640*480]

Repeat
ang#=ang#+0.5
c=750*Cos(ang#)
xo=200+200*Sin(ang#*2)
yo=200+200*Cos(ang#*3)
For y=0 To 479
For x=0 To 639
i=x+xo-320
j=y+yo-240
col=((i+j*c/256) & 255) ~ ((j-i*c/256) & 255)
pixels[x+(y*640)]=col
Next
Next
ptc_update(Varptr(Pixels[0]))
Until KeyDown(KEY_ESCAPE)
End

Enjoy and I will attach an exe for those none bmax owns later.


Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Bmax Framebuffer Lib
« Reply #2 on: September 27, 2006 »
Looking forward to see the exe files...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Bmax Framebuffer Lib
« Reply #3 on: September 27, 2006 »
I am one of those non bmax owners so I'll look forward to seeing the exes :) Nice work Jon.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Bmax Framebuffer Lib
« Reply #4 on: September 27, 2006 »
For some reason I cant get the code to work when I try using a framework to reduce the amount of stuff included in the exe, resulting in it currently producing bloated exe's only. Not sure why this is yet as I have not had any problems like this before  ???

Which means I cant attach the exe as the file size is to big and I dont currently have any webspace to host files on.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #5 on: September 27, 2006 »
Looks cool Joncom, will try it out once I've re-installed BMAX.

Thumbs up,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #6 on: September 28, 2006 »
Good stuff TinDragon!  Sorry I can't help with your bmax problem.

If you change
Code: [Select]
glDrawPixels(g_w,g_h,GL_BGRA_EXT,GL_UNSIGNED_BYTE,pBuffer)to
Code: [Select]
glDrawPixels(g_w,g_h,GL_RGBA,GL_UNSIGNED_BYTE,pBuffer)it'll convert the pixels the other way round.  If that's more convenient?

Jim
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Bmax Framebuffer Lib
« Reply #7 on: September 28, 2006 »
No worries Jim, I think I just have to work out which include lib I am missing and it will work I hope  :D

As for the rgb, bgr order, well I left the code I posted that way round as it matched the code in the lib you and rbaz posted and I thought it might make it easier to convert routines between the languages should anyone want to and I suspect a couple people might. Once I can workout the import problem I can hopefully make better size exe's rather than 440kb compressed.

Myself I might look to do some stuff in C/C++ using this idea as I need to brush up as I havent done any in ages :)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Bmax Framebuffer Lib
« Reply #8 on: September 28, 2006 »
The upload limit is 750kb at the moment mind Jon.
I haven't changed it back to 250kb yet :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Bmax Framebuffer Lib
« Reply #9 on: September 28, 2006 »
@Shockwave,  Didnt know that but to be honest I dont think it's worth wasting the bandwidth on the exe's since there not that impressive (yet ;) )  and hopefully I can work out whats gone wrong with the framework thing :)

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #10 on: September 29, 2006 »
I took at look at that framework problem last night, but couldn't crack it either. Just getting a black screen with nothing going on. It doesn't crash or anything. I will probably give it another try during the weekend.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #11 on: September 29, 2006 »
Do you need to tell BMAX which rendering method you want to use; DirectX or OGL?
Dont know it thats of any use to you.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Dad1916

  • Atari ST
  • ***
  • Posts: 112
  • Karma: 3
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #12 on: September 30, 2006 »
I tried the first code which compiles and links fine but I get this error
Code: [Select]
Unhandled Exception:Attempt to index array element beyond array length upon execution.

Code: [Select]
Building demo
Executing:demo.debug
Unhandled Exception:Attempt to index array element beyond array length

I tried TinDragon's Rotozoom style example code but also just get a black screen when executing.
« Last Edit: September 30, 2006 by rootuid »

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #13 on: September 30, 2006 »
It works fine on my setup. I am using the latest v1.22 of bmax, what version are you trying it with?

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #14 on: October 01, 2006 »
Code: [Select]
Global pixels:Int[640*480]
...
For p=0 To 640*480
In both C and Freebasic, that's one array entry too many.  Is that the problem here?

Jim
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Bmax Framebuffer Lib
« Reply #15 on: October 01, 2006 »
well the rotozoom doesn't do it that way Jim so it cant be the error with that one but it probably should generate an error in the first code  :-[ But it actually runs fine on my system and zawrans which is strange.

@Rootuid, are you trying to use a framework or just letting Bmax include everything as the black screen I only get when trying to reduce the imports using a framework ?

[Edit] Oh I just realized I am not building it in debug mode, turn that on and the first code does give an error. here's a qucik fix ;)

Code: [Select]
'-----------------------------------------------------------------------------------------------------
'
' The Tin Dragons - OpenGL Frame Buffer test By Joncom2000
'
'
'-----------------------------------------------------------------------------------------------------
Include "bmaxptc.bmx"

ptc_open("Test",640,480,60)

Global pixels:Int[640*480]

Repeat
For p=0 To (640*480)-1
col=Rand(255)
pixels[p]=col Shl 16+col Shl 8 + col
Next
ptc_update(Varptr(Pixels[0]))
Until KeyDown(KEY_ESCAPE)
End
« Last Edit: October 01, 2006 by TinDragon »

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Bmax Framebuffer Lib
« Reply #16 on: October 01, 2006 »
I only tried the rotozoom one, sorry, but that works at least. The other one would probably crash in release mode though.