January 22, 2019, 01:05:16 AM

Author Topic: Problem with TImagefont in MAXGUI+OpenB3D combination  (Read 1510 times)

Offline Krischan

  • Full Member
  • ***
  • Posts: 164
    • Krischan's Homepage
Problem with TImagefont in MAXGUI+OpenB3D combination
« on: October 22, 2017, 09:48:00 PM »
I have another problem, perhaps somebody knows how to fix this. In my current project I'm using the OpenB3D framework, a MaxGUI window with two canvases and a custom OTF font loaded using TImagefont. There is an interesting problem with the second canvas (depends on which one is activated): the font doesn't work correct in either the first or the second canvas. I've even tried to fix the BeginMax2D/EndMax2D functions but this didn't work. I've reduced the problem to a small demo (here using the Arial TTF from the OS instead of a custom OTF, makes no difference), press SPACE to switch between the MAXGUI BeginMax2D command and a fixed Begin2D command.

I must have two different canvases in MaxGUI (one uses 2D only, one 2D+3D) and they should be updated separately as they are organized in tabs in my application, with an additional third tab which contains a textfield for debug output. Everything works in the second canvas but the font in the first only shows a "filled" version of the font. beside that I'm absolutely unsure about if I've implemented the Hook/Mainloop and the Timer/Paint events correct. It's a real showstopper for my project, a tiny tool for Explorers in the game Elite Dangerous :(

EDIT: oh and by the way - does somebody know how to get Bruceys wx.mod running on BlitzMaxOS? It compiled but I only get errors when I try to run an example. I'm not very happy with MAXGUI and would like to change to a more customizable GUI.

