• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

BassBox

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

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

#150
Very interesting:
I find that %WM_KEYDOWN is correctly received in the WINMAIN message loop but does not get passed to WNDPROC.

One reason is because it is treated as a dialog message and skips.
But to remove this obstacle is not enough to reach GLWindowProc. So I think its getting lost somewhere in the Bassbox/zskin architecture.

PS: the %WM_KEYDOWN message does noy reach WNDPROC either.


          WHILE GetMessage(Msg, %NULL, 0, 0)  ' SK_MILLISECOND
             'IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                IsDialogMessage(hMain, Msg)
                if Msg.message=%WM_KEYDOWN then msgbox "keydown"
                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
             'END IF
          WEND

Patrice Terrier

#151
-- Charles

I shall take care of this into the next build.

First I will put the focus myself onto the OpenGL control, each time the user select a new plugin, and I shall also restore the focus in case of WM_LBUTTONDOWN if it is not set already.

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

Patrice Terrier

#152
All keyboard messages are now redirected to the Plugin control when it has the focus.


          hCtrl = zGetMainItem(%ID_OpenGL)
          CALL SetTimer(hMain, %OPENGL_TIMER, 0, %NULL)
          WHILE GetMessage(Msg, %NULL, 0, 0)  ' SK_MILLISECOND
             IF GetFocus() = hCtrl AND (Msg.message > 255 AND Msg.message < 266) THEN
                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
             ELSE
                IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                   CALL TranslateMessage(Msg)
                  CALL DispatchMessage(Msg)
                END IF
             END IF
          WEND
          CALL KillTimer(hMain, %OPENGL_TIMER)



See below attached BassPatch38.zip

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

Petr Schreiber

#153
Hi guys,

few tips on texture quality - mipmaps look good, but with LINEAR in both parameters, like this:
Quote
  glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR
  glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR_MIPMAP_LINEAR
  gluBuild2DMipmaps %GL_TEXTURE_2D, dataType, xSize, ySize, %GL_RGBA, %GL_UNSIGNED_BYTE, PixelArray(0)

This kind of mipmapping is often ( I think a bit oddly ) called "trilinear filtering". It is the best you can get from old graphic cards.
And that means there must be some better way ? Of course - anisotropic filtering.

Mip mapping + linear filter is good, but kind of blur textures at sharp angles too much, thats because as a base it takes textures which are filtered linearly.
Anisotropic filtering keeps all relatively sharp, to eliminate "pixelisation" we will combine it with classic mipmapping to get the best filtering currently available.

So how to put that marvel on :D ?
Via extension again.

Use this in your initialisation:
Quote
GLOBAL texture_AnisotropyAllowed AS BYTE
GLOBAL texture_AnisotropyMax AS SINGLE

LOCAL OpenGLInfoPTR AS DWORD
LOCAL OpenGLExtensions AS STRING

' -- Get list of available extensions
OpenGLInfoPTR = glGetString(%GL_EXTENSIONS)
OpenGLExtensions = UCASE$(PEEK$(ASCIIZ, OpenGLInfoPTR, 262144))

' -- Test whether we can use it
IF INSTR( OpenGLExtensions, "GL_EXT_TEXTURE_FILTER_ANISOTROPIC " ) THEN
  texture_AnisotropyAllowed = 1
  ' -- If yes, lets get maximum level of anisotrpy available
  glGetFloatv(%GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, texture_AnisotropyMax )
ELSE
  texture_AnisotropyAllowed = 0
  texture_AnisotropyMax     = 0
END IF

What is anisotropy level ? It is number determining number of samples involved in calculation - higher number, higher quality but more power demanding.

So when loading texture I do something like following for my TBGL thinBASIC module for graphics: if anisotropy is supported and I want it, go for it.
If not then do classic mipmapping, as it is best old hardware can do. Also good to check AnisoFactor does not exceed maximum level of anisotropy hardware offer.

