Click here to Skip to main content
Licence LGPL3
First Posted 20 Dec 2006
Views 37,452
Bookmarked 29 times

A Lightweight Real-time OpenGL Graph Component

By | 20 Dec 2006 | Article
An article on integrating an OpenGL-based graph component that provides real-time updates.

Introduction

I had this need to show some statistics through a graph in real-time, in a demo application which I wrote. The screenshot should illustrate clearly the idea behind this graph component. It will be useful for programmers who would like to track data in real-time, such as in data acquisition and analysis. I did not have time to develop something really elaborate, like different graph types, presentation options, and filters, but it should be very easy to add-on these functionalities from the code.

Using the code

Some of the features of this graph component are:

  • A user-defined cache (list) for storing the graph data
  • When data "overflows" the cache, the graph automatically discards the oldest data to create space for the latest data
  • Moving average is calculated on-the-fly

It is very easy to include this code into any OpenGL-based application. The programmer only needs to make sure he/she has the rendering context.

OGLGraph* myGraph;

void init ( GLvoid )     // Create Some Everyday Functions
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.f);
    //glClearDepth(1.0f);            
    myGraph = OGLGraph::Instance();
    myGraph->setup( 500 /*width*/, 100 /*height*/, 
                    10 /*offsetX*/, 10 /*offsetY*/, 
                    2 /*scaleX*/, 2 /*scaleY*/, 
                    1 /*channels*/, 200 /*cache size*/ );
}

void display ( void )   // Create The Display Function
{
    // ... 

    // This is a dummy function. Replace with custom input/data
    float time = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
    float value;
    value = 5*sin( 5*time ) + 10.f;

    myGraph->update( value );
    myGraph->draw();
}

Source code builds nicely in MS VS.NET 2003.

Points of Interest

You can include any filters like noise reduction, low-pass, or high-pass in the update() code, or even pass post-processed data into this function if you can do that with an external software (e.g., using Matlab).

History

  • First release.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

About the Author

Gabriyel



Singapore Singapore

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalmemory error while data input Pinmemberadityap28617:10 23 Sep '10  
GeneralRe: memory error while data input PinmemberGabriyel20:05 23 Sep '10  
GeneralRe: memory error while data input Pinmemberadityap28617:57 3 Oct '10  
GeneralNeed help in Real-Time OpenGL Graph PinmemberKwan Toh Choong4:39 6 May '09  
GeneralRe: Need help in Real-Time OpenGL Graph PinmemberGabriyel5:06 6 May '09  
GeneralFilemapping technic Pinmembernewspicy11:32 27 May '08  
Im trying to save the incoming data to an file, meanwhile i show it on the screen.
 
One idea i have, is first buffer up the incoming data directly to the memory, and meanwhile it show on the screen
save it to an file, with filemapping technic or on a asynkronic way.
 
But im not sure yeat if its the best way.
 
does anyone else has experience of it?
QuestionHow to add in MFC dialog Pinmemberm0fauzi18:32 22 May '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120604.1 | Last Updated 20 Dec 2006
Article Copyright 2006 by Gabriyel
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid