ScreenPtr
 
Returns a pointer to the current work page's framebuffer

Syntax

Declare Function ScreenPtr ( ) As Any Ptr

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. ScreenLock should be used before any read or writes are attempted. The pointer returned is valid up until any subsequent call to Screen or ScreenRes, which invalidates it.

ScreenPtr can also be used to test if a call to Screen or 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 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.

Because of the design of FreeBasic graphics library, ScreenPtr (if non-ZERO) will always point to the backbuffer, and never to actual video RAM.

Example

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

  • Not available in the -lang qb dialect unless referenced with the alias __Screenptr.

Differences from QB

  • New to FreeBASIC

See also

Сайт ПДСНПСР. Если ты патриот России - жми сюда!


Знаете ли Вы, что релятивистское объяснение феномену CMB (космическому микроволновому излучению) придумал человек выдающейся фантазии Иосиф Шкловский (помните книжку миллионного тиража "Вселенная, жизнь, разум"?). Он выдвинул совершенно абсурдную идею, заключавшуюся в том, что это есть "реликтовое" излучение, оставшееся после "Большого Взрыва", то есть от момента "рождения" Вселенной. Хотя из простой логики следует, что Вселенная есть всё, а значит, у нее нет ни начала, ни конца... Подробнее читайте в FAQ по эфирной физике.

НОВОСТИ ФОРУМАФорум Рыцари теории эфира
Рыцари теории эфира
 10.11.2021 - 12:37: ПЕРСОНАЛИИ - Personalias -> WHO IS WHO - КТО ЕСТЬ КТО - Карим_Хайдаров.
10.11.2021 - 12:36: СОВЕСТЬ - Conscience -> РАСЧЕЛОВЕЧИВАНИЕ ЧЕЛОВЕКА. КОМУ ЭТО НАДО? - Карим_Хайдаров.
10.11.2021 - 12:36: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от д.м.н. Александра Алексеевича Редько - Карим_Хайдаров.
10.11.2021 - 12:35: ЭКОЛОГИЯ - Ecology -> Биологическая безопасность населения - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> Проблема государственного терроризма - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> ПРАВОСУДИЯ.НЕТ - Карим_Хайдаров.
10.11.2021 - 12:34: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вадима Глогера, США - Карим_Хайдаров.
10.11.2021 - 09:18: НОВЫЕ ТЕХНОЛОГИИ - New Technologies -> Волновая генетика Петра Гаряева, 5G-контроль и управление - Карим_Хайдаров.
10.11.2021 - 09:18: ЭКОЛОГИЯ - Ecology -> ЭКОЛОГИЯ ДЛЯ ВСЕХ - Карим_Хайдаров.
10.11.2021 - 09:16: ЭКОЛОГИЯ - Ecology -> ПРОБЛЕМЫ МЕДИЦИНЫ - Карим_Хайдаров.
10.11.2021 - 09:15: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Екатерины Коваленко - Карим_Хайдаров.
10.11.2021 - 09:13: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вильгельма Варкентина - Карим_Хайдаров.
Bourabai Research Institution home page

Боровское исследовательское учреждение - Bourabai Research Bourabai Research Institution