Click here to Skip to main content
13,344,287 members (81,328 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 20 Dec 2006

A Lightweight Real-time OpenGL Graph Component

, 20 Dec 2006
Rate this:
Please Sign up or sign in to vote.
An article on integrating an OpenGL-based graph component that provides real-time updates.


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);
    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 );

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).


  • First release.


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


About the Author

Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionMultiple graphs on the same display Pin
V6128-Dec-15 0:44
memberV6128-Dec-15 0:44 
GeneralMy vote of 5 Pin
dsn8713-Aug-12 6:44
memberdsn8713-Aug-12 6:44 
Generalmemory error while data input Pin
adityap28623-Sep-10 18:10
memberadityap28623-Sep-10 18:10 
GeneralRe: memory error while data input Pin
Gabriyel23-Sep-10 21:05
memberGabriyel23-Sep-10 21:05 
GeneralRe: memory error while data input Pin
adityap2863-Oct-10 18:57
memberadityap2863-Oct-10 18:57 
GeneralNeed help in Real-Time OpenGL Graph Pin
Kwan Toh Choong6-May-09 5:39
memberKwan Toh Choong6-May-09 5:39 
GeneralRe: Need help in Real-Time OpenGL Graph Pin
Gabriyel6-May-09 6:06
memberGabriyel6-May-09 6:06 
GeneralFilemapping technic Pin
newspicy27-May-08 12:32
membernewspicy27-May-08 12:32 
QuestionHow to add in MFC dialog Pin
m0fauzi22-May-07 19:32
memberm0fauzi22-May-07 19:32 
Hi i'm new here.currently im using MSVC V6.0. i want to add some graph in my application by using MFC dialog base. I dun have any idea about OpenGL. Can u help me show how to include the code u made inside my application


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 20 Dec 2006
Article Copyright 2006 by Gabriyel
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid