-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Thu Dec 03, 2015 3:09 pm

Now that I 'was woken up' ;) a new post (quick & short for now) about palette animation (color cycling).
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Wed Feb 10, 2016 2:38 pm

Forgot to mention here: a new post two weeks ago around image color format conversion (based on discussion here viewtopic.php?f=32&t=57810#p892207 )

http://raspberrycompote.blogspot.ie/201 ... ry-pi.html

And another quick piece on palette animation / color cycling - slightly more interesting and inspiring demo hopefully :)

http://raspberrycompote.blogspot.com/20 ... -more.html
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Thu Feb 11, 2016 12:07 pm

http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Wed Feb 24, 2016 4:56 pm

Simple example on reading in an image file and displaying the image http://raspberrycompote.blogspot.ie/201 ... re_24.html
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

itsagoodquestion
Posts: 47
Joined: Sat Mar 05, 2016 10:30 pm

Re: Low-level (Linux framebuffer) graphics programming tutor

Sat Mar 05, 2016 11:27 pm

Wow... this is a lot of fun, it's really similar to GDI in Windows! I would really, really like to get this working on my raspberry pi v2 b+, but whenever I run this code - http://raspberrycompote.blogspot.com.ar ... -part.html - the entire screen goes black. I have my Pi hooked up to a small TV over HDMI. Can you tell me how to fix this please? Thanks!

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Mon Mar 07, 2016 9:40 am

Hmm, that sounds odd. I only have version 1 Pis so cannot be 100% sure but I have tested with both the older Wheezy versions of Raspbian and the latest Jessie.

Does it return back to the shell prompt after 5 seconds (as it should)?

Which OS and version you have (what does 'uname -a' output)?
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

itsagoodquestion
Posts: 47
Joined: Sat Mar 05, 2016 10:30 pm

Re: Low-level (Linux framebuffer) graphics programming tutor

Tue Mar 08, 2016 10:04 pm

Hey there, thanks for your response.

Code: Select all

$ uname -a
Linux raspberrypi 4.1.17-v7+ #838 SMP Tue Feb 9 13:15:09 GMT 2016 armv7l GNU/Linux
The code from your tutorial #2 works as intended, but it does not return my desktop me. All the other codes I tried give me a black screen. So anytime after I run it, I have to reboot the machine via serial to tty cable to get display back. I've also tried running fbset w/depth-16 set before and that doesn't work either.

I haven't had much time lately to troubleshoot it I was just hoping you knew a quick fix, but I look very forward to getting this code working when I get more time :D :D :D

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Wed Mar 09, 2016 9:33 am

