• Welcome to Theos PowerBasic Museum 2017.

BassBox

Started by Patrice Terrier, October 08, 2007, 10:57:44 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Charles Pegge

#120
Got it!

By pretending to go to bed, I caught the Gremlins off guard.

It seems you are getting a spurious error when you bind the texture. (I think you can disregard these errors except for diagnostics during coding).

This is my hack for PLUG004 and PLUG006, but you may want to leave off the error checking completely.


SUB MakeFireworksTexture
    LOCAL nRet AS LONG
    DIM Texture(0) AS STATIC LONG

    REDIM PixelArray(0) AS BYTE
    IF BBP_CreateGLTextureFromFile($BBP_PLUGIN_FOLDER + "Texture\particle.bmp", xSize&, ySize&, PixelArray(), 1) THEN
       CALL glDeleteTextures(1, Texture(0))
       CALL glGenTextures(1, Texture(0)): nRet = glGetError()
       IF nRet = 0 THEN CALL glBindTexture(%GL_TEXTURE_2D, Texture(0)): nRet = glGetError()

       nret=0 ' SUPPRESS THIS ERROR

       IF nRet = 0 THEN CALL glTexParameteri(%GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR): nRet = glGetError()
       IF nRet = 0 THEN CALL glTexParameteri(%GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR): nRet = glGetError()

       IF nRet = 0 THEN CALL glTexImage2D(%GL_TEXTURE_2D, 0, 4, xSize&, ySize&, 0, %GL_RGBA, %GL_UNSIGNED_BYTE, PixelArray(0)): nRet = glGetError()
    END IF

END SUB


Patrice Terrier

#121
This version allows you to create audio play list using the reserved ".bbp" extension.

A "bbp" play list is just a standard ascii text file where each line does match a specific audio file name (must be a full qualified path name).

As an extra bonus you can embed streaming audio URL into a "bbp" play list.

There is an example of bbp file into the BassBox folder and its name is "BassBox.bbp"


http://media.audiofanzine.com/compos/176294/spookyman-Summer_Games.mp3
http://media.audiofanzine.com/compos/322635/daniga-Astral_Motion.mp3
http://samueldequidt.free.fr/SOLARIS/SOLARIS.mp3
http://media.audiofanzine.com/compos/51433/Magic_Pascal-Magik_Sound.mp3
http://media.audiofanzine.com/compos/353134/peaktrance-ElectronicMusic.mp3


Note: You can mix URL and local audio files altogether into the same play list.

When using URL it is better to use a fast DSL connection to avoid lags while playing audio.

In the provided play list "SUMMER GAMES PART.1" is my favorite audio file, better to play it with the "Magic spectrum"

And if you are good guys, then, perhaps, I will add another extra function to save the result of the streamed audio file into a local folder, perhaps ;)

See below BassPatch32.zip

...


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Kent Sarikaya

Patrice that is great, I just dragged the playlist bpp file and away we go, sights, sound and eye candy, thanks really really nice!!

Patrice Terrier

-- Charles,

QuoteBy pretending to go to bed, I caught the Gremlins off guard.

I found myself that in "plug003c.bas" removing glDisable(GL_TEXTURE) and glEnable(GL_TEXTURE) and using only glDisable(GL_TEXTURE_2D) and glEnable(GL_TEXTURE_2D) solved the problem.

Also it would be better to use this procedure to create the texture:


SUB MakeTexture(zPathToTexture AS ASCIIZ)
    LOCAL nRet, xSize, ySize AS LONG
    DIM Texture(0) AS STATIC LONG

    REDIM PixelArray(0) AS BYTE
    IF BBP_CreateGLTextureFromFile(zPathToTexture, xSize, ySize, PixelArray(), 1) THEN
       CALL glDeleteTextures(1, Texture(0))
       CALL glGenTextures(1, Texture(0)): nRet = glGetError()
       IF nRet = 0 THEN
          CALL glBindTexture(GL_TEXTURE_2D, Texture(0))
          CALL glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
          CALL glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
          CALL glTexImage2D(GL_TEXTURE_2D, 0, 4, xSize, ySize, 0, GL_RGBA, GL_UNSIGNED_BYTE, PixelArray(0))
       END IF
    END IF

END SUB


