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

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++

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.

Concisely, win32. It's hard to learn, but it comes with any version (AFAIK, at least 2107 community edition) of Microsoft Visual Studio.

Related

GUI developement using Python and tkinter vs Qt and C++

I am trying to make a decision for what to use to continue developing my application.
I have some experience with C++ in the MFC Document/View architecture and have found it very frustrating. I felt I was always fighting the framework and also felt that my application didn't fit the doc/view architecture. (I now know that it probably would have fit, if I had known how to structure it that way.)
So I decided to try Python and ended up using tkinter. That was easier to learn and didn't have as many frustrations. (Though it had a few different new ones.) I think I learned a bit more about object orientation and setting up classes along the way. But am now concerned about the fact that it is an interpreted language and much slower than C++ for my purpose.
So I have been wanting to go back to C++ but not MFC. I have read a little about wxWidgets and Qt.
So here are the things I want to know:
For wxWidgets and Qt, do they use a resource editor for setting up the layout of a GUI or directly expose the code the way Python and tkinter do.
Do either wxWidgets or Qt produce any interpreted code or is everything ultimately compiled into native machine code?
Thanks
1. Both
Qt and wxWidgets have GUI builders available. In the case of Qt, an XML file is produced that is parsed by the uic to produce C++ code. wxWidgets has several designers available, they will differ between them, but I'll be surprised if they don't all follow the same pattern.
However many people, myself included, choose to hand code - there is no requirement to use the UI designers. Be careful using the term 'resource editor', as Qt has a Resource Editor and it is not used for designing GUIs.
2. Both
Qt and wxWidgets are not just GUI frameworks - they're cross-platform toolkits. In view of this, Qt is pushing for a clear separation between GUI and backend by using QtQuick and the QML language for GUI development. Qt5 still has full support for C++ widget-based development of course. wxWidgets has no equivalent that I'm aware of.
Also, if you liked Python but not tkinter, both Qt and wxWidgets have Python bindings.

Searching for framework for my application

I am searching for a framework(preferably c++, but i can learn other languages too) for my application. I will write what i need:
Borderless window(no buttons,frames etc.)
Real time 3d model rendering(or at least easy way to show 2d animation made from 3d model)
Cross-platform support(not mandatory)
If there is any other details you need to know, please tell me.
Thanks in advance.
Xojo will also do what you want. It creates Windows, OS X and Linux desktop apps and has built-in support for OpenGL.
http://www.xojo.com
One of the best cross-platform Gui-Frameworks for C++ is Qt. It can do 3d-stuff using OpenGL too. However, if you only need a plain window without any controls you may want to look into the next OpenGL tutorial for some infos.
I recommend Unity.
It works in Windows, Mac, Linux, iOS, and Android. (Furthermore in some game consoles.)
Its support languages are C#, boo and js.
C# is like C++ and easy to learn.

Popup Text Input Box in C++ with OpenGL

I am trying to create a simple popup box that appears when my C++ program starts that will allow the user to enter the width, height, and length of a cube that will then be displayed in a separate window. I have been searching for a very long time, and I have yet to find a solution that will allow me to do this. Can this be done using C++, OpenGL, and GLUT? Or do I need another library to allow me to do this.
Thank you.
Jordan
Edit: I am programming a cross-platform program and cannot use Win32 to accomplish this, nor any other Window-specific function.
What are you are looking for is a graphical user interface.
There are many libraries available that interface with various input methods (for keyboard and mouse) and provide graphical output. Each one has it's own model.
There are various models, but the most common one is hierarchical.
If you are looking for a learning experience, I suggest you do some Googling on how to make your own GUI.
If you are simply looking for a convenient library that does the hard-yards for you, I strongly recommended AntTweakBar:
AntTweakBar is a small and easy-to-use C/C++ library that allows programmers to quickly add a light and intuitive graphical user interface into graphic applications based on OpenGL, DirectX 9, DirectX 10 or DirectX 11 to interactively tweak parameters on-screen....AntTweakBar works with GNU/Linux, Windows and OSX
It was designed not as a monolithic batteries-included do-all library (such as Qt, another alternative), but as a simple and lightweight tweaking interface (hence the name).
There are several examples available and it's API is quite simple, so it should be reasonably easy to pick up.
There's also GWEN. It is not a well known library, but I find it extremely versatile and easy to use.
Facts- Coded in C++- Fully Namespaced- All standard window controls- Behaves like you'd expect- Lightweight (No XML readers, no font loaders/renderers, no texture loaders - your engine should be doing all this stuff!)- Easy to integrate (comes with renderers for Windows GDI, Allegro, OpenGL, DirectX and SFML)- Totally portable & cross platform- Doesn't need RTTI- Released under a "do whatever you want" MIT license.
Opinionated note: I prefer GLFW over GLUT. It provides a nicer model, and is still in active development (unlike GLUT which has not been updated in a significantly long time). At least use freeGLUT
You need to use another external gui library to do it. If you're doing it for windows, MFC is a good option. Or check library OpenGL User Interface Library.It's cross platform.
Here some libraries
Maybe this link helps you
Your statement saying that you wish to have a popup box implies your wish to use the underlying windowing system, regardless of the OS.
If you want to be cross-platform, there are quite a few libraries you can use that either emulate or actually use the underlying windowing system, such as wxWidgets.
If using such a library is not an option, you can always use the OpenGL window to draw text and emulate your popup yourself, but that's a bit more work, imo.

