Loading ...
Sorry, an error occurred while loading the content.

Example Framebuffer/Graphics code...

Expand Messages
  • bomberman0
    Hi everyone, After noticing all the framebuffer talk, I figured I d give it a shot myself. Here s sample code for writing to the ZipIt s screen. (I ve tested
    Message 1 of 7 , Aug 3, 2005
    • 0 Attachment
      Hi everyone,

      After noticing all the framebuffer talk, I figured I'd give it a shot
      myself.

      Here's sample code for writing to the ZipIt's screen. (I've tested it
      and it works fine on my ZipIt.)
      If you know C or C++ at all, it shouldn't be very hard to figure out
      how to draw other stuff with this.

      ====================================

      #include <unistd.h>
      #include <stdio.h>
      #include <fcntl.h>
      #include <linux/fb.h>
      #include <sys/mman.h>

      int main()
      {
      int fbfd = 0;
      struct fb_var_screeninfo vinfo;
      struct fb_fix_screeninfo finfo;
      long int screensize = 0;
      char *fbp = 0;
      int x = 0, y = 0;
      long int location = 0;

      /* Open the file for reading and writing */
      fbfd = open("/dev/fb0", O_RDWR);
      if (!fbfd) {
      printf("Error: cannot open framebuffer device.\n");
      exit(1);
      }
      printf("The framebuffer device was opened successfully.\n");

      /* Get fixed screen information */
      if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
      printf("Error reading fixed information.\n");
      exit(2);
      }

      /* Get variable screen information */
      if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
      printf("Error reading variable information.\n");
      exit(3);
      }

      /* Figure out the size of the screen in bytes */
      screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

      /* Map the device to memory */
      fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE,
      MAP_SHARED, fbfd, 0);
      if ((int)fbp == -1) {
      printf("Error: failed to map framebuffer device to memory.\n");
      exit(4);
      }
      printf("The framebuffer device was mapped to memory successfully.\n");

      for (y = 0; y < 240; y++)
      {
      for (x = 0; x < 320; x++)
      {
      //x = 100; y = 100; /* Where we are going to put the pixel */

      /* Figure out where in memory to put the pixel */
      location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/4) +
      (y+vinfo.yoffset) * finfo.line_length;

      *(fbp + location) = 255; //Paint a black pixel.
      }
      }
      munmap(fbp, screensize);
      close(fbfd);
      return 0;
      }

      ========================================

      As someone mentioned before, I think the tricky part is figuring out
      how to render text... anyone have any ideas?

      As well, what's the deal with people not sharing their code for this
      stuff - Why didn't someone already post a snippet like this? People
      obviously knew how to use the framebuffer... It doesn't take very long
      to post snippets, and it helps developers a lot, you know...


      Thanks,

      Albert
    • ZipItPet
      ... how to render text... anyone have any ideas? FWIW: I have an old version that draws directly to the video memory (works with or without the Linux
      Message 2 of 7 , Aug 4, 2005
      • 0 Attachment
        > As someone mentioned before, I think the tricky part is figuring out
        how to render text... anyone have any ideas?

        FWIW: I have an old version that draws directly to the video memory
        (works with or without the Linux framebuffer driver). Provides an EGA-
        style font (8x8 pixels = 40x30 characters). This was used before the
        linux port was complete (used in my Aibo viewer as well). Very simple
        code (figuring out the nibble order is the only marginally tricky
        part). Email me (zipitpet@...) if interested.

        For generic drawing text on the screen in a small font, printing to
        the console is now easier (ie. 'printf')

        Doing more complicated fonts is much more work (at that point you are
        better of porting an existing graphics package like SDL)
      • dan1123
        I found a little library called libfbx that might work. http://cvs.sourceforge.net/viewcvs.py/u4x/libfbx/ The readme mentions ARM, but a quick browse through
        Message 3 of 7 , Aug 4, 2005
        • 0 Attachment
          I found a little library called libfbx that might work.

          http://cvs.sourceforge.net/viewcvs.py/u4x/libfbx/

          The readme mentions ARM, but a quick browse through the sourcecode
          makes me doubt that it supports such a low bit depth.


          --- In zipitwireless@yahoogroups.com, "ZipItPet" <aibopet@a...> wrote:
          > > As someone mentioned before, I think the tricky part is figuring out
          > how to render text... anyone have any ideas?
          >
          > FWIW: I have an old version that draws directly to the video memory
          > (works with or without the Linux framebuffer driver). Provides an EGA-
          > style font (8x8 pixels = 40x30 characters). This was used before the
          > linux port was complete (used in my Aibo viewer as well). Very simple
          > code (figuring out the nibble order is the only marginally tricky
          > part). Email me (zipitpet@a...) if interested.
          >
          > For generic drawing text on the screen in a small font, printing to
          > the console is now easier (ie. 'printf')
          >
          > Doing more complicated fonts is much more work (at that point you are
          > better of porting an existing graphics package like SDL)
        • Kyle
          This example looks like it fills the screen with black, that about right? I ask as I m thinking of trying to run this in vga16fb on a PC where the screen is
          Message 4 of 7 , Aug 6, 2005
          • 0 Attachment
            This example looks like it fills the screen with black, that about
            right? I ask as I'm thinking of trying to run this in vga16fb on a PC
            where the screen is normally black ;)


            --- In zipitwireless@yahoogroups.com, "bomberman0" <asantoni@u...> wrote:
            > Hi everyone,
            >
            > After noticing all the framebuffer talk, I figured I'd give it a shot
            > myself.
            >
            > Here's sample code for writing to the ZipIt's screen. (I've tested it
            > and it works fine on my ZipIt.)
            > If you know C or C++ at all, it shouldn't be very hard to figure out
            > how to draw other stuff with this.
            >
            > ====================================
            >
            > #include <unistd.h>
            > #include <stdio.h>
            > #include <fcntl.h>
            > #include <linux/fb.h>
            > #include <sys/mman.h>
            >
            > int main()
            > {
            > int fbfd = 0;
            > struct fb_var_screeninfo vinfo;
            > struct fb_fix_screeninfo finfo;
            > long int screensize = 0;
            > char *fbp = 0;
            > int x = 0, y = 0;
            > long int location = 0;
            >
            > /* Open the file for reading and writing */
            > fbfd = open("/dev/fb0", O_RDWR);
            > if (!fbfd) {
            > printf("Error: cannot open framebuffer device.\n");
            > exit(1);
            > }
            > printf("The framebuffer device was opened successfully.\n");
            >
            > /* Get fixed screen information */
            > if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
            > printf("Error reading fixed information.\n");
            > exit(2);
            > }
            >
            > /* Get variable screen information */
            > if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
            > printf("Error reading variable information.\n");
            > exit(3);
            > }
            >
            > /* Figure out the size of the screen in bytes */
            > screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
            >
            > /* Map the device to memory */
            > fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE,
            > MAP_SHARED, fbfd, 0);
            > if ((int)fbp == -1) {
            > printf("Error: failed to map framebuffer device to memory.\n");
            > exit(4);
            > }
            > printf("The framebuffer device was mapped to memory
            successfully.\n");
            >
            > for (y = 0; y < 240; y++)
            > {
            > for (x = 0; x < 320; x++)
            > {
            > //x = 100; y = 100; /* Where we are going to put the
            pixel */
            >
            > /* Figure out where in memory to put the pixel */
            > location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/4) +
            > (y+vinfo.yoffset) * finfo.line_length;
            >
            > *(fbp + location) = 255; //Paint a black pixel.
            > }
            > }
            > munmap(fbp, screensize);
            > close(fbfd);
            > return 0;
            > }
            >
            > ========================================
            >
            > As someone mentioned before, I think the tricky part is figuring out
            > how to render text... anyone have any ideas?
            >
            > As well, what's the deal with people not sharing their code for this
            > stuff - Why didn't someone already post a snippet like this? People
            > obviously knew how to use the framebuffer... It doesn't take very long
            > to post snippets, and it helps developers a lot, you know...
            >
            >
            > Thanks,
            >
            > Albert
          • bomberman0
            Yep, that s exactly what it does... I ve gotta throw this code up on the wiki (with the right formatting) one of these days... Albert
            Message 5 of 7 , Aug 11, 2005
            • 0 Attachment
              Yep, that's exactly what it does... I've gotta throw this code up on
              the wiki (with the right formatting) one of these days...

              Albert

              --- In zipitwireless@yahoogroups.com, "Kyle" <yahoo-shiat@s...> wrote:
              > This example looks like it fills the screen with black, that about
              > right? I ask as I'm thinking of trying to run this in vga16fb on a PC
              > where the screen is normally black ;)
              >
              >
              > --- In zipitwireless@yahoogroups.com, "bomberman0" <asantoni@u...>
              wrote:
              > > Hi everyone,
              > >
              > > After noticing all the framebuffer talk, I figured I'd give it a shot
              > > myself.
              > >
              > > Here's sample code for writing to the ZipIt's screen. (I've tested it
              > > and it works fine on my ZipIt.)
              > > If you know C or C++ at all, it shouldn't be very hard to figure out
              > > how to draw other stuff with this.
              > >
              > > ====================================
              > >
              > > #include <unistd.h>
              > > #include <stdio.h>
              > > #include <fcntl.h>
              > > #include <linux/fb.h>
              > > #include <sys/mman.h>
              > >
              > > int main()
              > > {
              > > int fbfd = 0;
              > > struct fb_var_screeninfo vinfo;
              > > struct fb_fix_screeninfo finfo;
              > > long int screensize = 0;
              > > char *fbp = 0;
              > > int x = 0, y = 0;
              > > long int location = 0;
              > >
              > > /* Open the file for reading and writing */
              > > fbfd = open("/dev/fb0", O_RDWR);
              > > if (!fbfd) {
              > > printf("Error: cannot open framebuffer device.\n");
              > > exit(1);
              > > }
              > > printf("The framebuffer device was opened successfully.\n");
              > >
              > > /* Get fixed screen information */
              > > if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
              > > printf("Error reading fixed information.\n");
              > > exit(2);
              > > }
              > >
              > > /* Get variable screen information */
              > > if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
              > > printf("Error reading variable information.\n");
              > > exit(3);
              > > }
              > >
              > > /* Figure out the size of the screen in bytes */
              > > screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
              > >
              > > /* Map the device to memory */
              > > fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE,
              > > MAP_SHARED, fbfd, 0);
              > > if ((int)fbp == -1) {
              > > printf("Error: failed to map framebuffer device to memory.\n");
              > > exit(4);
              > > }
              > > printf("The framebuffer device was mapped to memory
              > successfully.\n");
              > >
              > > for (y = 0; y < 240; y++)
              > > {
              > > for (x = 0; x < 320; x++)
              > > {
              > > //x = 100; y = 100; /* Where we are going to put the
              > pixel */
              > >
              > > /* Figure out where in memory to put the pixel */
              > > location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/4) +
              > > (y+vinfo.yoffset) * finfo.line_length;
              > >
              > > *(fbp + location) = 255; //Paint a black pixel.
              > > }
              > > }
              > > munmap(fbp, screensize);
              > > close(fbfd);
              > > return 0;
              > > }
              > >
              > > ========================================
              > >
              > > As someone mentioned before, I think the tricky part is figuring out
              > > how to render text... anyone have any ideas?
              > >
              > > As well, what's the deal with people not sharing their code for this
              > > stuff - Why didn't someone already post a snippet like this? People
              > > obviously knew how to use the framebuffer... It doesn't take very long
              > > to post snippets, and it helps developers a lot, you know...
              > >
              > >
              > > Thanks,
              > >
              > > Albert
            • Samson
              it depending on your setup, but if you are telnet or the like into the zipit, the kernel will open the zipit s frame buffer, and the zipit s screen will
              Message 6 of 7 , Aug 13, 2005
              • 0 Attachment
                it depending on your setup, but if you are telnet or the like into the
                zipit, the kernel will open the zipit's frame buffer, and the zipit's
                screen will change.

                (correct me if i am utterly wrong...)

                On 8/6/05, Kyle <yahoo-shiat@...> wrote:
                > This example looks like it fills the screen with black, that about
                > right? I ask as I'm thinking of trying to run this in vga16fb on a PC
                > where the screen is normally black ;)
                >
                >
                >
                > --- In zipitwireless@yahoogroups.com, "bomberman0" <asantoni@u...> wrote:
                > > Hi everyone,
                > >
                > > After noticing all the framebuffer talk, I figured I'd give it a shot
                > > myself.
                > >
                > > Here's sample code for writing to the ZipIt's screen. (I've tested it
                > > and it works fine on my ZipIt.)
                > > If you know C or C++ at all, it shouldn't be very hard to figure out
                > > how to draw other stuff with this.
                > >
                > > ====================================
                > >
                > > #include <unistd.h>
                > > #include <stdio.h>
                > > #include <fcntl.h>
                > > #include <linux/fb.h>
                > > #include <sys/mman.h>
                > >
                > > int main()
                > > {
                > > int fbfd = 0;
                > > struct fb_var_screeninfo vinfo;
                > > struct fb_fix_screeninfo finfo;
                > > long int screensize = 0;
                > > char *fbp = 0;
                > > int x = 0, y = 0;
                > > long int location = 0;
                > >
                > > /* Open the file for reading and writing */
                > > fbfd = open("/dev/fb0", O_RDWR);
                > > if (!fbfd) {
                > > printf("Error: cannot open framebuffer device.\n");
                > > exit(1);
                > > }
                > > printf("The framebuffer device was opened successfully.\n");
                > >
                > > /* Get fixed screen information */
                > > if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
                > > printf("Error reading fixed information.\n");
                > > exit(2);
                > > }
                > >
                > > /* Get variable screen information */
                > > if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
                > > printf("Error reading variable information.\n");
                > > exit(3);
                > > }
                > >
                > > /* Figure out the size of the screen in bytes */
                > > screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
                > >
                > > /* Map the device to memory */
                > > fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE,
                > > MAP_SHARED, fbfd, 0);
                > > if ((int)fbp == -1) {
                > > printf("Error: failed to map framebuffer device to memory.\n");
                > > exit(4);
                > > }
                > > printf("The framebuffer device was mapped to memory
                > successfully.\n");
                > >
                > > for (y = 0; y < 240; y++)
                > > {
                > > for (x = 0; x < 320; x++)
                > > {
                > > //x = 100; y = 100; /* Where we are going to
                > put the
                > pixel */
                > >
                > > /* Figure out where in memory to put the pixel */
                > > location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/4)
                > +
                > > (y+vinfo.yoffset) * finfo.line_length;
                > >
                > > *(fbp + location) = 255; //Paint a black pixel.
                > > }
                > > }
                > > munmap(fbp, screensize);
                > > close(fbfd);
                > > return 0;
                > > }
                > >
                > > ========================================
                > >
                > > As someone mentioned before, I think the tricky part is figuring out
                > > how to render text... anyone have any ideas?
                > >
                > > As well, what's the deal with people not sharing their code for this
                > > stuff - Why didn't someone already post a snippet like this? People
                > > obviously knew how to use the framebuffer... It doesn't take very long
                > > to post snippets, and it helps developers a lot, you know...
                > >
                > >
                > > Thanks,
                > >
                > > Albert
                >
                >
                >
                >
                >
                >
                > ________________________________
                > YAHOO! GROUPS LINKS
                >
                > Visit your group "zipitwireless" on the web.
                >
                > To unsubscribe from this group, send an email to:
                > zipitwireless-unsubscribe@yahoogroups.com
                >
                > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
                > ________________________________
                >


                --
                -samson
              • bomberman0
                Just to confirm, if you SSH or telnet into the zipit and run this executable on the ZipIt, it will black the screen on the ZipIt. If you compile and run this
                Message 7 of 7 , Aug 14, 2005
                • 0 Attachment
                  Just to confirm, if you SSH or telnet into the zipit and run this
                  executable on the ZipIt, it will black the screen on the ZipIt.

                  If you compile and run this on your desktop PC, it'll draw weird lines
                  probably, because the bit depth is not 4-bit...

                  Albert


                  --- In zipitwireless@yahoogroups.com, Samson <fragmede@g...> wrote:
                  > it depending on your setup, but if you are telnet or the like into the
                  > zipit, the kernel will open the zipit's frame buffer, and the zipit's
                  > screen will change.
                  >
                  > (correct me if i am utterly wrong...)
                  >
                  > On 8/6/05, Kyle <yahoo-shiat@s...> wrote:
                  > > This example looks like it fills the screen with black, that about
                  > > right? I ask as I'm thinking of trying to run this in vga16fb on a PC
                  > > where the screen is normally black ;)
                  > >
                  > >
                  > >
                  > > --- In zipitwireless@yahoogroups.com, "bomberman0" <asantoni@u...>
                  wrote:
                  > > > Hi everyone,
                  > > >
                  > > > After noticing all the framebuffer talk, I figured I'd give it a
                  shot
                  > > > myself.
                  > > >
                  > > > Here's sample code for writing to the ZipIt's screen. (I've
                  tested it
                  > > > and it works fine on my ZipIt.)
                  > > > If you know C or C++ at all, it shouldn't be very hard to figure out
                  > > > how to draw other stuff with this.
                  > > >
                  > > > ====================================
                  > > >
                  > > > #include <unistd.h>
                  > > > #include <stdio.h>
                  > > > #include <fcntl.h>
                  > > > #include <linux/fb.h>
                  > > > #include <sys/mman.h>
                  > > >
                  > > > int main()
                  > > > {
                  > > > int fbfd = 0;
                  > > > struct fb_var_screeninfo vinfo;
                  > > > struct fb_fix_screeninfo finfo;
                  > > > long int screensize = 0;
                  > > > char *fbp = 0;
                  > > > int x = 0, y = 0;
                  > > > long int location = 0;
                  > > >
                  > > > /* Open the file for reading and writing */
                  > > > fbfd = open("/dev/fb0", O_RDWR);
                  > > > if (!fbfd) {
                  > > > printf("Error: cannot open framebuffer device.\n");
                  > > > exit(1);
                  > > > }
                  > > > printf("The framebuffer device was opened successfully.\n");
                  > > >
                  > > > /* Get fixed screen information */
                  > > > if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
                  > > > printf("Error reading fixed information.\n");
                  > > > exit(2);
                  > > > }
                  > > >
                  > > > /* Get variable screen information */
                  > > > if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
                  > > > printf("Error reading variable information.\n");
                  > > > exit(3);
                  > > > }
                  > > >
                  > > > /* Figure out the size of the screen in bytes */
                  > > > screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
                  > > >
                  > > > /* Map the device to memory */
                  > > > fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE,
                  > > > MAP_SHARED, fbfd, 0);
                  > > > if ((int)fbp == -1) {
                  > > > printf("Error: failed to map framebuffer device to
                  memory.\n");
                  > > > exit(4);
                  > > > }
                  > > > printf("The framebuffer device was mapped to memory
                  > > successfully.\n");
                  > > >
                  > > > for (y = 0; y < 240; y++)
                  > > > {
                  > > > for (x = 0; x < 320; x++)
                  > > > {
                  > > > //x = 100; y = 100; /* Where we are
                  going to
                  > > put the
                  > > pixel */
                  > > >
                  > > > /* Figure out where in memory to put the pixel */
                  > > > location = (x+vinfo.xoffset) *
                  (vinfo.bits_per_pixel/4)
                  > > +
                  > > > (y+vinfo.yoffset) * finfo.line_length;
                  > > >
                  > > > *(fbp + location) = 255; //Paint a black pixel.
                  > > > }
                  > > > }
                  > > > munmap(fbp, screensize);
                  > > > close(fbfd);
                  > > > return 0;
                  > > > }
                  > > >
                  > > > ========================================
                  > > >
                  > > > As someone mentioned before, I think the tricky part is figuring out
                  > > > how to render text... anyone have any ideas?
                  > > >
                  > > > As well, what's the deal with people not sharing their code for this
                  > > > stuff - Why didn't someone already post a snippet like this? People
                  > > > obviously knew how to use the framebuffer... It doesn't take
                  very long
                  > > > to post snippets, and it helps developers a lot, you know...
                  > > >
                  > > >
                  > > > Thanks,
                  > > >
                  > > > Albert
                  > >
                  > >
                  > >
                  > >
                  > >
                  > >
                  > > ________________________________
                  > > YAHOO! GROUPS LINKS
                  > >
                  > > Visit your group "zipitwireless" on the web.
                  > >
                  > > To unsubscribe from this group, send an email to:
                  > > zipitwireless-unsubscribe@yahoogroups.com
                  > >
                  > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
                  > > ________________________________
                  > >
                  >
                  >
                  > --
                  > -samson
                Your message has been successfully submitted and would be delivered to recipients shortly.