CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Forum for discussion about the documentation project.
SamL
Posts: 43
Joined: Nov 23, 2019 17:30
Location: Minnesota

CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Postby SamL » Jun 22, 2021 0:36

CLS command in manual needs updated due to 1.08 changes to ScreenInfo.

CLS example code to clear the screen buffer no longer works in Manual.

"In graphics modes, if you want to clear the entire screen to color 0, it can be faster using Clear to write zeroes to the screen memory than calling Cls."

Code: Select all

Dim scrbuf As Byte Ptr, scrsize As Integer
Dim As Integer scrhei, scrpitch
Dim As Integer r = 0, dr = 1

ScreenRes 640, 480, 8

scrbuf = ScreenPtr: Assert( scrbuf <> 0 )
ScreenInfo( , scrhei, , , scrpitch )
scrsize = scrpitch * scrhei

Do
   
    '' lock the screen (must do this while working directly on screenbuffer)
    ScreenLock
       
        '' clear the screen (could use Cls here):
        Clear *scrbuf, 0, scrsize
       
        '' draw circle
        Circle (320, 240), r
       
    ScreenUnlock
   
    '' grow/shrink circle radius
    r += dr
    If r <= 0 Then dr = 1 Else If r >= 100 Then dr = -1
   
    '' short pause in each frame (prevents hogging the CPU)
    Sleep 1, 1
   
    '' run loop until user presses a key
Loop Until Len(Inkey) > 0
Last edited by SamL on Jun 23, 2021 14:55, edited 1 time in total.
fxm
Moderator
Posts: 10448
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: CLS command in manual needs updated due to 1.08 changes to ScreenInfo

Postby fxm » Jun 22, 2021 6:16

Yes.
More generally, I have to do a pass on all the examples in documentation that use ScreenInfo or ImageInfo or ScreenControl.


[edit]
Done.

At the moment I only updated the examples that did not compile with fbc 64-bit version 1.08:
- KeyPgImageInfo → fxm [second example updated following the change of parameter types for ImageInfo]
- KeyPgImageConvertRow → fxm [example updated following the change of parameter types for ImageInfo]
- ProPgPolymorphism → fxm [updated last example following the parameter types change for ScreenInfo]
- KeyPgCls → fxm [updated second example following the parameter types change for ScreenInfo]

The other examples that still compile with fbc 64-bit version 1.08 owe it to the added overload procedures (with parameters of type 'Longint' overloading type 'Long', and therefore compatible with type 'Integer<64>').

For fbc 32-bit version 1.08, no problem because the type 'Long' is compatible with type 'Integer<32>'.
dodicat
Posts: 6999
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CLS command in manual needs updated due to 1.08 changes to ScreenInfo

Postby dodicat » Jun 22, 2021 9:33

Version 1.08 doesn't get every pixel, there are untouched pixels down the right margin.
Also with no frame I see the missing pixels.
(I tested the 1.07 versions and an old .24 version I keep), all the pixels are used then.
(same code with some colour).

Code: Select all

Dim scrbuf As Byte Ptr, scrsize As Integer
Dim As long scrhei, scrpitch
Dim As Integer r = 0, dr = 1

ScreenRes 640, 480, 8


scrbuf = ScreenPtr: Assert( scrbuf <> 0 )
ScreenInfo( , scrhei, , , scrpitch )
scrsize = scrpitch * scrhei

Do

    '' lock the screen (must do this while working directly on screenbuffer)
    ScreenLock
       'cls
        '' clear the screen (could use Cls here):
        Clear *scrbuf, 5, scrsize
       
        '' draw circle
        Circle (320, 240), r
       
    ScreenUnlock
   
    '' grow/shrink circle radius
    r += dr
    If r <= 0 Then dr = 1 Else If r >= 100 Then dr = -1
   
    '' short pause in each frame (prevents hogging the CPU)
    Sleep 1, 1
   
    '' run loop until user presses a key
Loop Until Len(Inkey) > 0
fxm
Moderator
Posts: 10448
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: CLS command in manual needs updated due to 1.08 changes to ScreenInfo

Postby fxm » Jun 22, 2021 9:47

Due to Direct2D ?
Works with GDI or DirectX.
fxm
Moderator
Posts: 10448
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: CLS command in manual needs updated due to 1.08 changes to ScreenInfo

Postby fxm » Jun 22, 2021 11:38

For @adeyblue, @coderJeff

This seems to be a general problem with Direct2D (no problem with DirectX or GDI):
We cannot draw or print anything on all last pixels on the right (the last pixel on the right for all lines).

Code: Select all

SetEnviron("fbgfx=Direct2D")
'SetEnviron("fbgfx=DirectX")
'SetEnviron("fbgfx=GDI")

Screen 12
Locate 7, 79
Print Chr(219); Chr(219)
Line (0, 240) - (639, 240)
Line (320, 0) - (320, 479)
Sleep
fxm
Moderator
Posts: 10448
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: CLS command in manual needs updated due to 1.08 changes to ScreenInfo

Postby fxm » Jun 23, 2021 8:44

Another story of number of pixels or intervals between pixels for the definition of the variable 'winWidth' ?
adeyblue
Posts: 78
Joined: Nov 07, 2019 20:08

Re: CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Postby adeyblue » Jun 26, 2021 5:34

