Port-sparc64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Creator3D programming



On Wed, 24 Jun 2009 00:02:54 +0100
raymond.meyer%rambler.ru@localhost wrote:

> Can anyone give me a few examples of how to modify pixels on the
> screen? How does Xorg sunffb use the hardware, does it use
> framebuffer rendering pipeline? Say for example, I want to set pixel
> at location (10, 10) to black colour, can I use either direct (i.e.
> bypass rendering pipeline) or accelerated path? How can I do it?

OK, nevermind, I managed to figure it out eventually.
If anyone is interested, check out the following C program. It draws 3
graident lines in the top left corner of the screen. It modifies pixels
directly in the framebuffer's memory
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
        int fb;
        volatile void *sfb32;

        if((fb = open("/dev/fb0", O_RDWR, 0)) == -1)
        {
                perror("Error opening fb");
                exit(1);
        }
        
        /*
        -- mmap SFB32 framebuffer access mode, which starts at offset 0x5000000 
        -- from the base address.
        */
        if((sfb32 = mmap(NULL, 0x1000000, PROT_READ | PROT_WRITE, MAP_PRIVATE,
                fb, 0x5000000)) == MAP_FAILED)
        {
                perror("Error mmapping fb");
                exit(1);
        }

/*
Address Format:

00000101000011001000000110010000
        yyyyyyyyyyyxxxxxxxxxxxzz

y = 11-bit Y pixel coordinate (e.g. 100)
x = 11-bit X pixel coordinate (e.g. 100)
z = always zero
*/

        {
        int i, y_loc, x_loc;
        uint32_t pixel;

        /* Draw Blue gradient */
        y_loc = 100;
        x_loc = 100;
        for(i = 0; i < 256; i++)
        {
                pixel = (i << 16);
                *((uint32_t *)(sfb32 + (((y_loc + 0) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 1) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 2) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 3) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 4) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 5) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 6) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 7) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 8) << 13) | (x_loc << 2)))) = 
pixel;
                x_loc++;
                usleep(1000);
        }/* end for */

        /* Draw Green gradient */
        y_loc = 112;
        x_loc = 100;
        for(i = 0; i < 256; i++)
        {
                pixel = (i << 8);
                *((uint32_t *)(sfb32 + (((y_loc + 0) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 1) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 2) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 3) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 4) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 5) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 6) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 7) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 8) << 13) | (x_loc << 2)))) = 
pixel;
                x_loc++;
                usleep(1000);
        }/* end for */

        /* Draw Red gradient */
        y_loc = 124;
        x_loc = 100;
        for(i = 0; i < 256; i++)
        {
                pixel = i;
                *((uint32_t *)(sfb32 + (((y_loc + 0) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 1) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 2) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 3) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 4) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 5) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 6) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 7) << 13) | (x_loc << 2)))) = 
pixel;
                *((uint32_t *)(sfb32 + (((y_loc + 8) << 13) | (x_loc << 2)))) = 
pixel;
                x_loc++;
                usleep(1000);
        }/* end for */
        }

        exit(0);
}


Home | Main Index | Thread Index | Old Index