Code: BlitzMax
  1. SuperStrict
  2.  
  3. Framework openb3d.b3dglgraphics
  4.  
  5. Import MaxGui.Drivers
  6. Import brl.Timer
  7. Import brl.EventQueue
  8. Import BRL.freetypefont
  9.  
  10. SetGraphicsDriver GLMax2DDriver()
  11.  
  12. ' MAXGUI stuff
  13. Global width:Int = 320
  14. Global Height:Int = 240
  15. Global wx:Int = (ClientWidth(Desktop()) - width) / 2
  16. Global wy:Int = (ClientHeight(Desktop()) - Height) / 2
  17. Global Window1:TGadget = CreateWindow("First Canvas", wx, wy, width, Height, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
  18. Global canvas1:TGadget = CreateCanvas(0, 0, 320, 240, Window1)
  19. Global window2:TGadget = CreateWindow("Second Canvas", wx * 1.25, wy * 1.25, width, Height, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
  20. Global canvas2:TGadget = CreateCanvas(0, 0, 320, 240, window2)
  21. ActivateGadget(canvas2)
  22.  
  23. ' load font
  24. Global Font:TImageFont = LoadImageFont(getenv_("WINDIR") + "/Fonts/Arial.ttf", 32)
  25.  
  26. Global switch:Int = 0
  27. Global switchtext:String[] = ["MAX2D", "MAX2D fixed"]
  28.  
  29. ' OpenB3D stuff
  30. SetGraphics CanvasGraphics(canvas1)
  31. Graphics3D width, Height, 0, 2, 60, -1, True
  32. Global cam:TCamera = CreateCamera()
  33. Global mesh:TMesh = CreateCube()
  34. Global light:TLight = CreateLight(1)
  35. AmbientLight 0, 0, 0
  36. PositionEntity mesh, 0, 0, 3
  37.  
  38. CreateTimer 60
  39.  
  40. ' hook
  41. AddHook EmitEventHook, LoopHook
  42.  
  43. ' main loop
  44. Repeat
  45.  
  46.         WaitEvent()
  47.  
  48. Forever
  49.  
  50. End
  51.  
  52. ' ----------------------------------------------------------------------------
  53. ' Loop Hook
  54. ' ----------------------------------------------------------------------------
  55. Function LoopHook:Object(id:Int, data:Object, context:Object)
  56.  
  57.         Local Event:TEvent = TEvent(data)
  58.         If Event = Null Then Return Event
  59.  
  60.         Select Event.id
  61.  
  62.                 Case EVENT_TIMERTICK
  63.  
  64.                         TurnEntity mesh, 0.5, 1, 0.5
  65.                
  66.                         RedrawGadget canvas1
  67.                         RedrawGadget canvas2
  68.  
  69.                 Case EVENT_GADGETPAINT
  70.  
  71.                         Select Event.source
  72.  
  73.                                 Case canvas1
  74.  
  75.                                                         SetGraphics CanvasGraphics(canvas1)
  76.                                                        
  77.                                                         Cls
  78.                                                        
  79.                                                         RenderWorld
  80.                                                        
  81.                                                         If switch Then Begin2D() Else BeginMax2D()
  82.                                                        
  83.                                                         SetBlend ALPHABLEND
  84.                                                         SetColor(255, 0, 0)
  85.                                                         SetImageFont Font
  86.                                                         DrawText switchtext[switch], 0, 0
  87.                                                        
  88.                                                         If switch Then End2D() Else EndMax2D()
  89.                                                        
  90.                                                         Flip False
  91.        
  92.                                 Case canvas2
  93.        
  94.                                                         SetGraphics CanvasGraphics(canvas2)
  95.                                                        
  96.                                                         Cls
  97.                                                        
  98.                                                         RenderWorld
  99.                                                        
  100.                                                         If switch Then Begin2D() Else BeginMax2D()
  101.                                                        
  102.                                                         SetBlend ALPHABLEND
  103.                                                         SetColor(0, 255, 0)
  104.                                                         SetImageFont Font
  105.                                                         DrawText switchtext[switch], 0, 0
  106.                                                        
  107.                                                         If switch Then End2D() Else EndMax2D()
  108.                                                        
  109.                                                         Flip false
  110.  
  111.                         End Select
  112.                        
  113.                 Case EVENT_KEYDOWN
  114.                
  115.                         Select Event.data
  116.                        
  117.                                 Case KEY_SPACE
  118.                                
  119.                                                         switch = 1 - switch
  120.                        
  121.                         End Select
  122.  
  123.                 Case EVENT_WINDOWCLOSE
  124.  
  125.                         FreeGadget canvas1
  126.                         FreeGadget canvas2
  127.                         End
  128.  
  129.                 Case EVENT_APPTERMINATE
  130.  
  131.                         End
  132.  
  133.         End Select
  134.  
  135. End Function
  136.  
  137. ' Fixed BeginMax2D()
  138. Function Begin2D()
  139.  
  140.         Local x:Int, y:Int, w:Int, h:Int
  141.         GetViewport(x, y, w, h)
  142.  
  143.         glDisable(GL_LIGHTING)
  144.         glDisable(GL_DEPTH_TEST)
  145.         glDisable(GL_SCISSOR_TEST)
  146.         glDisable(GL_FOG)
  147.         glDisable(GL_CULL_FACE)
  148.  
  149.         glMatrixMode GL_TEXTURE
  150.         glLoadIdentity
  151.  
  152.         glMatrixMode GL_PROJECTION
  153.         glLoadIdentity
  154.         glOrtho 0, width, Height, 0, -1, 1
  155.  
  156.         glMatrixMode GL_MODELVIEW
  157.         glLoadIdentity
  158.  
  159.         SetViewport x, y, w, h
  160.  
  161.         Local MaxTex:Int
  162.         glGetIntegerv(GL_MAX_TEXTURE_UNITS, Varptr(MaxTex))
  163.  
  164.         For Local Layer:Int = 0 Until MaxTex
  165.  
  166.                 glActiveTexture(GL_TEXTURE0+Layer)
  167.  
  168.                 glDisable(GL_TEXTURE_CUBE_MAP)
  169.                 glDisable(GL_TEXTURE_GEN_S)
  170.                 glDisable(GL_TEXTURE_GEN_T)
  171.                 glDisable(GL_TEXTURE_GEN_R)
  172.  
  173.                 glDisable(GL_TEXTURE_2D)
  174.  
  175.         Next
  176.  
  177.         glActiveTexture(GL_TEXTURE0)
  178.  
  179.         glViewport(0, 0, width, Height)
  180.         glScissor(0, 0, width, Height)
  181.  
  182.         glEnable GL_BLEND
  183.         glEnable(GL_TEXTURE_2D)
  184.  
  185. End Function
  186.  
  187.  
  188.  
  189. ' Fixed EndMax2D()
  190. Function End2D()
  191.  
  192.         glDisable(GL_TEXTURE_CUBE_MAP)
  193.         glDisable(GL_TEXTURE_GEN_S)
  194.         glDisable(GL_TEXTURE_GEN_T)
  195.         glDisable(GL_TEXTURE_GEN_R)
  196.  
  197.         glDisable(GL_TEXTURE_2D)
  198.         glDisable GL_BLEND
  199.  
  200.         TGlobal.EnableStates()
  201.  
  202.         TGlobal.alpha_enable[0] = 0     ' alpha blending was disabled by Max2d (GL_BLEND)
  203.         TGlobal.blend_mode[0] = 1       ' force alpha blending
  204.         TGlobal.fx1[0] = 0                      ' full bright/surface normals was enabled by EnableStates (GL_NORMAL_ARRAY)
  205.         TGlobal.fx2[0] = 1                      ' vertex colors was enabled by EnableStates (GL_COLOR_ARRAY)
  206.  
  207.         glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)
  208.         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
  209.  
  210.         glClearDepth(1.0)
  211.         glDepthFunc(GL_LEQUAL)
  212.         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
  213.  
  214.         glAlphaFunc(GL_GEQUAL, 0.5)
  215.  
  216.         For Local cam:TCamera=EachIn TCamera.cam_list
  217.  
  218.                  ' active camera - was if cam.hide[0]=0
  219.                  If cam = TGlobal.camera_in_use
  220.  
  221.                         ' fog with Max2d fix
  222.                         cam.UpdateFog()
  223.                         Exit
  224.  
  225.                 EndIf
  226.  
  227.         Next
  228.  
  229. End Function
Kind regards
Krischan

Windows 10 Pro | iMac 27" Late 2013 [i7 4771 @ 3.5GHz | GTX 780M]
My Blitzbasic Archive | Extrasolar Project

Offline Derron

  • Hero Member
  • *****
  • Posts: 1557
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #1 on: October 23, 2017, 08:38:36 AM »
wx.mod: works here (linux).

For Windows it is always a matter of using the right MinGW ... I think I was using TDM 4.6 to do the job - so you might give it a try.
Of course error lines would help (blitzmax errors or gcc errors?).


@ font error
cannot try it now but did you check if it works with 2 max2d-canvases only? Maybe openb3d is changing a opengl-variable (matrix, modes,....) which disturbs the font rendering?

bye
Ron

Offline RonTek

  • Sr. Member
  • ****
  • Posts: 357
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #2 on: October 23, 2017, 01:57:05 PM »
I remember doing Max2D and OpenB3D and have to do the Max2D Begin and End functions. I think you also need to play around with the AlphaBlend settings and if I'm not mistaken there's a fix/patch that you need to apply to make it work, though I'm not sure and I have to dig it up when I get a chance.

I have not tried using MaxGUI and OpenB3D, but there's a demo on both provided in the download or repo.

MaxGUI
https://github.com/markcwm/openb3d.mod/blob/master/examples/minib3d/maxgui.bmx

Max2D
https://github.com/markcwm/openb3d.mod/blob/master/examples/minib3d/max2d.bmx

Offline Krischan

  • Full Member
  • ***
  • Posts: 164
    • Krischan's Homepage
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #3 on: October 23, 2017, 07:16:25 PM »
Hmm, without OpenB3D it works, but only when I comment the SetGraphicsDriver GLMax2DDriver() line, uncommented the same error occurs.

For the wx problem, I'm using BlitzMaxOS with MinGW 5.1.0.2 here. I'm only getting a fatal error (see attachment), the modules compiles without any errors, the program too (in Debug and Release mode). But it just crashes. Does it work with 5.1 or only with 4.x? This would be too bad and I must stay with MAXGUI then. And is it normal that a simple demo like aboutbox takes 10MB space? Huh?

I'll take a look at the OpenB3D examples later, my wife is hungry and she shouldn't wait for the cook ;)