Which C++ cross platform GUI framework has good skinning ability?

What is a cross-platform C++ GUI framework that has good skinning ability?
So I could (and give the users) the ability to customise the GUI.
The Qt framework allows for changing the appearance of widgets using style sheets (using css). See: http://qt-project.org/doc/qt-5.0/qtwidgets/stylesheet.html.
EDIT: As you're looking for something like wxSkin, first why not use it in the first place?
Then, if you don't want to use wxSkin, have a look at Juce. Qt's goal is definitely not themeable GUIs although windows masks and stylesheets are a way to implement them. There is the QSkingObject project on Qt-Apps.org but last time I checked it I found that the quality of the code was poor (of course this is subjective and argumentative).
You can have a look at Juce which has a dual license: GPL and commercial.
Qt (LGPL) has stylesheets to style the widgets, but it still let the operating system draw the windows decorations unless you instruct it to draw frameless windows and draw the decorations by yourself.
However, think twice before going the skinned application route. A typical example is Songbird (written in XUL) which used frameless windows and painted its own titlebar and windows buttons. Then they back-pedaled and switch back to system windows decorations after many users complained.
Qt has convenient support for that with Qt style sheets et al. The Qt labs blog had an example post that might give you an idea.
As other say, Qt's stylesheets work well.
You also have the option to customize the drawing in Qt by overriding QStyle. You could allow users to use plugins (exporting a QStyle implementation) to make it super-customizable.
(Then, I don't know if your users are C++ coders or not...)
I've used Juce (compatible with Windows, Linux and Mac OS X) in the past and it has a LookAndFeel class (gotta love the name) that allows you to do that.
I'd have to vote for XULRunner because it's extremely skinnable. However, it's not pure C++: application code is written in JavaScript while extensions can be implemented as C++ XPCOM components.

C++ UI resources

Now that I know C++ I want to get into desktop application that have a UI instead of Command Prompt stuff, where should I start?, and what are some good online resources?
wxWidgets is a cross platform GUI library for C++ (and other languages). The main site should have enough pointers to resources to get going.
You might also want to check out this question/answer here on stack overflow if you are specifically thinking of Windows
If cross platform support is important then I would second the suggestion to look at Qt. It supports Windows, Linux and the Mac. For free software it is free (there is a GPL version on Unix but not for Windows) but for comercial software it is not particulary cheap. There are now several books on Programming with Qt.
It does come with a large number of extra libraries for networking, parsing XML etc. It also has integration with Visual Studio on Windows.
One downside with Qt is that there are not as many add on libraries as with some other GUI frameworks. Ot will depend on the type of applications that you wish to write whether this is important to you or not.
I use Codegear's C++ Builder. It's C++ language support is not 100% but it more than makes up for it by having a great two-way RAD IDE and the ability to use a huge library of existing Delphi components.
How about QT? Its cross-platform and its is used in a lot of commercial softwares.
On Linux and maybe Windows, you can use Gtk+ with Glade. Gtk+ is the GUI toolkit. Glade is a GUI drag and drop GUI editor. If you came from Windows or Java and thought GUI programming is hard, this stuff is easy.
If marketability is a concern, then C++/CLI with WinForms and WPF which really translates to "just learn WinForms and WPF, regardless of what specific language you use".
CodeProject has a ton of WinForms/WPF samples/tutorials to get you started.
The Fox GUI Toolkit
Really decent tried-and-true toolkit with a very nice event system. I've used the Ruby port, and my Windows apps had a very native look and feel.
It might lack some features, but FLTK is an incredibly simple cross-platform GUI library.
If you are using Windows the traditional place to start is Petzold
There is a nice simple framework here which will help you on the way without abstracting too much away.
Get Visual Studio Express, and start with a MFC "Dialog Based" application. All the window toolkits mentioned are good, but MFC will look the best on a resume!