I don't understand what you're asking but winWidth is the same number passed as the width to the ScreenRes functions. And in this place of the code, it's which columns of the window need redrawing. GfxLib only keeps track of which rows have been modified, not which columns, so the columns to redraw are always set to all of them, ie the whole width of the window.

It was winWidth - 1 because, for a 640 pixel wide window for example, to me 0-639 would be 640 pixels to draw. But then I suppose it makes sense for the upper bound to be exclusive because when left and right coordinates are the same, that's 0 pixels wide not 1 pixel wide. And now you know why I write banking software not games, because I can't count!
fxm
Moderator
Posts: 10448
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Postby fxm » Jun 26, 2021 7:12

In any case, it works now (version 1.09.0).
Thank you.
dodicat
Posts: 6999
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Postby dodicat » Jun 26, 2021 14:44

Direct pixels use 0 to width-1 to be within range, but still the gap.
Opengl is OK with it's bland screen.
Where can I get version 1.09.0?

Code: Select all

#include "GL/gl.bi"

Screen 12,,,2
dim as string driver
screeninfo ,,,,,,driver
Sub setupgl
    Dim As Integer xres,yres
    Screeninfo xres,yres
    glDisable (GL_DEPTH_TEST)
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
    glEnable (GL_BLEND)
    glEnable (GL_LINE_SMOOTH)
    glOrtho 0, xres, yres,0,-1, 1
    glClearColor 1,1,1,1
End Sub

setupgl


Sub drawstring(xpos As Long,ypos As Long,text As String ,col As Ulong,size As Single,xres As Long,yres As Long) Export
    glMatrixMode GL_PROJECTION 'save projection
    glPushMatrix
    glMatrixMode GL_MODELVIEW
    glPushMatrix
   
    glMatrixMode GL_PROJECTION 'make ortho
    glLoadIdentity
    glOrtho 0, xres, yres, 0,-1, 1
    glMatrixMode GL_MODELVIEW
    glLoadIdentity
    #define Red(c) ((c) Shr 16 And 255)
    #define Green(c) ((c) Shr  8 And 255)
    #define Blue(c) ((c) And 255)
    #define Alph(c) ((c) Shr 24)
    glColor4ub Red(col),Green(col),Blue(col),alph(col)
    glend
    glpointsize(1.1*size)
    glBegin (GL_POINTS)
    Type D2
        As Single x,y
    End Type
    Static As d2 cpt(),XY()
    Static As Long runflag
    If runflag=0 Then   
        Redim  XY(128,255)
        Redim cpt(1 To 64*2)
        Screen 8
        Width 640\8,200\16
        Dim As Ulong Pointer img
        Dim count As Long
        For ch As Long=1 To 255
            img=Imagecreate(640,200)
            Draw String img,(1,1),Chr(ch)
            For x As Long=1 To 8
                For y As Long=1 To 16
                    If Point(x,y,img)<>0 Then
                        count=count+1
                        XY(count,ch)=Type<D2>(x,y)
                    End If
                Next y
            Next x
            count=0
            Imagedestroy img
        Next ch
        runflag=1
    End If
    If size=0 Then Exit Sub
    Dim As D2 np,t
    #macro Scale(p1,p2,d)
    np.x=d*(p2.x-p1.x)+p1.x
    np.y=d*(p2.y-p1.y)+p1.y
    #endmacro
   
    Dim As D2 c=Type<D2>(xpos,ypos)
    Dim As Long dx=xpos,dy=ypos
    For z6 As Long=1 To Len(text)
        Var asci=text[z6-1]
        For _x1 As Long=1 To 64*2
            t=Type<D2>(XY(_x1,asci).x+dx,XY(_x1,asci).y+dy)         
            Scale(c,t,size)
            cpt(_x1)=np
           
            If XY(_x1,asci).x<>0 Then
                If Abs(size)>0 Then
                    glVertex3f (cpt(_x1).x,(cpt(_x1).y),0)
                End If
            End If
        Next _x1
        dx=dx+8
    Next z6
    glend
    glMatrixMode GL_PROJECTION 'restore
    glPopMatrix
    glMatrixMode GL_MODELVIEW
    glPopMatrix
End Sub

Sub inittext Constructor
    drawstring(0,0,"",0,0,0,0)
End Sub


Do
    glClear(GL_COLOR_BUFFER_BIT)
    drawstring(20,20,"I'm All right",Rgb(0,0,0),1,640,480)
    drawstring(20,60,driver,Rgb(0,0,0),1,640,480)
    drawstring(632,100,chr(219),rgb(200,0,0),1,640,480)
    drawstring(632-8-1,100,chr(219),rgb(200,0,0),1,640,480)
    glbegin gl_lines
    glcolor3ub(0,0,200)
    glvertex2d(0,240)
    glvertex2d(640,240)
    glend
   
    Flip
   
    Sleep 1

Loop While Inkey = ""
 
SARG
Posts: 1264
Joined: May 27, 2005 7:15
Location: FRANCE

Re: CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Postby SARG » Jun 26, 2021 15:12

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

Re: CLS example in manual needs updated due to 1.08 changes to ScreenInfo

Postby dodicat » Jun 27, 2021 11:38

Thanks SARG.

Return to “Documentation”

Who is online

Users browsing this forum: No registered users and 2 guests