Code for anisotropy is here:
Quote
glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR
glTexParameteri %GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR_MIPMAP_LINEAR
IF texture_AnisotropyAllowed THEN glTexParameterf(%GL_TEXTURE_2D, %GL_TEXTURE_MAX_ANISOTROPY_EXT, AnisoLevel)
gluBuild2DMipmaps %GL_TEXTURE_2D, dataType, xSize, ySize, %GL_RGBA, %GL_UNSIGNED_BYTE, PixelArray(0)
Where AnisoLevel could be 1, 4, 8, 16 ... up to texture_AnisotropyAllowed .

As you can see, it is quite a mutant composed from linear, aniso and mipmap techniques, but it really looks good :)

I attached picture so you can see the diffffference ( as says G-Man from half life 2 :) ).
On static picture mipmapping looks like a terrible one, but first two filters cause quite disturbing noise in the picture when animated.


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

psch.thinbasic.com

Patrice Terrier

Petr,

What about a working example?

;)

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

Charles Pegge

#155
Just tried your new patch Patrice. Thanks. But keyboard messages of any sort are still not getting through. I think it may be a deeper seated problem than focus. When I press any key, it goes 'plunk'.


    CASE %BBP_KEYBOARD

         '// Handle all Windows keyboard messages there
         Msg = BBP.WinMsg: wParam = BBP.wParam: lParam = BBP.lParam
         SELECT CASE LONG Msg
         MSGBOX HEX$(wParam)+" any"
         CASE %WM_KEYDOWN
          IF (wParam AND 255)=&h20 THEN ' '
           Cx=15: Cy=0: Cz=0 ' reset object orientation
          END IF
         CASE %WM_KEYUP
          MSGBOX HEX$(wParam)+" up"
         END SELECT


PS: But this part works correctly


          WHILE GetMessage(Msg, %NULL, 0, 0)  ' SK_MILLISECOND
             IF GetFocus() = hCtrl AND (Msg.message > 255 AND Msg.message < 266) THEN

                IF msg.message=%wm_keydown THEN MSGBOX "keydown main"

                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
             ELSE
                IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                   CALL TranslateMessage(Msg)
                  CALL DispatchMessage(Msg)
                END IF
             END IF
          WEND




Thanks for the info on MIP mapping and Anisotropics, Petr. I tried your MIP linear settings but Its interactions with light and color are different and I can no longer blend color with texture for some reason. I will have to do some more experimenting and study the Opengl manuals.

Patrice Terrier

--Charles

Then the solution is quite simple, we will handle ourselves the message dispatching, like this:

- First, we REM OUT this in GLWindowProc

'    CASE %WM_KEYDOWN TO %WM_UNICHAR
'         BBP.Msg    = %BBP_KEYBOARD
'         BBP.WinMsg = Msg
'         BBP.wParam = wParam
'         BBP.lParam = lParam
'         CALL BBP_Plugin(BBP)   


- Second, add this to the main message pump

          LOCAL BBP AS BBPLUGIN
          hCtrl = zGetMainItem(%ID_OpenGL)
          CALL SetTimer(hMain, %OPENGL_TIMER, 0, %NULL)
          WHILE GetMessage(Msg, %NULL, 0, 0)  ' SK_MILLISECOND
             IF GetFocus() = hCtrl AND (Msg.message > 255 AND Msg.message < 266) THEN
               
                BBP.Msg    = %BBP_KEYBOARD ' <---
                BBP.WinMsg = Msg.message   ' <---
                BBP.wParam = Msg.wParam    ' <---
                BBP.lParam = Msg.lParam    ' <---
                CALL BBP_Plugin(BBP)       ' <---

                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
             ELSE
                IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                   CALL TranslateMessage(Msg)
                  CALL DispatchMessage(Msg)
                END IF
             END IF
          WEND
          CALL KillTimer(hMain, %OPENGL_TIMER)


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

Charles Pegge

Patrice, This works when hctrl is ignored.

Using the keyboard generates %WM_KEYDOWN (&h100)
but after using the mouse, the keyboard message then becomes %WM_SYSKEYDOWN (&h104).

