Linux FB window ( on top )

Linux specific questions.
albert
Posts: 4041
Joined: Sep 28, 2006 2:41
Location: California, USA

Linux FB window ( on top )

Postby albert » Apr 02, 2017 1:47

How do you set a FB Linux window to be always on top ?

I'm trying to port my "Morphius" screensavers to Linux..
and as-is the start bar shows up at the bottom, I'd like the window to cover the start bar.

Code: Select all

'=============================================================================='
'=============================================================================='
'                                                                              '
'                        Morphius_Solid_4                                      '
'                                                                              '
'   written with:                                                              '
'   Free Basic for Windows Also available for Linux and DOS      '
'                                                                              '
'   compiler available at:                                                     '
'   http://sourceforge.net/projects/fbc/files/                                 '
'                                                                              '
'   FBIDE , A simple to use IDE :                                              '
'   Just load the code and hit F5 to run program                               '
'                                                                              '
'   http://fbide.freebasic.net/index.php?menuID=56                             '
'                                                                              '
'   click on: FBIde - zipped. Download                                         '
'   Install in the same directory you installed FreeBasic                      '
'                                                                              '
'                                                                              '
'   Modified From D.J.Peters Sphere code                                       '
'   http://www.freebasic.net/forum/viewtopic.php?f=3&t=16207&start=1530        '
'   post number, 3 and 5                                                       '
'=============================================================================='
'=============================================================================='
#include once "fbgfx.bi"
#include once "GL/gl.bi"
#include once "GL/glu.bi"

Dim as integer My_Frame_Rate=40
'===============================================================================
'declare subs
'===============================================================================
declare Sub regulate(MyFps As integer)
declare sub Normalize(v as glfloat ptr,n as glfloat ptr)
declare sub CreateSphere()
declare sub PlotSphere()
declare sub DeleteSphere()
'===============================================================================
'set up GL screen
'===============================================================================
dim as integer xres,yres
screeninfo xres,yres
screenres xres,yres,32,,10

glViewport 0, 0, xres, yres
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 11.25, xres/yres, .1, 100.0
glMatrixMode GL_MODELVIEW
glLoadIdentity
   