And change your plug003c.bas source code to this (while removing glDisable(GL_TEXTURE))


    CASE %BBP_INIT
         CALL BBP_SplitColorARGB(BBP.BackARGB, A?, R?, G?, B?)
         Alpha! = A? + 1: Red! = R? + 1: Green! = G? + 1: Blue! = B? + 1
         CALL glClearColor(Red! / 256, Green! /256, Blue! / 256, Alpha! / 256)

         CALL setup_polyhedron_povray (1, "BBPlugin\Include\geo.inc", 1)

         ' default material
         DIM ambi(3)  AS STATIC GLfloat: ambi(0)=0.5:ambi(1)=0.5:ambi(2)=0.5:ambi(3)=1.0
         DIM diff(3)  AS STATIC GLfloat: diff(0)=1.0:diff(1)=1.0:diff(2)=1.0:diff(3)=1.0
         DIM spec(3)  AS STATIC GLfloat: spec(0)=1.0:spec(1)=1.0:spec(2)=1.0:spec(3)=1.0
         DIM emis(3)  AS STATIC GLfloat: emis(0)=1.0:emis(1)=1.0:emis(2)=1.0:emis(3)=1.0
         DIM shine(0) AS STATIC GLfloat: shine(0)=0 ' larger number = smaller more concentrated

         glShadeModel GL_SMOOTH                            'Enable Smooth Shading
         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                              'Enable Lighting
         glEnable GL_COLOR_MATERIAL                        'Enable Coloring Of Material
         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 'Enable Alpha Blending
         glEnable(GL_BLEND)                                'Enable Blending
         glEnable(GL_ALPHA_TEST)                           'Enable Alpha Testing
         glAlphaFunc(GL_ALWAYS,0.0)                        'Set Alpha Testing
         'glEnable(GL_CULL_FACE)                            'Remove front or Back Face

         CALL ColorInit()

         glEnable GL_TEXTURE_2D
         CALL MakeTexture ($BBP_PLUGIN_FOLDER + "Texture\mask72.jpg")
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#124
I forget to tell you that when you perform audio streaming, you can use either "http://" or "ftp://" and the next patch will also handle the use of either "\" or "/" to parse the full path name ( hello Charles ;) ).

In the next patch I plan also to add a new folder named "NetCapture" where audio files streamed from the Internet will be saved while you play them on line. They will be saved under the same name as the original streamed audio file, using the same audio format file extension.
Then you will be further able to play them without lags, if you are using a low rate SDL connection.

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Petr Schreiber

Hi Patrice,

this news sound exciting again.

After long period I had time to look in detail how plugin SDK is done for BassBox, and I must say it is exactly what I think is needed.
I have two ideas for plugin now, so hope I will get time to realise them :D


Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge

Many thanks Patrice, using GL_TEXTURE_2D instead of GL_TEXTURE to enable and disable textures, has resolved another problem I was having with spinning flares, where the texture is temporarily disabled.

I'll be using several textures so I can adopt and adapt ypur CreateGLTextureFromFile procedure, assuming it's ok to leave the textures in place until they are redefined.

As for accommodating "/" as well as "\", you are half way to Linux. :)

The FFT data is very exciting, I would like to create a sonic landscape, but that is going to be quite an intricate thing to do well.

Petr I look forward to seeing some more of your creations.

Patrice Terrier

#127
Here is the BassBox NET capture version that saves streamed audio files into the new "NetCapture\" folder.

See below last BassPatch34.zip

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

--Charles

Suggestion for multiple textures creation:


TYPE ZGLTEXTURE
    ID       AS LONG
    FullName AS ASCIIZ * 260
    Texture  AS LONG
END TYPE