The next key pressed after this will revert to %WM_KEYDOWN (&h100)



          WHILE GetMessage(Msg, %NULL, 0, 0)  ' SK_MILLISECOND
             'IF GetFocus() = hCtrl AND
             IF (Msg.message > 255 AND Msg.message < 266) THEN
                 
                'IF msg.message=%wm_keydown THEN MSGBOX "keydown main"
                'IF msg.message=%wm_syskeydown THEN MSGBOX "syskeydown main"
               
                LOCAL BBP AS BBPLUGIN
                BBP.Msg    = %BBP_KEYBOARD
                BBP.WinMsg = Msg.message
                BBP.wParam = Msg.wParam
                BBP.lParam = Msg.lParam
                CALL BBP_Plugin(BBP)

                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
             ELSE
                IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                   CALL TranslateMessage(Msg)
                  CALL DispatchMessage(Msg)
                END IF
             END IF
          WEND



Patrice Terrier

#158
--Charles,

QuoteUsing the keyboard generates %WM_KEYDOWN (&h100)
but after using the mouse, the keyboard message then becomes %WM_SYSKEYDOWN (&h104).
The next key pressed after this will revert to %WM_KEYDOWN (&h100)

Yes, this is because we are not using a dedicated "game message pump", but a full Windows message pump using the TranslateMessage API to be compatible with the other child controls of the BassBox window.

See details on MSDN there:
http://msdn2.microsoft.com/en-us/library/ms644955.aspx
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Charles Pegge


That's fine Patrice. I have disabled the hctrl focus condition in the Winmain message loop. But is there a way to stop it 'plunk'ing when a key is pressed.

Sonic Circles

This update is well behaved, easier on the eye and visualises more sonic data.

Patrice Terrier

#160
--Charles

BBP_CreateGLTextureFromFile ("BBPlugin\Texture\wood.jpg",tsc,tsc,pix(),0)

You improperly use the BBP_CreateGLTextureFromFile API. (please look at the source code in BBPlugin.inc)

No need for you to first DIM the array, juste use REDIM pix(0) AS BYTE, because the real size of the array is computed inside of the API.
And using BBPlugin\Texture\wood.jpg",tsc,tsc,pix(),0) is a NoNo, because the texture could fit into a rectangle and not necessarily into a square, moreover the size is rounded to the best 2^, and not to the size YOU specify.
This is because BBP_CreateGLTextureFromFile is able to create a texture form any picture size, and from any GDIPLUS graphic format.

Here is how to use it:

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


The important part is:
    REDIM PixelArray(0) AS BYTE
    IF BBP_CreateGLTextureFromFile(zPathToTexture, BYREF xSize, BYREF ySize, PixelArray(), 1) THEN



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

Charles Pegge

Patrice, I may need a bit more flexibility - to be able to grab pieces of an image, at varying resolutions, twiddle the pixels etc. The GDIplus Thumbnail was fine for this. Some images may be used at very low resolutions for diffuse effects. I want to use images like Jackson Pollock uses paint :)

One idea I am pursuing at the moment is to be able to construct the scene, then capture this as a texture and use it in the next frame so you get an infinite recursion of the image - like a hall of mirrors.

So you see, keeping close to the lower levels of the interface has its benefits.

Patrice Terrier

#162
--Charles

I have no problem with flexibility, I am just focusing your attention on the way the current BBP_CreateGLTextureFromFile works.
Of course feel free to use your own procedure to perform texture creation as long as it is well behaved with the others plugins.

About the focus everything is done by the kernell (BassBox), thus no need to do it in the plugin.
I have edited, and checked all the enclosed plugins to make sure they work well with the current BassBox version.

There is a new texture: Mask72.jpg that looks also good with what you have done.

The current plug005 version makes me think to "Stonehenge" perhaps we could use menhirs and dolmens instead of the wooden pieces and it would become very celtic...  ;)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Petr Schreiber

Hi,

thanks for the perfect updates, it really looks cool.

I am sorry, but I am afraid there won't be any complete code from me for some time, as I am running too much paralel processes while having single core brain :D


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

psch.thinbasic.com

Charles Pegge


Thanks Patrice. The Celtic theme is an excellent idea. Will need to find some convincing stones. Celtic patterns are interesting too.

By the way, Patch39 contains my 2 previous bas versions of PLUG005 but not the latest source, though you have included the compiled DLL of it.



Petr, there is only one solution to single core brain syndrome, and that is to combine all your projects into one big project.