Revision [14441]

This is an old revision of KeyPgScreenptr made by CountingPine on 2009-08-29 21:56:59.

 

SCREENPTR


Returns a pointer to the current work page's framebuffer

Syntax:
Usage:
result = Screenptr

Return Value:
a pointer to the current work page framebuffer memory, or NULL (0) if no graphics mode is set.

Description:
Screenptr provides a way to directly read/write the working page's framebuffer. KeyPgScreenlock Screenlock should be used before any read or writes are attempted. The pointer returned is valid up until any subsequent call to KeyPgScreengraphics Screen or KeyPgScreenres Screenres, which invalidates it.

Screenptr can also be used to test if a call to KeyPgScreengraphics Screen or KeyPgScreenres Screenres was successful, indicated by a non-NULL (<> 0) return value.
In order to access a pixel in the screen buffer, you will need to know the screen's width, height, bytes per pixel and pitch (bytes per row). This information can be found out using KeyPgScreeninfo Screeninfo.
Each row in the frame buffer is pitch bytes long. The frame buffer consists of height rows, stored in order of their position on the screen, running from top to bottom, left to right.

Examples:
Const SCREEN_WIDTH = 640, SCREEN_HEIGHT = 480
Dim As Integer w, h, bypp, pitch

'' Make 8-bit screen.
ScreenRes SCREEN_WIDTH, SCREEN_HEIGHT, 8

'' Get screen info (w and h should match the constants above, bypp should be 1)
ScreenInfo w, h, , bypp, pitch

'' Get the address of the frame buffer. An Any Ptr
'' is used here to allow simple pointer arithmetic
Dim buffer As Any Ptr = ScreenPtr()
If (buffer = 0) Then
    Print "Error: graphics screen not initialized."
    Sleep
    End -1
End If

'' Lock the screen to allow direct framebuffer access
ScreenLock()
   
    '' Find the address of the pixel in the centre of the screen
    '' It's an 8-bit pixel, so use a UByte Ptr.
    Dim As Integer x = w \ 2, y = h \ 2
    Dim As UByte Ptr pixel = buffer + (y * pitch) + (x * bypp)
   
   
    '' Set the pixel color to 10 (light green).
    *pixel = 10

'' Unlock the screen.
ScreenUnlock()

'' Wait for the user to press a key before closing the program
Sleep

Const SCREEN_WIDTH = 256, SCREEN_HEIGHT = 256
Dim As Integer w, h, bypp, pitch

'' Make 32-bit screen.
ScreenRes SCREEN_WIDTH, SCREEN_HEIGHT, 32

'' Get screen info (w and h should match the constants above, bypp should be 4)
ScreenInfo w, h, , bypp, pitch

'' Get the address of the frame buffer. An Any Ptr
'' is used here to allow simple pointer arithmetic
Dim buffer As Any Ptr = ScreenPtr()
If (buffer = 0) Then
    Print "Error: graphics screen not initialized."
    Sleep
    End -1
End If

'' Lock the screen to allow direct framebuffer access
ScreenLock()
   
    '' Set row address to the start of the buffer
    Dim As Any Ptr row = buffer
   
    '' Iterate over all the pixels in the screen:
   
    For y As Integer = 0 To h - 1
       
        '' Set pixel address to the start of the row
        '' It's a 32-bit pixel, so use a UInteger Ptr
        Dim As UInteger Ptr pixel = row
       
        For x As Integer = 0 To w - 1
           
            '' Set the pixel value
            *pixel = RGB(x, x Xor y, y)
           
            '' Get the next pixel address
            '' (UInteger Ptr will increment by 4 bytes)
            pixel += 1
           
        Next x
       
        '' Go to the next row
        row += pitch
       
    Next y

'' Unlock the screen.
ScreenUnlock()

'' Wait for the user to press a key before closing the program
Sleep



Dialect Differences:
Differences from QB:
See also:
Back to Screen Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode