Android Question [SOLVED] glsSurfaceView Background Color

mmieher

Active Member
Licensed User
Longtime User
Reference:
https://www.b4x.com/android/forum/threads/3d-spinning-cube.92442/#content

I've tabled this problem in my Splash page long enough. I hope @Johan Schoeman is out there ...

How to set the Background Color of the glsSurfaceView in the attached small project?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
        
    Facelist.Initialize
    'add 6 images to (List) facelist - one for each of the faces of the cube
    mbm(0).Initialize(File.DirAssets,"image1.png")
    Facelist.Add(mbm(0))
    mbm(1).Initialize(File.DirAssets,"image2.png")
    Facelist.Add(mbm(1))
    mbm(2).Initialize(File.DirAssets,"image3.png")
    Facelist.Add(mbm(2))
    mbm(3).Initialize(File.DirAssets,"image4.png")
    Facelist.Add(mbm(3))
    mbm(4).Initialize(File.DirAssets,"image5.png")
    Facelist.Add(mbm(4))
    mbm(5).Initialize(File.DirAssets,"image6.png")
    Facelist.Add(mbm(5))
    
    gls1.SixFaces = Facelist
    
    ''    gls1.Color = Colors.Transparent    '    appears to do nothing
    ''    gls1.Color = Colors.Red    '    just coats the whole view with red
    ''    gls1.SetColorAnimated(Colors.Red,Colors.White,Colors.Transparent)    '    does not seem to do anything?  What are the 'args'?  The third one is gls1.color
    
    '    Although cool, this just puts a big "O" in the middle of the view
    ''    Dim bmd As BitmapDrawable
    ''    bmd.Initialize(TextToBitmap("O", 24, Colors.RGB(255, 0, 0)))
    ''    gls1.Background = bmd
    

    '    ANY OTHER IDEAS?    
    

End Sub
 

Attachments

  • b4aOpenGlesPhotoCube.zip
    126.7 KB · Views: 102

Johan Schoeman

Expert
Licensed User
Longtime User
Reference:
https://www.b4x.com/android/forum/threads/3d-spinning-cube.92442/#content

I've tabled this problem in my Splash page long enough. I hope @Johan Schoeman is out there ...

How to set the Background Color of the glsSurfaceView in the attached small project?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
     
    Facelist.Initialize
    'add 6 images to (List) facelist - one for each of the faces of the cube
    mbm(0).Initialize(File.DirAssets,"image1.png")
    Facelist.Add(mbm(0))
    mbm(1).Initialize(File.DirAssets,"image2.png")
    Facelist.Add(mbm(1))
    mbm(2).Initialize(File.DirAssets,"image3.png")
    Facelist.Add(mbm(2))
    mbm(3).Initialize(File.DirAssets,"image4.png")
    Facelist.Add(mbm(3))
    mbm(4).Initialize(File.DirAssets,"image5.png")
    Facelist.Add(mbm(4))
    mbm(5).Initialize(File.DirAssets,"image6.png")
    Facelist.Add(mbm(5))
 
    gls1.SixFaces = Facelist
 
    ''    gls1.Color = Colors.Transparent    '    appears to do nothing
    ''    gls1.Color = Colors.Red    '    just coats the whole view with red
    ''    gls1.SetColorAnimated(Colors.Red,Colors.White,Colors.Transparent)    '    does not seem to do anything?  What are the 'args'?  The third one is gls1.color
 
    '    Although cool, this just puts a big "O" in the middle of the view
    ''    Dim bmd As BitmapDrawable
    ''    bmd.Initialize(TextToBitmap("O", 24, Colors.RGB(255, 0, 0)))
    ''    gls1.Background = bmd
 

    '    ANY OTHER IDEAS? 
 

End Sub
Go here:


B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aOpenGlesPhotoCube
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

'    Marc Removed
'#AdditionalRes: ..\DemoRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private gls1 As glSurfaceView
   
    '    Added by Marc
    Private Facelist As List
    Private mbm(6) As Bitmap
   
   
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
   
   
       
    Facelist.Initialize
    'add 6 images to (List) facelist - one for each of the faces of the cube
    mbm(0).Initialize(File.DirAssets,"image1.png")
    Facelist.Add(mbm(0))
    mbm(1).Initialize(File.DirAssets,"image2.png")
    Facelist.Add(mbm(1))
    mbm(2).Initialize(File.DirAssets,"image3.png")
    Facelist.Add(mbm(2))
    mbm(3).Initialize(File.DirAssets,"image4.png")
    Facelist.Add(mbm(3))
    mbm(4).Initialize(File.DirAssets,"image5.png")
    Facelist.Add(mbm(4))
    mbm(5).Initialize(File.DirAssets,"image6.png")
    Facelist.Add(mbm(5))
   
   
    gls1.SixFaces = Facelist
   
    gls1.ZoomInOut = True                       'it will make the cube zoom In/Out while spinning anround the below defined RotationPlane
    gls1.CubeSpeed = 3.0                        'A negative value will reverse the direction of the spin
    gls1.RotationPlane(1.0, -1.0, 0.0)          'Keep these values between 0.0 and 1.0 (you can also apply negative values)
    gls1.CubeSpeed = 3.0f
    gls1.ZoomInOut = True
    gls1.ZoomMaxValue = -5.0f
    gls1.ZoomMinValue = -50.0f
   
    gls1.setCubeBackgroundColor(0.0f, 0.0f, 0.5f, 0.1f)
   
    ''gls1.Color = Colors.Transparent    '    appears to do nothing
    ''gls1.Color = Colors.Red    '    just coats the whole view with red
    ''gls1.SetColorAnimated(Colors.Red,Colors.White,Colors.Transparent)    '    does not seem to do anything?  What are the 'args'?  The third one is gls1.color
   
    '    Although cool, this just puts a big "O" in the middle of the view
    ''    Dim bmd As BitmapDrawable
    ''    bmd.Initialize(TextToBitmap("O", 24, Colors.RGB(255, 0, 0)))
    ''    gls1.Background = bmd
   

    '    ANY OTHER IDEAS?  
   

End Sub

'    This was used for a tet above
Sub TextToBitmap (s As String, FontSize As Float, lFontColour As Long) As Bitmap
 
    Dim bmp As Bitmap
    Dim cvs As Canvas
 
    bmp.InitializeMutable(28dip, 24dip)
    cvs.Initialize2(bmp)
    Dim h As Double = cvs.MeasureStringHeight(s, Typeface.DEFAULT, FontSize)
    cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.DEFAULT, FontSize, lFontColour, "CENTER")
 
    Return cvs.Bitmap
 
End Sub

Sub Activity_Resume
   
    If gls1.IsInitialized Then
'    this line from the original demo crashes every time
'        gls1.RESUME
    End If

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   
    gls1.PAUSE

End Sub
 

Attachments

  • b4aOpenGlesPhotoCube.zip
    126.9 KB · Views: 98
Last edited:
Upvote 0
Top