Code: BlitzMax
  1. SuperStrict
  2.  
  3. Import maxgui.Drivers
  4. Import brl.Timer
  5. Import brl.EventQueue
  6. Import BRL.freetypefont
  7.  
  8. 'SetGraphicsDriver GLMax2DDriver()
  9.  
  10. ' MAXGUI stuff
  11. Global width:Int = 320
  12. Global Height:Int = 240
  13. Global wx:Int = (ClientWidth(Desktop()) - width) / 2
  14. Global wy:Int = (ClientHeight(Desktop()) - Height) / 2
  15. Global Window1:TGadget = CreateWindow("First Canvas", wx, wy, width, Height, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
  16. Global canvas1:TGadget = CreateCanvas(0, 0, 320, 240, Window1)
  17. Global window2:TGadget = CreateWindow("Second Canvas", wx * 1.25, wy * 1.25, width, Height, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
  18. Global canvas2:TGadget = CreateCanvas(0, 0, 320, 240, window2)
  19. ActivateGadget(canvas1)
  20.  
  21. ' load font
  22. Global Font:TImageFont = LoadImageFont(getenv_("WINDIR") + "/Fonts/Arial.ttf", 32)
  23.  
  24. Global switch:Int = 0
  25. Global switchtext:String[] = ["MAX2D", "MAX2D fixed"]
  26.  
  27. SetGraphics CanvasGraphics(canvas1)
  28.  
  29. CreateTimer 60
  30.  
  31. ' hook
  32. AddHook EmitEventHook, LoopHook
  33.  
  34. ' main loop
  35. Repeat
  36.  
  37.         WaitEvent()
  38.  
  39. Forever
  40.  
  41. End
  42.  
  43. ' ----------------------------------------------------------------------------
  44. ' Loop Hook
  45. ' ----------------------------------------------------------------------------
  46. Function LoopHook:Object(id:Int, data:Object, context:Object)
  47.  
  48.         Local Event:TEvent = TEvent(data)
  49.         If Event = Null Then Return Event
  50.  
  51.         Select Event.id
  52.  
  53.                 Case EVENT_TIMERTICK
  54.                
  55.                         RedrawGadget canvas1
  56.                         RedrawGadget canvas2
  57.  
  58.                 Case EVENT_GADGETPAINT
  59.  
  60.                         Select Event.source
  61.  
  62.                                 Case canvas1
  63.  
  64.                                                         SetGraphics CanvasGraphics(canvas1)
  65.                                                        
  66.                                                         Cls
  67.                                                                                                                                                                        
  68.                                                         SetBlend ALPHABLEND
  69.                                                         SetColor(255, 0, 0)
  70.                                                         SetImageFont Font
  71.                                                         DrawText switchtext[switch], 0, 0
  72.                                                                                                                
  73.                                                         Flip False
  74.        
  75.                                 Case canvas2
  76.        
  77.                                                         SetGraphics CanvasGraphics(canvas2)
  78.                                                        
  79.                                                         Cls
  80.                                                                                                                                                                        
  81.                                                         SetBlend ALPHABLEND
  82.                                                         SetColor(0, 255, 0)
  83.                                                         SetImageFont Font
  84.                                                         DrawText switchtext[switch], 0, 0
  85.                                                                                                                
  86.                                                         Flip False
  87.  
  88.                         End Select
  89.                        
  90.                 Case EVENT_KEYDOWN
  91.                
  92.                         Select Event.data
  93.                        
  94.                                 Case KEY_SPACE
  95.                                
  96.                                                         switch = 1 - switch
  97.                        
  98.                         End Select
  99.  
  100.                 Case EVENT_WINDOWCLOSE
  101.  
  102.                         FreeGadget canvas1
  103.                         FreeGadget canvas2
  104.                         End
  105.  
  106.                 Case EVENT_APPTERMINATE
  107.  
  108.                         End
  109.  
  110.         End Select
  111.  
  112. End Function
Kind regards
Krischan

Windows 10 Pro | iMac 27" Late 2013 [i7 4771 @ 3.5GHz | GTX 780M]
My Blitzbasic Archive | Extrasolar Project

Offline Derron

  • Hero Member
  • *****
  • Posts: 1557
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #4 on: October 23, 2017, 07:39:21 PM »
10 megs is because it contains the complete wx library - so even if you only added a button, you compile the code for rich edits etc into the exe. And wx creates everything "on its own", so it does not rely on some simple calls to a windows library.
This explains the 10 mb.

Stripping it might reduce file size a bit.


@ EAV
You might consider trying to build it in "debug" mode and you will see where it errors out...




I then used "GLMax2DDriver()" (as I am running my XP in a VirtualBox and so only have proper access to OpenGL). ... it created two windows but they do not refresh without artifacts (might be my VirtualBox thing...).

So might it be that with D3D (and the blitzmax-implementation) you cannot have 2 canvases?


bye
Ron

Offline Dabz

  • Full Member
  • ***
  • Posts: 123
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #5 on: October 23, 2017, 08:11:52 PM »
If I run the app with SetGraphicsDriver GLMax2DDriver() commented, it works a charm here...

If I uncomment it, canvas1 is fine and the text is clear, canvas2 on the other hand, the text is garbage!

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 8Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Offline Dabz

  • Full Member
  • ***
  • Posts: 123
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #6 on: October 23, 2017, 08:25:43 PM »
Little more detail that I've found...

Right, canvasthing3.png is the one that runs as expected (With SetGraphicsDriver GLMax2DDriver() commented out)...

canvasthing1.png is what I get (When SetGraphicsDriver GLMax2DDriver() isnt commented out) when I click on canvas1 first, then hit Space...

canvasthing2.png on the other hand, is what I get (When SetGraphicsDriver GLMax2DDriver() isnt commented out) when I click on canvas2 first (Bringing it to the front), then hitting Space!

Not a clue whats happening there mind, because as I recall... That did work as expected, and I cannot see nothing wrong with the code!?!

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 8Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Offline col

  • Sr. Member
  • ****
  • Posts: 407
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #7 on: October 23, 2017, 11:27:56 PM »
You should be able to create multiple windows with the direct3d drivers too.

I get an EAV on the D3D9Max2DDriver.
I also get the same garbage text that Dabz is getting without bringing in the openb3d module.

Win7 x64.
Any bugs in my code are proof of its hand-coded nature.
https://github.com/davecamp

Offline col

  • Sr. Member
  • ****
  • Posts: 407
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #8 on: October 23, 2017, 11:47:34 PM »
Without digging deep I *think* the problem is because the font uses textures for the glyphs. The textures are created by an underlying context. That context is different for each window. If I recall correctly you shouldn't share textures across glcontexts ( across windows ) ?? Someone should correct me there. Also isn't there glShareContexts type of function that may be of use?

Creating and using a second font for the second window solves the immediate issue for me.
Not sure what's going with D3D9 though - I haven't looked into that one and I need an early night ;D
Any bugs in my code are proof of its hand-coded nature.
https://github.com/davecamp

Offline Dabz

  • Full Member
  • ***
  • Posts: 123
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #9 on: October 24, 2017, 07:08:04 AM »
Just checked with D3D9Max2DDriver, and, works... I had to check as it's been that long I wasnt sure what BlitzMax defaulted to when you just use Graphics()

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 8Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Offline Krischan

  • Full Member
  • ***
  • Posts: 164
    • Krischan's Homepage
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #10 on: October 24, 2017, 07:37:50 AM »
GlShareContexts(). That's it, thanks col! But the text only works with my modified Begin2D() / End2D() functions - but that's ok.

Code: [Select]
    SuperStrict
     
    Framework openb3d.b3dglgraphics
     
    Import MaxGui.Drivers
    Import brl.Timer
    Import brl.EventQueue
    Import BRL.freetypefont
     
    SetGraphicsDriver GLMax2DDriver()

GLShareContexts()
     
    ' MAXGUI stuff
    Global width:Int = 320
    Global Height:Int = 240
    Global wx:Int = (ClientWidth(Desktop()) - width) / 2
    Global wy:Int = (ClientHeight(Desktop()) - Height) / 2
    Global Window1:TGadget = CreateWindow("First Canvas", wx, wy, width, Height, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
    Global canvas1:TGadget = CreateCanvas(0, 0, 320, 240, Window1)
    Global window2:TGadget = CreateWindow("Second Canvas", wx * 1.25, wy * 1.25, width, Height, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
    Global canvas2:TGadget = CreateCanvas(0, 0, 320, 240, window2)
    ActivateGadget(canvas2)
     
    ' load font
    Global Font:TImageFont = LoadImageFont(getenv_("WINDIR") + "/Fonts/Arial.ttf", 32)
     
    Global switch:Int = 1
    Global switchtext:String[] = ["MAX2D", "MAX2D fixed"]
     
    ' OpenB3D stuff
    SetGraphics CanvasGraphics(canvas1)
    Graphics3D width, Height, 0, 2, 60, -1, True
    Global cam:TCamera = CreateCamera()
    Global mesh:TMesh = CreateCube()
    Global light:TLight = CreateLight(1)
    AmbientLight 0, 0, 0
    PositionEntity mesh, 0, 0, 3
     
    CreateTimer 60
     
    ' hook
    AddHook EmitEventHook, LoopHook
     
    ' main loop
    Repeat
     
            WaitEvent()
     
    Forever
     
    End
     
    ' ----------------------------------------------------------------------------
    ' Loop Hook
    ' ----------------------------------------------------------------------------
    Function LoopHook:Object(id:Int, data:Object, context:Object)
     
            Local Event:TEvent = TEvent(data)
            If Event = Null Then Return Event
     
            Select Event.id
     
                    Case EVENT_TIMERTICK
     
                            TurnEntity mesh, 0.5, 1, 0.5
                   
                            RedrawGadget canvas1
                            RedrawGadget canvas2
     
                    Case EVENT_GADGETPAINT
     
                            Select Event.source
     
                                    Case canvas1
     
                                                            SetGraphics CanvasGraphics(canvas1)
                                                           
                                                            Cls
                                                           
                                                            RenderWorld
                                                           
                                                            If switch Then Begin2D() Else BeginMax2D()
                                                           
                                                            SetBlend ALPHABLEND
                                                            SetColor(255, 0, 0)
                                                            SetImageFont Font
                                                            DrawText switchtext[switch], 0, 0
                                                           
                                                            If switch Then End2D() Else EndMax2D()
                                                           
                                                            Flip False
           
                                    Case canvas2
           
                                                            SetGraphics CanvasGraphics(canvas2)
                                                           
                                                            Cls
                                                           
                                                            RenderWorld
                                                           
                                                            If switch Then Begin2D() Else BeginMax2D()
                                                           
                                                            SetBlend ALPHABLEND
                                                            SetColor(0, 255, 0)
                                                            SetImageFont Font
                                                            DrawText switchtext[switch], 0, 0
                                                           
                                                            If switch Then End2D() Else EndMax2D()
                                                           
                                                            Flip false
     
                            End Select
                           
                    Case EVENT_KEYDOWN
                   
                            Select Event.data
                           
                                    Case KEY_SPACE
                                   
                                                            switch = 1 - switch
                           
                            End Select
     
                    Case EVENT_WINDOWCLOSE
     
                            FreeGadget canvas1
                            FreeGadget canvas2
                            End
     
                    Case EVENT_APPTERMINATE
     
                            End
     
            End Select
     
    End Function
     
    ' Fixed BeginMax2D()
    Function Begin2D()
     
            Local x:Int, y:Int, w:Int, h:Int
            GetViewport(x, y, w, h)
     
            glDisable(GL_LIGHTING)
            glDisable(GL_DEPTH_TEST)
            glDisable(GL_SCISSOR_TEST)
            glDisable(GL_FOG)
            glDisable(GL_CULL_FACE)
     
            glMatrixMode GL_TEXTURE
            glLoadIdentity
     
            glMatrixMode GL_PROJECTION
            glLoadIdentity
            glOrtho 0, width, Height, 0, -1, 1
     
            glMatrixMode GL_MODELVIEW
            glLoadIdentity
     
            SetViewport x, y, w, h
     
            Local MaxTex:Int
            glGetIntegerv(GL_MAX_TEXTURE_UNITS, Varptr(MaxTex))
     
            For Local Layer:Int = 0 Until MaxTex
     
                    glActiveTexture(GL_TEXTURE0+Layer)
     
                    glDisable(GL_TEXTURE_CUBE_MAP)
                    glDisable(GL_TEXTURE_GEN_S)
                    glDisable(GL_TEXTURE_GEN_T)
                    glDisable(GL_TEXTURE_GEN_R)
     
                    glDisable(GL_TEXTURE_2D)
     
            Next
     
            glActiveTexture(GL_TEXTURE0)
     
            glViewport(0, 0, width, Height)
            glScissor(0, 0, width, Height)
     
            glEnable GL_BLEND
            glEnable(GL_TEXTURE_2D)
     
    End Function
     
     
     
    ' Fixed EndMax2D()
    Function End2D()
     
            glDisable(GL_TEXTURE_CUBE_MAP)
            glDisable(GL_TEXTURE_GEN_S)
            glDisable(GL_TEXTURE_GEN_T)
            glDisable(GL_TEXTURE_GEN_R)
     
            glDisable(GL_TEXTURE_2D)
            glDisable GL_BLEND
     
            TGlobal.EnableStates()
     
            TGlobal.alpha_enable[0] = 0     ' alpha blending was disabled by Max2d (GL_BLEND)
            TGlobal.blend_mode[0] = 1       ' force alpha blending
            TGlobal.fx1[0] = 0                      ' full bright/surface normals was enabled by EnableStates (GL_NORMAL_ARRAY)
            TGlobal.fx2[0] = 1                      ' vertex colors was enabled by EnableStates (GL_COLOR_ARRAY)
     
            glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)
            glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
     
            glClearDepth(1.0)
            glDepthFunc(GL_LEQUAL)
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
     
            glAlphaFunc(GL_GEQUAL, 0.5)
     
            For Local cam:TCamera=EachIn TCamera.cam_list
     
                     ' active camera - was if cam.hide[0]=0
                     If cam = TGlobal.camera_in_use
     
                            ' fog with Max2d fix
                            cam.UpdateFog()
                            Exit
     
                    EndIf
     
            Next
     
    End Function

A question to Qube: the codebox in the forum here converts Tabs to Spaces, is it possible to fix this? See second screenshot.
Kind regards
Krischan

Windows 10 Pro | iMac 27" Late 2013 [i7 4771 @ 3.5GHz | GTX 780M]
My Blitzbasic Archive | Extrasolar Project

Offline Derron

  • Hero Member
  • *****
  • Posts: 1557
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #11 on: October 24, 2017, 12:09:28 PM »
Just convert your tabs to spaced before posting here. That way you can define how "deep" your tab-spaces should be (by default it should be 4 or 8).


Also: The line with "GLSharecontexts()" is having a "tab" at the beginning. Maybe it only removes the tabs when doing a code-paste in wysiwyg-mode.




bye
Ron

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 314
Re: Problem with TImagefont in MAXGUI+OpenB3D combination
« Reply #12 on: October 29, 2017, 09:33:25 PM »
I've used this code as the basis for a multi-canvas example named maxgui2, it works well now but it took me a few days. So thanks Krischan. Also thanks for the improved begin and endmax2d functions, I have replaced the old functions with them and renamed the old functions Begin and EndMini3D (so as not to conflict with your names).

There's a new commit for the wrapper which has a few other fixes; the Graphics3D command flags wouldn't let you override the default settings, LoadMesh now has a usenative=True parameter to choose between library or native loaders (which currently lack animation but are otherwise an improvement). And there's a few new examples. ;)