Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C++ has an equivalent of HTML <canvas></canvas> and JS fillRect?

Tags:

c++

2d

2d-games

Is there a way to draw figures in C++ like you do in HTML combined with JavaScript? By drawing figures I mean the <canvas></canvas> function in HTML and [canvas name].fillRect function.

I'm trying to make a 2D brick breaker in C++

like image 409
Recondito Avatar asked Mar 08 '23 07:03

Recondito


1 Answers

C++ does not have a graphic user interface (GUI) packed in the standard library so you cannot draw using the standard functions.

However GUI toolkits like: Wxwidgets, Tk, Qt and Gtk all support it. In addition most of them support 3d graphics and images as well. In the case of Gtk the GUI can be styled with CSS style-sheets. No JavaScript unfortunately.

You can also use the inbuilt GUI that comes loaded on the operating system you are using. For example under Windows you have the Win32API and under Linux GTK, but note that the Win32API is not cross platform and the default GTK on Linux may not be bleeding edge.

Also you can't use the html or JavaScript syntax in any of these GUI. Canvases would be specifically programmed in C++/C (or the language it is aimed at).

If you want a more html like approach and if your game is going to be Windows only, XAML may also be an option. It is possible to use it with C++.

Also it may be worth noting that Qt is no longer free.

like image 147
Xantium Avatar answered Apr 26 '23 09:04

Xantium