glShadeModel GL_SMOOTH
glClearColor 0.0, 0.0, 0.0, 0.0
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
   
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_COLOR_MATERIAL)
'===============================================================================
'for OpenGl transition,rotation
'===============================================================================
dim as double xt =0, yt =0, zt=-15  'transition variables
dim as double xr =0, yr =0, zr= 0      'rotation variables
dim as double xrs=1, yrs=1, zrs=1' transitions of camera
dim as ubyte    xt_adj = 1 'toggle for x motion
dim as ubyte    yt_adj = 1 'toggle for y motion
dim as ubyte    xt_adj_toggle = 0 'toggles to trigger morphing
dim as ubyte    yt_adj_toggle = 0
dim as ubyte xt_yt_adj_toggle = 0
'===============================================================================
'Variables for Sphere
'===============================================================================
dim shared as double PI  = ATN(1)*4
dim shared as uinteger NumOfSegments : NumOfSegments = 10
dim shared as uinteger NumOfPoints   : NumOfPoints   = (NumOfSegments+1)*(NumOfSegments+1)
dim shared as single multiplier1=1
dim shared as single multiplier2=1
dim as single color_red  =.25+rnd:if color_red  >=.75 then color_red  =.75:if color_red  <=.25 then color_red  = .25
dim as single color_green=.25+rnd:if color_green>=.75 then color_green=.75:if color_green<=.25 then color_green= .25
dim as single color_blue =.25+rnd:if color_blue >=.75 then color_blue =.75:if color_blue <=.25 then color_blue = .25
'===============================================================================
'Setup Open GL Array to hold points
'===============================================================================
dim shared as GLuint listnum = 0
dim shared as glfloat points(NumOfPoints*3-1)
'===============================================================================
'Variables for looping,timing and input
'===============================================================================
dim as single time1, time2 , time_1
dim as string ink
dim as ubyte status = 1
'===============================================================================
'start main loop
'===============================================================================
CreateSphere()
dim as double framerate
do while status=1
   
    regulate(45) 'set at 40 above
   
    glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
    glLoadIdentity
    gltranslatef xt, yt, zt
    glrotatef xr, 1, 0, 0
    glrotatef yr, 0, 1, 0
    glrotatef zr, 0, 0, 1       
    glColor3f( color_red, color_green , color_blue )
   
    PlotSphere()  'call the Draw-Sphere sub routine
    flip
 
    ink=inkey : if ink<>"" then status = 0 ' any key to quit
   
    xr = xr + xrs
    yr = yr + yrs
    zr = zr + zrs
     
    if xt_adj = 1 then xt+=.01
    if xt_adj = 0 then xt-=.01
    if yt_adj = 1 then yt+=.01
    if yt_adj = 0 then yt-=.01
   
    if xt >= +xres/yres then if xt_adj = 1 then xt_adj = 0 : if xt_adj_toggle<>4 then xt_adj_toggle+=1
    if xt <= -xres/yres then if xt_adj = 0 then xt_adj = 1 : if xt_adj_toggle<>4 then xt_adj_toggle+=1
    if yt >= +yres/xres then if yt_adj = 1 then yt_adj = 0 : if yt_adj_toggle<>8 then yt_adj_toggle+=1
    if yt <= -yres/xres then if yt_adj = 0 then yt_adj = 1 : if yt_adj_toggle<>8 then yt_adj_toggle+=1
   
   
    if xt_adj_toggle = 4 and yt_adj_toggle =8 then
        if (xt+.25 = 0) or (xt-.25 = 0) then xt_yt_adj_toggle=1
    end if
   
    if xt_yt_adj_toggle=1 then
        multiplier2+=1
        if multiplier2=1001 then multiplier2=1
        if multiplier2 mod 35 = 0 then xt_adj_toggle=0 : yt_adj_toggle=0 : xt_yt_adj_toggle=0 : time1=time2-60
        DeleteSphere()
        CreateSphere()
    end if
   
    time2=timer
    if time2-time1 >=60 then
        color_red  =.25+rnd:if color_red  >=.75 then color_red  =.75:if color_red  <=.25 then color_red  = .25
        color_green=.25+rnd:if color_green>=.75 then color_green=.75:if color_green<=.25 then color_green= .25
        color_blue =.25+rnd:if color_blue >=.75 then color_blue =.75:if color_blue <=.25 then color_blue = .25
        time1=timer
        multiplier1+=1
        if multiplier1 mod 5 = 0 then multiplier1+=1
        if multiplier1=1001 then multiplier1=1
    end if
   
loop
'===============================================================================
'EXIT main loop
'===============================================================================
DeleteSphere()
END
'===============================================================================
'===============================================================================
'===============================================================================
'===============================================================================
'Sphere subs below here
'===============================================================================
'===============================================================================
'===============================================================================
'===============================================================================
Sub regulate(MyFps As integer)
    static as double timervalue
    Do While (Timer - TimerValue) < 1/MyFps
    Loop
    timervalue=timer
End Sub
'===============================================================================
'===============================================================================
sub Normalize(v as glfloat ptr,n as glfloat ptr)
  dim as glfloat l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]
  if l then
    l=1/sqr(l)
    n[0]=v[0]*l
    n[1]=v[1]*l
    n[2]=v[2]*l
  end if
