Author Topic: rendered BMP to FLTK window  (Read 5187 times)

0 Members and 1 Guest are viewing this topic.

Offline BlinkenLights

  • he's just this guy, ya know?
  • Administrator
  • Hero Member
  • *****
  • Posts: 726
  • Milliwatts: 4
  • Gender: Male
  • 'The Messenger' by Will Cascio
    • View Profile
rendered BMP to FLTK window
« on: April 13, 2009, 10:29:35 pm »
check this..

The math is all mine :)

i started with an example tho

run attachment (its safe promise)

Code: [Select]
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>
#include <stdio.h>
#include <time.h>

#define XSIZE 640
#define YSIZE 640
#define UPDATE_RATE 0.01     // update speed


// WINDOW CLASS TO HANDLE DRAWING IMAGE
class MyWindow : public Fl_Double_Window {
    unsigned char pixbuf[YSIZE][XSIZE][3];              // image buffer

    // FLTK DRAW METHOD
    void draw() {
        fl_draw_image((const uchar*)&pixbuf, 0, 0, XSIZE, YSIZE, 3, XSIZE*3);
    }

    // TIMER CALLBACK: CALLED TO UPDATE THE DRAWING
    static void RenderImage_CB(void *userdata) {
        MyWindow *win = (MyWindow*)userdata;
        win->RenderImage();
        Fl::repeat_timeout(UPDATE_RATE, RenderImage_CB, userdata);
    }

public:
    // CTOR
    MyWindow(int w, int h, const char *name=0) : Fl_Double_Window(w,h,name) {
        end();
        RenderImage();                   // show first drawing
        // Start timer updating
        Fl::add_timeout(UPDATE_RATE, RenderImage_CB, (void*)this);
    }

    // PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER
    void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
        pixbuf[y][x][2] = r;
        pixbuf[y][x][1] = g;
        pixbuf[y][x][0] = b;
    }

    // MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT
    void RenderImage() {
        static unsigned char drawcount = 0;
        for ( int x=0; x<XSIZE; x++ )
            for ( int y=0; y<XSIZE; y++ )
                PlotPixel(x, y, x+drawcount*drawcount, y+drawcount*drawcount, x*y+drawcount*drawcount);
        ++drawcount;
        redraw();
    }
};

int main(int argc, char**argv) {
    Fl::visual(FL_RGB);         // prevents dithering on some systems
    MyWindow *win = new MyWindow(XSIZE, YSIZE);
    win->show();
    return(Fl::run());
}

Offline BlinkenLights

  • he's just this guy, ya know?
  • Administrator
  • Hero Member
  • *****
  • Posts: 726
  • Milliwatts: 4
  • Gender: Male
  • 'The Messenger' by Will Cascio
    • View Profile
Re: rendered BMP to FLTK window
« Reply #1 on: April 13, 2009, 11:03:20 pm »
Better math :)
Code: [Select]
    // PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER
    void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
        pixbuf[y][x][0] = r;
        pixbuf[y][x][1] = g;
        pixbuf[y][x][2] = b;
    }

    // MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT
    void RenderImage() {
        static unsigned char drawcount = 0;
        for ( int x=0; x<XSIZE; x++ )
            for ( int y=0; y<XSIZE; y++ )
                PlotPixel(x, y, drawcount+y/3.14, drawcount+x/3.14, x*y*.01);
        ++drawcount;
        redraw();
    }
};
« Last Edit: April 13, 2009, 11:08:38 pm by BlinkenLights »

Offline drlava

  • Sr. Member
  • ****
  • Posts: 314
  • Milliwatts: 18
    • View Profile
Re: rendered BMP to FLTK window
« Reply #2 on: April 14, 2009, 08:10:05 pm »
FLTK is totally awesome.  I use it for ILD SOS and couldn't be happier!
Enjoy your experimentation ;)

Offline BlinkenLights

  • he's just this guy, ya know?
  • Administrator
  • Hero Member
  • *****
  • Posts: 726
  • Milliwatts: 4
  • Gender: Male
  • 'The Messenger' by Will Cascio
    • View Profile
Re: rendered BMP to FLTK window
« Reply #3 on: April 14, 2009, 10:47:04 pm »
next i add widgets... :):)

Offline BlinkenLights

  • he's just this guy, ya know?
  • Administrator
  • Hero Member
  • *****
  • Posts: 726
  • Milliwatts: 4
  • Gender: Male
  • 'The Messenger' by Will Cascio
    • View Profile
Re: rendered BMP to FLTK window
« Reply #4 on: April 20, 2009, 09:08:00 pm »
PI is cool

Code: [Select]
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>
#include <stdio.h>
#include <time.h>
#include <math.h>

#define XSIZE 640
#define YSIZE 640
#define UPDATE_RATE .01     // update speed
const double PI = 4.0*atan(1.0);



// WINDOW CLASS TO HANDLE DRAWING IMAGE
class MyWindow : public Fl_Double_Window {
    unsigned char pixbuf[YSIZE][XSIZE][3];              // image buffer

    // FLTK DRAW METHOD
    void draw() {
        fl_draw_image((const uchar*)&pixbuf, 0, 0, XSIZE, YSIZE, 3, XSIZE*3);
    }

    // TIMER CALLBACK: CALLED TO UPDATE THE DRAWING
    static void RenderImage_CB(void *userdata) {
        MyWindow *win = (MyWindow*)userdata;
        win->RenderImage();
        Fl::repeat_timeout(UPDATE_RATE, RenderImage_CB, userdata);
    }

public:
    // CTOR
    MyWindow(int w, int h, const char *name=0) : Fl_Double_Window(w,h,name) {
        end();
        RenderImage();                   // show first drawing
        // Start timer updating
        Fl::add_timeout(UPDATE_RATE, RenderImage_CB, (void*)this);
    }

    // PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER
    void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
        pixbuf[y][x][0] = r;
        pixbuf[y][x][1] = g;
        pixbuf[y][x][2] = b;
    }

    // MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT
    void RenderImage() {
        static unsigned char drawcount = 0;
        for ( int x=0; x<XSIZE; x++ )
            for ( int y=0; y<XSIZE; y++ )
                PlotPixel(x, y, ((drawcount*PI)+y)*.003*x, ((drawcount*PI)+x)*.002*y, drawcount*(PI*.001)*((x+y)/2) );
        ++drawcount;
        redraw();
    }
};

int main(int argc, char**argv) {
    Fl::visual(FL_RGB);         // prevents dithering on some systems
    MyWindow *win = new MyWindow(XSIZE, YSIZE);
    win->show();
    return(Fl::run());
}


 

SMF spam blocked by CleanTalk