[quote="itsagoodquestion"... So anytime after I run it, I have to reboot the machine via serial to tty cable to get display back. I've also tried running fbset w/depth-16 set before and that doesn't work either. ...[/quote]

One trick that might help in these situations (obviously if it is not a complete lock up) is the use of the virtual consoles: hit Ctrl+Alt+F2 to get to the second console, login and reboot from there (of course the serial tty or a ssh session is about the same but this does not require another computer).
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

ciel77
Posts: 6
Joined: Fri Jun 09, 2017 11:05 pm

Re: Low-level (Linux framebuffer) graphics programming tutor

Fri Jun 09, 2017 11:11 pm

Great post! Thank you so much for writing this up.
I have no problem running switch page using your "ioctl version", however, I got "ioctl_set_msg failed:-1" when running "mailbox version". I am using raspberry pi 3 B+ with jessie 8. I need to change major device number in vcio.h from 100 to 248. But still cannot figuring out what's causing "ioctl_set_msg failed:-1". I have been searching around but couldn't find a solution. Any thoughts on what I am missing here? Thank you.

ciel77
Posts: 6
Joined: Fri Jun 09, 2017 11:05 pm

Re: Low-level (Linux framebuffer) graphics programming tutor

Fri Jun 09, 2017 11:13 pm

Great post! Thank you so much for writing this up.
I have no problem running switch page using "ioctl version", however, I got "ioctl_set_msg failed:-1" when running "mailbox version". I am using raspberry pi 3 B+ with jessie 8. I need to change major device number in vcio.h from 100 to 248. But still cannot figuring out what's causing "ioctl_set_msg failed:-1". I have been searching around but couldn't find a solution. Any thoughts on what I am missing here? Thank you.

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Low-level (Linux framebuffer) graphics programming tutor

Mon Jun 12, 2017 5:03 pm

The mailbox interface seems to have changed at some point and will likely not work anymore (as I think I pointed out in one of the posts).
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

ciel77
Posts: 6
Joined: Fri Jun 09, 2017 11:05 pm

Re: Low-level (Linux framebuffer) graphics programming tutor

Tue Jun 13, 2017 2:27 am

-rst- wrote:The mailbox interface seems to have changed at some point and will likely not work anymore (as I think I pointed out in one of the posts).
Thank you for the reply. Based on https://github.com/raspberrypi/firmware ... ual-offset, I modified the code as below and but it's not working:

Code: Select all

   p[i++] = 0; // size
   p[i++] = 0x00000000; // process request

   p[i++] = 0x00048009; // set virtual offset
   p[i++] = 0x00000008; 
   p[i++] = 0x00000008; 
   p[i++] = *x; // value buffer
   p[i++] = *y; // value buffer 2
Am I using the mailbox interface wrong?

User avatar
paulwratt
Posts: 72
Joined: Fri Jun 12, 2015 12:15 am

Re: Low-level (Linux framebuffer) graphics programming tutorial

Fri Sep 01, 2017 2:19 am

I just spent 2 days with repo/fb/font/fbtestfnt.c getting it to work on a late 2016 build of Raspbian (PipaOS 5 XGUI) (kernal 4.4.50-v7+), and althought I just lost all the code, I thought I post some info about it. NOTE this is all in framebuffer console mode on an UNIDEN 12v (marine) HDMI output, ie NOT in X (although it may work):

Jessie & Wheezy prior to late 2016 used to report framebuffer as 15bit or 16bit, now its 32bit.

Out of the box fbtestfnt.c does not work as expected, nor report an error.

16bit instead of 8bit
fbtestfnt.c will work in if you can change vinfo.bits_per_pixel, declare some colors globally, and modify the put_pixel function to take a string of characters as the color instead of an integer. Without modifying anything else, the new framebuffer color bit mask is BBBBBrrrrrGGGGGG (BRG556):

Code: Select all

(under struct definitions)
char* cBLACK="\x00\x00";
char* cYELLOW="\x07\xFF";
char* cLIGHTBLUE="\xF0\x00";
char* cBLUE="\xF8\x00";
char* cRED="\x07\xC0";
char* cWHITE="\xFF\xFF";

void put_pixel (int x, int y, char* c)
{
	int cl,ci,cp;
	unsigned int pixel_offset = ( x * ( vinfo.bits_per_pixel / 8 )) + (  y * finfo.line_length);
	
	cl = strlen(c);
	for(ci=0; ci<cl; ci++) {
		cp = c[ci];
		*((char*)(fbp * pixel_offset + ci) = cp;
	}
}

void fill_rect (int x, int y, int w, int h, char* c)
{
	int cx,cy;
	for(cx=0; cy<h; cy++) {
		for (cx=0; cx<w; cx++) {
			put_pixel(cx, cy, c);
		}
	}
}
Change textC in all the put_pixel() calls & the 1 in fill_rect() call to a cCOLOR. I chose cLIGHTBLUE for the fill_rect(), cYELLOW for the first draw() loop, and cWHITE for the "demo" loop. The for loop in the put_pixel() function allows the color byte length to change without modifying the put_pixel() function again.

In the main() function, if I changed the line vinfo.xres & vinfo.yres to 640 & 480 respectively, I got a nice centered fullscreen MSX style out, with cYELLOW for any supplied text. With the following ascii.sh script and a full set of fonts (in fbtextfnt.h), on the command line I was able to do:

Code: Select all

TEXT=`./ascii.sh`; ./fbtestfnt "$TEXT" 2>&1 >fbtestfnt.txt

Code: Select all

#!/bin/sh
for i in `seq 32 127`; do print \\$(printf '%03o\t` "$i"); done; printf "\n"
32bit mode
32 bit works with 32bit color bit mask (BGRA) and some cCOLOR32 colors defined, font pixels are placed in the right colors, but the fill_rect() function with cBLACK32 does not work as expected (alpha maybe?). If you skip the parts of the code in main() where it sets vinfo values & the ioctl(), set some 32bit color values, and comment out the fill_rect() call, you can get a pretty picture as the background (even works in infbterm):

Code: Select all

cat image.fbimg > /dev/fb0; ./fbtestfnt "$TEXT" 2>&1 >fbtestfnt.txt
I do see an update regarding vinfo.bits_per_pixel on Raspberry Compote Blog site.

NOTE: alternately you can use shell script to dd values directly into /dev/fb0.

Cheers

Paul

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 4 guests