end sub   
'===============================================================================
'===============================================================================
sub CreateSphere()

    'dim as GLuint listnum = 0
    'dim as glfloat points(NumOfPoints*3-1)
    dim as single  UR=0, YP=0, VR=0, UW=0, VW=0, l=0
    dim as single  US = (PI*2*(multiplier1)) / NumOfSegments 'horizontal portion
    dim as single  VS = (PI*2*(multiplier2)) / NumOfSegments 'verticle portion
    dim as integer PC = 0
   
    For yc as integer = 0 To NumOfSegments
        UR = Sin(yc*VW)
        YP = Cos(yc*VW)
        VR = Sin(yc*VW)
        VW+= VS + ( (US*((rnd*4)+1)) )' * atn(VW) )
       
        UW = 0
        For xc as integer = 0 To NumOfSegments
            Points(PC*3+0)=Sin(PI + UW) * UR
            Points(PC*3+1)=               YP
            Points(PC*3+2)=Cos(PI + UW) * VR
            PC+=1: UW+=US
        Next
    Next
   
    listnum = glGenLists(1)
    glNewList listnum , GL_COMPILE
    glBegin GL_TRIANGLES
   
    For yc as integer = 0 To NumOfSegments - 1
        For xc as integer= 0 To NumOfSegments - 1
            dim as integer P0 = (yc + 1) * (NumOfSegments + 1) + (xc + 0)
            dim as integer P1 = (yc + 1) * (NumOfSegments + 1) + (xc + 1)
            dim as integer P2 = (yc + 0) * (NumOfSegments + 1) + (xc + 1)
            dim as integer P3 = (yc + 0) * (NumOfSegments + 1) + (xc + 0)
           
            dim as glfloat v(2),n(2)
           
            v(0)=Points(p0*3+0)
            v(1)=Points(p0*3+1)
            v(2)=Points(p0*3+2)
            Normalize @v(0),@n(0)
            glNormal3fv(@n(0))
            glVertex3fv(@v(0))
           
            v(0)=Points(p1*3+0)
            v(1)=Points(p1*3+1)
            v(2)=Points(p1*3+2)
            Normalize @v(0),@n(0)
            glNormal3fv(@n(0))
            glVertex3fv(@v(0))
           
            v(0)=Points(p3*3+0)
            v(1)=Points(p3*3+1)
            v(2)=Points(p3*3+2)
            Normalize @v(0),@n(0)
            glNormal3fv(@n(0))
            glVertex3fv(@v(0))
           
            v(0)=Points(p1*3+0)
            v(1)=Points(p1*3+1)
            v(2)=Points(p1*3+2)
            Normalize @v(0),@n(0)
            glNormal3fv(@n(0))
            glVertex3fv(@v(0))
           
            v(0)=Points(p2*3+0)
            v(1)=Points(p2*3+1)
            v(2)=Points(p2*3+2)
            Normalize @v(0),@n(0)
            glNormal3fv(@n(0))
            glVertex3fv(@v(0))
           
            v(0)=Points(p3*3+0)
            v(1)=Points(p3*3+1)
            v(2)=Points(p3*3+2)
            Normalize @v(0),@n(0)
            glNormal3fv(@n(0))
            glVertex3fv(@v(0))
        Next
    Next
   
    glEnd()
    glEndList()
    'glCallList(listnum)
   
    'glDeleteLists(listnum , NumOfPoints*3)
    'glDeleteLists(points(0), NumOfPoints*3)
   
end sub
'===============================================================================
'===============================================================================
sub PlotSphere()
    glCallList(listnum)
end sub
'===============================================================================
'===============================================================================
sub DeleteSphere()
    glDeleteLists(listnum , NumOfpoints*3)
    glDeleteLists(points(0), NumOfpoints*3)
end sub

dodicat
Posts: 4495
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Linux FB window ( on top )

Postby dodicat » Apr 02, 2017 19:03

You could try
screenres xres,yres,32,,170
which is opengl + always on top +high priority+no frame

Code: Select all

#include "gl/glu.bi"

Screenres 640,480,32,,170


do
    glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
    flip
    sleep 1,1
    loop until len(inkey)

 
albert
Posts: 4041
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Linux FB window ( on top )

Postby albert » Apr 03, 2017 1:37

@Dodicat

No good , 170 doesn't work, the start bar is still on top... 10 works under Windows but not Linux..
srvaldez
Posts: 1372
Joined: Sep 25, 2005 21:54

Re: Linux FB window ( on top )

