Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 352993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:47:20+00:00 2026-05-12T11:47:20+00:00

I’m a scientist who is quite comfortable with C for numerical computation, but I

  • 0

I’m a scientist who is quite comfortable with C for numerical computation, but I need some help with displaying the results. I want to be able to display a continuously updated bitmap in a window, which is calculated from realtime data. I’d like to be able to update the image quite quickly (e.g. faster than 1 frame/second, preferably 100 fps). For example:

char image_buffer[width*height*3];//rgb data
initializewindow();

for (t=0;t<t_end;t++)
{
   getdata(data);//get some realtime data
   docalcs(image_buffer, data);//process the data into an image
   drawimage(image_buffer);//draw the image
}

What’s the easiest way to do this on linux (Ubuntu)? What should I use for initializewindow() and drawimage()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:47:20+00:00Added an answer on May 12, 2026 at 11:47 am

    If all you want to do is display the data (ie no need for a GUI), you might want to take a look at SDL: It’s straight-forward to create a surface from your pixel data and then display it on screen.

    Inspired by Artelius’ answer, I also hacked up an example program:

    #include <SDL/SDL.h>
    #include <assert.h>
    #include <stdint.h>
    #include <stdlib.h>
    
    #define WIDTH 256
    #define HEIGHT 256
    
    static _Bool init_app(const char * name, SDL_Surface * icon, uint32_t flags)
    {
        atexit(SDL_Quit);
        if(SDL_Init(flags) < 0)
            return 0;
    
        SDL_WM_SetCaption(name, name);
        SDL_WM_SetIcon(icon, NULL);
    
        return 1;
    }
    
    static uint8_t * init_data(uint8_t * data)
    {
        for(size_t i = WIDTH * HEIGHT * 3; i--; )
            data[i] = (i % 3 == 0) ? (i / 3) % WIDTH :
                (i % 3 == 1) ? (i / 3) / WIDTH : 0;
    
        return data;
    }
    
    static _Bool process(uint8_t * data)
    {
        for(SDL_Event event; SDL_PollEvent(&event);)
            if(event.type == SDL_QUIT) return 0;
    
        for(size_t i = 0; i < WIDTH * HEIGHT * 3; i += 1 + rand() % 3)
            data[i] -= rand() % 8;
    
        return 1;
    }
    
    static void render(SDL_Surface * sf)
    {
        SDL_Surface * screen = SDL_GetVideoSurface();
        if(SDL_BlitSurface(sf, NULL, screen, NULL) == 0)
            SDL_UpdateRect(screen, 0, 0, 0, 0);
    }
    
    static int filter(const SDL_Event * event)
    { return event->type == SDL_QUIT; }
    
    #define mask32(BYTE) (*(uint32_t *)(uint8_t [4]){ [BYTE] = 0xff })
    
    int main(int argc, char * argv[])
    {
        (void)argc, (void)argv;
        static uint8_t buffer[WIDTH * HEIGHT * 3];
    
        _Bool ok =
            init_app("SDL example", NULL, SDL_INIT_VIDEO) &&
            SDL_SetVideoMode(WIDTH, HEIGHT, 24, SDL_HWSURFACE);
    
        assert(ok);
    
        SDL_Surface * data_sf = SDL_CreateRGBSurfaceFrom(
            init_data(buffer), WIDTH, HEIGHT, 24, WIDTH * 3,
            mask32(0), mask32(1), mask32(2), 0);
    
        SDL_SetEventFilter(filter);
    
        for(; process(buffer); SDL_Delay(10))
            render(data_sf);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.