FUNCTION SetMutipleGLTexture (BYVAL ztp AS ZGLTEXTURE PTR, BYVAL N AS LONG) EXPORT AS LONG
    LOCAL mtCount, K, Ret, nCount AS LONG
    '*'STATIC sTexture AS STRING
    DIM mt(1 TO N) AS ZGLTEXTURE AT ztp

    mtCount = UBOUND(mt()) - LBOUND(mt()) + 1
    IF mtCount THEN
       '*'IF LEN(sTexture) THEN
       '*'   nCount = PARSECOUNT(sTexture)
       '*'   DIM T(1 TO nCount) AS LONG
       '*'   FOR K = 1 TO nCount: T(K) = VAL(PARSE$(sTexture, K)): NEXT
       '*'   CALL glDeleteTextures(nCount, T(1))
       '*'   ERASE T()
       '*'END IF
       DIM Texture(1 TO mtCount) AS LONG
       CALL glGenTextures(mtCount, Texture(1)): Ret = glGetError
       '*'sTexture = ""
       IF Ret& = 0 THEN
          FOR K = 1 TO mtCount
              REDIM PixelArray(0) AS BYTE
              IF BBP_CreateGLTextureFromFile(zPathToTexture, xSize, ySize, PixelArray(), 1) THEN
                 mt(k).Texture = Texture(K)
                 '*'sTexture = sTexture + LTRIM$(STR$(Texture(K))) + ","
                 CALL glBindTexture(%GL_TEXTURE_2D, Texture(K)): Ret = glGetError
                 IF Ret& = 0 THEN CALL glTexParameteri(%GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR): Ret = glGetError
                 IF Ret& = 0 THEN CALL glTexParameteri(%GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR): Ret = glGetError
                 IF Ret& = 0 THEN CALL glTexImage2D(%GL_TEXTURE_2D, 0, 4, xSize&, ySize&, 0, %GL_RGBA, %GL_UNSIGNED_BYTE, PixelArray(0)): Ret = glGetError
                 FUNCTION  = Ret&
              END IF
          NEXT
       END IF
    END IF
END FUNCTION

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Marco Pontello


Charles Pegge

Patrice
Re: Suggestion for multiple textures creation:

I think it may be better to keep our options open and handle Opengl directly, for max flexibility. I find that creating 3d scenes is more like painting than coding. So most of it gets developed inline and functions / subroutines are only deployed to avoid repetition, and keep the code to a manageable size. The coding style is almost the opposite of systems programming.

If most of the code is in pure Opengl it is easier to transfer and share, even between different host languages, which is why I am using a MACROised Opengl header to avoid '%' markers everywhere.


Patrice Terrier

--Marco

I know you wont miss that one  :)


--Charles

As I said, it was just a suggestion, but of course do it as you are more comfortable with.
 
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#132
Here is a new BassBox plugin entitled "Laser borealis".

This one is also FFT based, it comes along with a new BBPlugin.inc, that provides support for OpenGL fonts.


FUNCTION BBP_DefaultFont() AS LONG
    STATIC hDefault AS LONG
    IF hDefault = 0 THEN hDefault = GetStockObject(12)      ' %ANSI_VAR_FONT
    FUNCTION = hDefault
END FUNCTION

SUB BBP_BuildGLfont (BYVAL hDC AS LONG, UseFont AS ZGLFONT)
    LOCAL OldFont AS LONG, lpSize AS SIZEL, hFont AS LONG, LenFontName AS LONG

    UseFont.charStart = 32
    UseFont.charNum   = 96
    UseFont.fontBase  = glGenLists(UseFont.charNum)         ' Storage For 96 Characters
    LenFontName = LEN(UseFont.fontName)
    IF hDC = 0 THEN LenFontName = 0
    IF LenFontName THEN
       IF UseFont.fontHeight < 1 THEN UseFont.fontHeight = 10
       UseFont.fontHeight = -1 * (UseFont.fontHeight * GetDeviceCaps(hDC, 90)) \ 72
       IF UseFont.fontWeight = 0 THEN UseFont.fontWeight = %FW_BOLD
       hFont = CreateFont(UseFont.fontHeight, _             ' Height Of Font
                          0, _                              ' Width Of Font
                          0, _                              ' Angle Of Escapement
                          0, _                              ' Orientation Angle
                          UseFont.fontWeight, _             ' Font Weight
                          0, _                              ' Italic
                          0, _                              ' Underline
                          0, _                              ' Strikeout
                          0, _                              ' %ANSI_CHARSET Character Set Identifier
                          %OUT_TT_PRECIS, _                 ' Output Precision
                          0, _                              ' %CLIP_DEFAULT_PRECIS Clipping Precision
                          %ANTIALIASED_QUALITY, _           ' Output Quality
                          0, _                              ' %FF_DONTCARE OR %DEFAULT_PITCH Family And Pitch
                          UseFont.fontName)                 ' Font Name
    ELSE
       hFont = BBP_DefaultFont()
    END IF
    IF hFont THEN
       OldFont = SelectObject(hDC, hFont)                   ' Selects our font
     ' Builds 96 Characters Starting At Character 32
       CALL wglUseFontBitmaps(hDC, UseFont.charStart, UseFont.charNum, UseFont.fontBase)
     ' Get font height
       CALL GetTextExtentPoint32(hDC, "W", 1, lpSize)
       UseFont.fontHeight = lpSize.cy
       CALL SelectObject(hDC, oldfont)                      ' Restore previous selected font
       IF LenFontName THEN UseFont.fontHandle = hFont       ' Save the Win32 font handle
    END IF