Postby srvaldez » Apr 03, 2017 14:06

albert, not sure there's another way but setting the start bar to "windows can cover" or "auto hide" works here.
btw, how did you resolve the libraries not found problem?
I finally made a symbolic link to the GLU lib, ln -s /usr/lib64/libGLU.so.1 /usr/local/lib64/libGLU.so
albert
Posts: 4041
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Linux FB window ( on top )

Postby albert » Apr 03, 2017 16:03

@srvaldez

I did the same thing , i set the startbar properties to "Allow Windows to cover" and it's working now..
Not sure exactly , how to make a real Linux screen saver?

I had to install glu lib.. https://software.opensuse.org/package/libGLU1
And then for glut i installed "Freeglut" from the SUSE software manager..Freeglut is also on sourceforge.

I put the Linux 64 sourcecode on SourceForge along with the pre-compiled Linux binaries.
https://sourceforge.net/projects/morphi ... inux%2064/

The files with no extension are the binaries.

How do you make an rpm package from your software ?
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Re: Linux FB window ( on top )

Postby D.J.Peters » Apr 03, 2017 22:51

I posted the code you needed under tips and tricks OpenGL vsync on off.

Get Display connection from your OpenGL window glXGetCurrentDisplay() and the Window ID glXGetCurrentDrawable().
viewtopic.php?f=7&t=22617&p=198274&hilit=vsync#p198274

With the Window ID you can use the XLib stuf XRaiseWindow() to bring your Window on top.
Posted in the fltk-c for FreeBASIC thread
viewtopic.php?f=14&t=24547&p=220132&hilit=XRaiseWindow#p220132

docu: XRaiseWindow()

Joshy
albert
Posts: 4041
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Linux FB window ( on top )

Postby albert » Apr 04, 2017 0:54

@D.J.Peters

The include file fltk-c.bi isn't on my FreeBASIC 64 Linux file system. no fltk ?
I've got the Xlib *.bi's
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Re: Linux FB window ( on top )

Postby D.J.Peters » Apr 04, 2017 19:31

@albert you don't need FLTK
use glXGetCurrentDisplay() to get the X-server connection from your OpenGL context
with glXGetCurrentDrawable() you get the xLib ID from fbgfx Window
with this ID you can use XRaiseWindow() to bring the fbgfx Window on top.

Joshy
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Re: Linux FB window ( on top )

Postby D.J.Peters » Apr 05, 2017 14:40

Make the fbgfx window the top most (Windows and Linux)

I can't test ATM not at home and only windows here but it should work.

If I made a typo try to fix it self.

Joshy

Code: Select all

#ifdef __FB_WIN32__
 #include once "fbgfx.bi"
 #include once "windows.bi"
 sub WindowSetTopmost
   dim as integer win
   screencontrol FB.GET_WINDOW_HANDLE,win
   dim as HWND hWin = cast(as HANDLE,win)
   SetWindowPos(hWin, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
 end sub
#else ' linux
 #include "X11/Xlib.bi"
 sub WindowSetTopmost(byval win as integer)
  var disp = glXGetCurrentDisplay()
  var hWin = glXGetCurrentDrawable()
  XRaiseWindow(disp,hWin)
 end sub
#endif

' after screenres use
WindowSetTopMost()
albert
Posts: 4041
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Linux FB window ( on top )

Postby albert » Apr 06, 2017 16:41

@D.J.Peters

Your code errors:

fbc -w all "Morphius.bas" (in directory: /home/other/Desktop)
Morphius.bas(31) error 41: Variable not declared, glXGetCurrentDisplay in 'var disp = glXGetCurrentDisplay()'
Morphius.bas(32) error 41: Variable not declared, glXGetCurrentDrawable in 'var hWin = glXGetCurrentDrawable()'
Morphius.bas(33) warning 1(1): Passing scalar as pointer, at parameter 1 of XRAISEWINDOW()
Morphius.bas(63) error 1: Argument count mismatch, found ')' in 'WindowSetTopMost()'
Compilation failed.

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest