Help with selecting a graphics library for Visual Studio C++

Hi,

I am an embedded C programmer. I am working on a project which collects a lot of data from multiple sensors. I need to be able to display this data in a graphics format, pixels and lines. I recently downloaded Visual Studio C++ and found it easy to use, but was surprised to find it has no built in graphics libraries. Since I used Borland’s Pascal years ago I was temped to WinBgim, but it is apparently very old and I don’t want to start using an obsolete library. I am looking for an easy to use graphics library for which I can use with Visual Studio C++ 2019 to read data from a text file and use that data to put pixels and lines on the screen. Nothing fancy. Any recommendations?

Thanks for your help,

Bob

There actually is a built in one, but it is frowned upon because it is not 'high performance**'. However it is easy to use and I had a real time plotting program using it a few years ago, basically it was a scrolling window and I drew the latest point on the right hand side then scrolled everything to the left each iteration. https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-using-gdi--use
Note that its somewhat dated but still used in simple programs.

If you just want to PLOT data, I believe VS has built in excel plots you can use? This is positively ancient but I didn't have time to find the 2019 version links. Something like this should still exist.

https://klmlinks.wordpress.com/2016/06/17/microsoft-com-how-to-embed-and-automate-an-excel-worksheet-by-using-mfc-and-visual-c-2005/

**its more than fast enough if you are not writing a modern game.
Last edited on

You can use the console for barebones graphics via gdi.
Here are my compiler switches for gcc
-std=c++0x -lUxtheme -lgdi32
simple example (colour getter):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#define WIN32_LEAN_AND_MEAN
#include<windows.h>
#include <Uxtheme.h>  // blue frame only
#include <stdio.h>
#include <iostream>


union colour
{
    unsigned int c;     // occupies 4 bytes
    struct 
    {
    unsigned char r; 
    unsigned char g;     // each occupies 1 byte
    unsigned char b;
    unsigned char a;
};
};  

                 

void Locate( int column, int line,int d )
  {
  COORD coord;
  coord.Y = column;
  coord.X = line;
  SetConsoleCursorPosition(
    GetStdHandle( STD_OUTPUT_HANDLE ),
    coord
    );
  }

int main()
{

HWND p = GetConsoleWindow();
POINT pt;
colour clr;
int r=50;
SetWindowPos(p, HWND_TOPMOST, 100, 100, 200, 280, SWP_SHOWWINDOW); // size the window here
SetWindowTheme(p,L" ",L" ");
system("title [MOVE]");
ShowScrollBar(p, SB_BOTH, FALSE);

HDC h=GetDC(0), wh=GetDC(p);
SelectObject(wh,GetStockObject(DC_BRUSH));
SelectObject(wh,GetStockObject(DC_PEN));
while (p!=0)
{
      GetCursorPos(&pt);
      clr.c=GetPixel(h,pt.x,pt.y);
      ShowScrollBar(p, SB_BOTH, FALSE);
      SetDCBrushColor(wh,clr.c);
      SetDCPenColor(wh,clr.c);
      Ellipse(wh,(95-r),(70-r),(95+r),(70+r));
      printf("\e[?25l"); // hide the cursor
      Locate(10,3,0);
      printf("Red   %s","   ");
      Locate(10,3,0);
      printf("Red   %d",clr.r);
      Locate(11,3,0);
      printf("Green %s","   ");
      Locate(11,3,0);
      printf("Green %d",clr.g);
     
      Locate(12,3,0);
      printf("Blue  %s","   ");
      Locate(12,3,0);
      printf("Blue  %d",clr.b);
     
      Locate(13,3,0);
      printf("HEX   %s","          ");
      Locate(13,9,0);
      std::cout<<std::hex<<clr.c;
     
      Locate(14,3,0);
      printf("RAW   %s","          ");
      Locate(14,3,0);
      printf("RAW   %d",clr.c);
     
      Locate(15,3,0);
      printf("X,Y   %s","             ");
      Locate(15,3,0);
      printf("X,Y   %d ,%s %d",pt.x,"",pt.y);
      Sleep(20);
  }
//Wend
}
  
Topic archived. No new replies allowed.