END SUB

SUB BBP_DeleteGLFont (UseFont AS ZGLFONT)
    IF UseFont.fontBase THEN
       CALL glDeleteLists(UseFont.fontBase, UseFont.charNum)       ' Delete All 96 Characters
       IF UseFont.fontHandle THEN DeleteObject(UseFont.fontHandle) ' The Win32 font handle
    END IF
END SUB

SUB BBP_DrawGLText (BYVAL glWnd AS LONG, UseFont AS ZGLFONT, BYVAL x AS LONG, BYVAL y AS LONG, zTxt AS ASCIIZ, BYVAL ARGB AS LONG)
    LOCAL rc AS RECT, A, R, G, B AS BYTE, Alpha, Red, Green, Blue AS SINGLE, WasTexture, WasLighting AS LONG
   
    CALL GetClientRect(glWnd, rc)

    WasTexture = glIsEnabled(%GL_TEXTURE_2D)
    IF WasTexture THEN CALL glDisable(%GL_TEXTURE_2D)        ' Turn off textures, didn't want our text textured
    WasLighting = glIsEnabled(%GL_LIGHTING)
    IF WasLighting THEN CALL glDisable(%GL_LIGHTING)         ' Disable Lighting

    CALL glMatrixMode(%GL_PROJECTION)
    CALL glPushMatrix()
    CALL glLoadIdentity()
    CALL glOrtho(0.0, rc.nRight, 0.0, rc.nBottom, -1.0, 1.0)
    CALL glMatrixMode(%GL_MODELVIEW)
    CALL glPushMatrix()
    CALL glLoadIdentity()

  ' Set color
    CALL BBP_SplitColorARGB(ARGB, A, R, G, B)
    Alpha = A + 1: Red = R + 1: Green = G + 1: Blue = B + 1
    CALL glColor3f(Red / 256, Green / 256, Blue / 256)
  ' Set X,Y location
    CALL glRasterPos2i(x, rc.nBottom - (UseFont.fontHeight - 4) - y)
  ' Draw the text
    CALL glPushAttrib(%GL_LIST_BIT)                           ' Pushes The Display List Bits
         CALL glListBase(UseFont.fontBase - UseFont.charStart)' Sets The Base Character to 0
         CALL glCallLists(LEN(zTxt), %GL_UNSIGNED_BYTE, zTxt) ' Draws The Display List Text
    CALL glPopAttrib()                                        ' Pops The Display List Bits

    CALL glPopMatrix()
    CALL glMatrixMode(%GL_PROJECTION)
    CALL glPopMatrix()
    CALL glMatrixMode(%GL_MODELVIEW)

    IF WasTexture THEN CALL glEnable(%GL_TEXTURE_2D)          ' Enable texture mode
    IF WasLighting THEN CALL glEnable(%GL_LIGHTING)           ' Enable Lighting

    CALL glColor3f(1, 1, 1)                                   ' Back to default color

END SUB



To use the OpenGL font in your own plugin, add this at the end of the BBP.Init section:


         UseFont.fontName = "Arial"
         UseFont.fontHeight = 10
         UseFont.fontWeight = %FW_BOLD
         CALL BBP_BuildGLfont(BBP.DC, UseFont) ' Build OpenGL font for our OpenGL window


A few minor changes have also been done into BassBox itself, to accommodate the use of OpenGL fonts.

Note: in order to play "Laser borealis" in full screen, you must have a good grahic card and enable the OpenGL wait for vertical retrace mode.

Try this plugin with different audio style to see how it renders each of them.

Also try with these CX, CY, CZ values:
CX -316, CY -176, CZ -2
CX -143, CY -577, CZ -8


The default value is: CX -128, CY -235, CZ -18

Enjoy  8)

See below BassPatch35.zip

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Charles Pegge

Patrice, how about making the keyboard available to Plugins, like the BBmouse. All we need is the WM_KEYDOWN and WM_KEYUP messages. This will allow the Plugin to capture any combination of key states into a table as well as detecting individual keystrokes.

Patrice Terrier

-- Charles

Keyboard is already on my list, but because it is easy for me to add it, I did first the hard things ;)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com