about use of graphics(GUI) - c++

i know this is not a disscusion forum,but i am going to ask a question,whose appropriate answer was not given to me by anyone,
I am new to programming & learning C++,NOW,when i am doing well with it,& was curious to learn graphics in C++,i came to hear that the graphical programming in C++,is difficult,& is not used commonly,as there are many other languages which can do all this much more easily as compared to C++.
now my questions are:
the bold sentence is valid upto which extent
is it a good thing to start learning any other language to handle the graphics for me

Graphics with C++, if you mean Graphical User Interface and Desktop programs, is really easy if you use, for example, Qt. Yes, C++ GUI isn't pleasant if you're not using any library and are using only the OS API (or a really old library such as MFC), but why would you do that?
I must admit though that the WYSIWYG editor integrated in Visual Studio for C# is a bit more intuitive than that of Qt Creator for C++. But that's a matter of habit and taste, I think. Writing desktop applications with Qt is piece of cake!
If by graphics you mean game dev with real 3D graphics, then I'm afraid it's not trivial in any language. You should probably have to learn OpenGL or Direct3D (OpenGL has C API, Direct X has C++ API)

It's probably true that GUI programming in C++ is more difficult than in some other languages, unless you're an expert in C++ and dislike those other languages.
If you did want to do relatively common GUI things in C++, you might consider using the Qt library, which is mature and at least somewhat cross-platform (your apps will probably seem a bit ugly on Windows or Mac, but maybe not too bad).
As for other languages to learn, you should ask about that on programmers.stackexchange.com .

As long as most (PC and console) games are written in C++ I would not dare to say
the graphical programming in C++,is difficult,& is not used commonly
Hard, yes, common? YES!
Other languages might make programming graphics easier but for sheer speed C++ is still a very valid option.
anti flame disclaimer: I know there are many languages/APIs that are quite capable of handling graphics.

Related

C++ Analogue for WPF

So I've fooled around with WPF a bit recently, and I must say that I really like the idea. I love the framework as a whole, from the GUI to the plumbing.
However, as much as I love managed land, I love my native code just as much. So I'm wondering what sort of libraries exists for C++ which capture the essence of various parts of WPF. I'm not looking for interop solution, nor do I want Managed C++ or C++/CLI solutions, but pure C++ solutions.
Now, I'm not expecting to find a "copy" of WPF for C++ - I wouldn't expect that to exist, nor would I need it to. Instead, I would expect that different libraries might capture a subset of the desired concepts. My particular interests are
Hardware accelerated graphics for widget based GUI's (via DirectX or OpenGL, preferably the latter)
Declarative language for GUI design (preferably an XML dialect)
Data binding
Resolution independence (less important)
To say a little about my reasoning, I would like to implement such a library myself, which captures a specific model that I have begun working out. I am in the process of finding some more inspiration and helpful resources before locking down my design. The library is intended to be cross-platform, so references to cross-platform ideas would be great, but not strictly necessary as I am usually capable of translating things into cross-platform solutions.
Lastly, although I am writing a C++ library, and C++ ideas would be great, I am open to ideas from any native language.
Thanks in advance for any help.
There isn't really anything like this. Not cross-platform at any rate. Direct2D works reasonably well, but is obviously Windows-only. And NVIDIA recently dropped this "path" extension of OpenGL that is similar in basic functionality, but it is NVIDIA-only (and not available on Mac OSX). Cairo has an OpenGL backend, but I have no idea how good it is. It can't be that good if Mozilla dumped Cairo in favor of D2D on Windows.
Many GUI toolkits have some form of language for making a GUI. Qt has one that is pre-compiled into C++.
Not that I know of. Data binding requires some form of reflection (WPF-style data binding does), and C++ has no native support for reflection. So you would need to implement reflection of some sort before you can even begin to make WPF-style data binding work.
That comes with #1. More or less, as any GPU-based renderer will be able to operate at arbitrary resolutions.
I love C++, but honestly, this sort of thing is best implemented for a higher level language. The lack of language-based reflection support will make implementing data binding a huge pain. Whereas, you could just implement the low-level "render stuff to area" and basic window/event management in C++, then expose it to a scripting language where data binding and such work. That way, you have native code speed where you need it, but the versatility and reflection of a scripting language for dealing with the GUI and its associated data.
I'm several years late, but for the benefit of anybody else reading this question: you're looking for Qt Quick / QML:
http://qt-project.org/doc/qt-4.8/qml-intro.html
http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

What is the best way to get started in GUI C++ programming?

So, I learned C++ (fundamentals) and I want to write software, however I have stumbled upon a problem where I don't know where to get started. It seems like learning C++ was the easiest part by far when it comes to understanding the libraries for the GUI construction the concept I yet don't fully comprehend. I searched a lot and couldn't even decide been a new guy on MFC, Win32 or Qt.
Qt C++ GUI seems like a fun and easy to use software with the definitions of classes available right there quickly.
With Visual's MFC I am seeing a lot of code upfront on the pre made project file and a lot of description of classes, however getting definitions is a bit slower as I have to go to the internet.
Win32 is apparently written in C and is not updated much?
A lot of people recommend Java and C# as well, but I am not interested in learning a new language when I don't have C++ set in stone and practiced with enough yet.
Not sure how to go about this.
Go with Qt if you envision porting your program to platforms other than Windows and/or your actual UI needs are relatively straightforward. But Qt, being "fun," abstracts you away from the Windows API, so if you find yourself needing to access features of that API not offered by Qt, then you'll be up the creek. So go with MFC if you're staying on Windows and you're building an application whose complexity or Windows-specific features may require more direct access to the Windows API. MFC provides a thin abstraction layer over that API; its concepts map more or less one-to-one with the API's concepts.
What kind of GUI do you want? Any framework should be able to do any kind of GUI, but some are optimized for certain work:
MFC is optimized for making applications that edit documents, like MS Office programs Word, Excel, Powerpoint.
wxWidgets and Qt (and .NET WinForms and WPF) are optimized for any sort of app that primarily uses widgets (textboxes, buttons, menus).
SDL is optimized if you want to draw stuff, like graphs or vector artwork.
I wouldn't recommend that you use MFC since it isn't a good fit for most applications, and also doesn't use modern C++ design, it's loaded with workarounds needed for stuff that was broken in early versions of Visual C++ and now can't shake those workarounds because of backward compatibility.
The Win32 API is actually really useful to know regardless of what kind of application you want to make, because it defines the rules for how the UI interfaces to the rest of the system. Yes, it's written in C, but this is to make it usable from any programming language, not because it's an obsolete design. Win32 API is highly object-oriented and uses polymorphism extensively.
Few things you need to be aware of:
If one day you want to sell a program written using Qt you might need to purchase a license.
If you feel like GUI applications/ GUI programming is what you want to do in general, for windows platform you better learn WinForms or even better WPF (with C# of course).
If you just want to quickly put up simple GUIs for your C++ programs for learning purposes, and you don't care much about learning the frameworks and licensing issues, just go with Qt or wxWidgets.
MFC is outdated. If sticking with C++ on Windows, I recommend you to lean C++ CLI.
However I suggest you to learn c# directly since c# is the mainstream language in .Net world.
For GUI, the windows world is now dominated by WPF.

C++ for small, individual projects (i.e. hobby programming)

I recently started C++. I am using PHP right now and decided to take a look at C++. Web programming had me working with a couple of languages, with a couple of people. I wanted to do programming where I only had to bother with one language and create small utility apps (mostly not web-based). I wanted a compiled, strongly-type language without memorizing a tome of classes. Basically I wanted to learn C++ for the following:
mobile programming (I don't ever want to go touching Java, and I don't have a Mac for Objective C or IPhone SDK)
small desktop apps like DTRs, POSs
creating small desktop-based games
creating small Air-like applications that can access the web for additional content
I heard that C++ is not beginner-friendly and is mostly used for huge projects with lots of calculations and fine details (like 3D games). Is it practical or even possible for me to use C++ for the above cases? (Sorry, I haven't delved on C++ that much yet, so aside from "huge, monolithic project", I don't know any other uses for it)
You can certainly use C++ in all the areas you mention, though whether it is best of breed for any of them is open to debate. C++ is very large and complex language, and requires a fair bit of effort to get up to speed on. If I were you, I would pick one of the areas you mention that you are most interested in, and then find out which language(s) are best suited for that area and learn that.
If you are set on learning C++ you will need to read at least one book on it - you cannot learn it from internet resources alone. See this question The Definitive C++ Book Guide and List for a book list.
On the droid you can use other languages aside from Java - check out their ASE (Active Scripting Environment). C++ / C should really only be used when you have no other choice - i.e. speed critical code, operating systems etc. It's very easy to make a mistake that's difficult to diagnose and there are lots of task where it'll take way longer than it should to write and odds are others have already done so and done it way better - reinventing the wheel is bad. If it interests you though by all means learn and eventually you may master it. It's an excellent skill to have.
It's also not a completely object oriented language however, it's a hybrid one that supports most object oriented features, but some such as inheritance and polymorphism are a bit awkward to deal with in C++ - for example you have to define methods as virtual in base classes in order to be allowed to redefine them in subclasses - sort of like predicting the future - will this method every be desired to be redefined by an inheritor? Really what happens in that case is you make the base class method virtual later on to enable it to be redefinable - that is if you happen to have access to the source code to do just that - if not then oh well. For an example of this confusing stuff in C++ and other gotchas: Pitfalls
Look at other languages such as Ruby or Python - in particular Stackless Python where a combination of it and C++ (used where necessary) was used to create EVE Online as well as the functional languages such Erlang and Haskell.
For 2, 3 and 4, I recommend C# over C++, for the reasons I wrote here.
About 1, you can do iPhone development with .NET but I've never tried it and I don't know how viable it is.
Edit
To answer your actual question: yes, it's totally practical to write small and large desktop apps in C++. Especially if you use quality tools like Visual Studio and Qt. It's just that I think it'd waste a lot of your time for no reason, unless you intend to go into professional game development eventually.
I went to C++ from PHP like you, but I was more interested in 3D games and such. Now I have moved on to C# and find it much more enjoyable than C++.
As for your specific areas of interest however, C++ is certainly an option but C# may be better.
Mobile programming with C++ is probably not a good idea. I know it's possible with NDKs and such but for a beginner it's probably not so good. For iPhone development, other than the official SDK, the next best option is the (commercial) MonoTouch framework from Novell. However, you may still need a mac to deploy (I don't know). In terms of Android, if you don't want to touch Java (don't blame you) I believe a C# framework (similar to MonoTouch) is in development and other languages may be available. Other platforms? No idea.
Small desktop apps is also very possible with C++. Assuming you're running Windows, you can use the Win32 API (pain) or the C++/CLI API (better). You could also use a different GUI framework like Qt, wxWidgets or GTK+ which are all also supported on other platforms. Again coming back to C#, GUI development using GTK# in MonoDevelop is so much fun. Having used WinForms in Visual C# Express back in my Windows days, I can say that I now enjoy the process whereas I didn't before.
Games are my main area of interest and the reason I originally picked up C++. Seeing as you've said small and desktop-based, using C++ for performance reasons is way overkill IMO. You could make a decent, fun, playable game in Python using pygame without the pain of using a language like C++. In C# (yes, I'm trying to sell it to you) you could create awesome games using the XNA framework from Microsoft or other frameworks like (my personal favorite) OpenTK.
Rich internet applications. C++ is probably not the right tool to use here. It's certainly possible but seeing as C++ has no standard networking library, you would have to figure some of this stuff out yourself. C# may not be the right tool either but it makes it a little easier. There are other options as well (like Python) but it's not something I know much about.
Despite what I've said about it, I still think C++ is a good language to learn. It teaches you about lower-level things you never think about in PHP land. If you want to learn it, the book that really helped me was "C++: A beginners guide" by Herbert Schildt and also "Programming" by Bjarne Stroustrup.
Yes, your use cases can all be done with C++, more or less (YMMV on mobile devices).
To some degree or another, a language like C# will be more rapid to develop in, however.
In my opinion, once you get away from the straight-up form design features and hack for a while in a language & application, language feature comparisons begin to diminish in meaningfulness.
I recommend C++ as a first "heavyweight" language; see here for my most recent discussion on it.

Tired of building web applications? Trying maybe C++?

I'm getting a little tired of building web applications. Feels like same thing over and over again. Are there any other cool things you can do. I'm maybe getting to start coding in C++.
Any suggestions for tips in that area? Should I delve into Qt or MFC? Any suggestions?
My latest interest is in Robotics. You can get a microcontroller for about $30 (arduino.cc) - and miscellaneous motors off of E-bay. I also have some cheap rangefinders and a GPS receiver - each of them under $30...
I build web apps as well. I'm not really tired of it, but I spend all my spare time programming in C.
If you're just starting out in C++, I recommend starting with some simple console-based applications first. Get used to the syntax and some fundamentals like strong typing, pointers, and understanding the difference between pointers and references. (Depending on your experience as a developer, you may already know all or most of the theory behind these concepts.)
If you're comfortable with these things, building GUI applications is easier (although still far from trivial.) I'd recommend going with a toolkit like Qt rather than MFC, which is largely deprecated in favor of dot NET, if I'm not mistaken.
Edit: also, consider trying out a language like C# instead. C# is newer, a little more cohesive, and lets you use dot NET for building Windows GUI applications.
Write a game. An action game. Like, a shoot-them up for example.
You'll discover the other face of programming. Use whatever you want to make it. C++ is a good choice, but any language will be good. C++ will be harder to "master" than other languages but learning it will make you understand a lot about other languages. But that's your choice : the project domain is more important than the language (that is just the tool).
Just try to make a game, I think it will really be different and you'll discover a lot of interesting things. I recommand a shoot them up because it's visual, make you learn basic graphic rendering, basic collision management and is a good base for a potentially interesting game (if you add a feature that makes it stand appart) that will keep your motivations for learning.
Look into mobile application development like on Android or iphone. C/C++ will come in handy.
C++ is great and all, but writing GUIs in MFC is just stupidly painfully compared to any other reasonable framework out there, like .NET (VB, C#, C++/CLI, pick your language) or Cocoa/Obj-C on the Mac OS X / iPhone OS. Qt is probably better than MFC.
Buy "The C Programming Language" by Kernighan and Ritchie and work through it.
Ideally, you also have access to an OSX/Linux system and can work on that. (C and Unix go hand in hand).
If you're used to working in relatively high-level languages such as C# or PHP, going back to something like C++ where you need to do your own memory allocation and other low-level stuff will probably seem cumbersome. Personally, I was happier making the switch in the other direction, and having much more done for me.
But if you do want a challenge, C++ could be a good option. Or, go straight to embedded. Robotics is a very fun topic, try to fit interesting things (that really move!) inside the 2-KB RAM environment of a PIC microcontroller :-)
I would recommend trying to implement something useful in C/C++. Is these a utility in your operating system you don't like? That you think you could improve? Have you always wanted to do X easily and have a good idea? No matter how big it might seem, research it. Learning an OSes API will teach you a lot about C/C++. Add a user interface in the library of your choice to learn even more. Basically, push the envelope a bit - building a calculator is great or a little console app for learning a few things, but building a fully fledged app with a purpose will really teach you things.
Add intelligence to a simple game using a neural network. I've always wanted to add a neural net to Oware to see if it improves its wins.
If your into pain, you could correct flaws on Windows Vista and 7. :-(
I'd recommend moving to Python rather than C++ if you're coming from a web design background. Get good at object-oriented programming, encapsulation, and related things before you go to C++ and have to deal with pointers and cleaning up after yourself.

Learning C++ right?

Since I have been mostly using script languages in the past time but now want to go to the "high-performance" level I decided to learn C++ some time ago.
I looked at some "beginner" tutorials and bought an O'reilly C++ pocket reference book (it's really helpful). My problem is that I now know all the basics but I'm not good enought to program a more complicated game, for example, yet.
Do I have to get one of those thick C++ books for further learning?
I'm going to use C++ on Windows mainly. What APIs beside Win32 are important for me?
My goal would be to write a small interpreter for a programming language I've though of - I managed that in several scripting languages already, what API/Library knowledge do I need in C++ to write one?
You don't need a thick book - you need a good one. Get Accelerated C++, written by Koenig & Moo, two of the original C++ development team.
Depends what you want to do.
You don't need anything - you can write a perfectly good interpreter or compiler using just the C++ Standard library. See this SO question for lots of info in this area.
Learn with books. C++ is a complex language. My suggestion is to first go with a rather quick introduction and general overview of the major programming paradigms that C++ supports: OOP and generic programming: Accelerated C++.
When you finish this book, you can go with the two volumes of Bruce Eckel's Thinking in C++ which are very detailed.
For UI programming, the best C++ toolkit is Qt, and it is multiplaform-ready. You can read "C++ GUI Programming With Qt4" (the first edition is free to download, just google it). If you want to stick with C++/Windows API, learn the Windows Template Library, altough it may be a bit hard due to lack of official documentation (altough there are good tutorials on the net). WTL is the way to go to create very small, lightweight applications (Qt DLLs on the other side, need a few MBs each).
I have always found that learning a language from a book is pretty difficult and that after you know the basics you should begin to program. So instead of picking up a thick manual I would check out something like http://www.cprogramming.com/tutorial.html#advanced or just google for c++ tutorial and something that you would like to try to make.
A good (and) thin book to get started in C++ is Accelerated C++ by Koenig and Moo.
I mainly do programming under Linux, but I hear a lot of bad things about MFC, so I'd try to find a different GUI library.
Once you get up to speed with some of the more complicated parts of C++ syntax, have a look at the Boost.Spirit libraries for parser generation. The various Boost libraries provide some very useful extensions to the Standard Library.
Honestly, In learning C++ i never picked up a book (no flaming please). The best advice i can give is to go to this page and go through the tutorial. It covers the majority of the C++ language (read: most commonly used features) and keeps it as simple as possible. As far as APIs that are important... well that is a matter of preference. No one toolkit/api has really "won", but Qt, GTK-- (gtkmm), and wxWidgets are all big players. And besides GUIs, you'll probably want to learn either the raw winsock2 and threading APIs OR the boost library's threading and network interfaces. I do agree that MFC is dying, and for windows-only development C# is taking an increasingly large role (even on linux/mono C# is starting to catch on... slowly).
Also, the best way to learn a language is to code. So don't just read a whole ton- without practical experience you're never going to learn the language. Ask questions, answer those you can, and write tutorials- for yourself if nobody else. Writing down what you've learned is a great reference, and the process of straightening everything out in your head to write it down in a fashion that another person can understand it alone is a great way to reinforce concepts. In a strange, but seemingly backwards, way I found the best way I learn programming is by helping other people with their questions.
#Neil- i disagree that online tutorials are "flat out wrong". If anything, the style they teach you might be geared towards readability rather than optimization- which in-my-not-so-humble-opinion is an advantage. In my limited experience I've found cplusplus.com a go-to reference for pretty much everything.
Specifically, to answer your questions:
1. No thick book needed. I've heard that the thinner ones can be useful as a quick reference, though.
It's completely subjective and depends on your goal. Boost's network and multithreading libraries are probably a good start.
between std::string, std::stringstream, and getline(std::istream&, std::string&) you should be pretty good. C++ comes with a whole ton of built-in functionality yet isn't too bloated/huge/impossible to learn. Take advantage of it. All of the parsing is built in already.
Please, for Pete's sake, don't use directly use the Win32 API. You'll be painting yourself in the Microsoft corner. There are plenty of cross-platform libraries out there you can use instead:
Standard C++ library: strings, file i/o, containers, algorithms
Boost for the everyday stuff they left out of the standard library: parsing, networking, threading, smart pointers, memory pools, date/time, matrices, etc... Boost libraries are peer-reviewed before being accepted and are high-quality. Boost is the breeding ground for libraries that eventually become part of the next C++ standard.
GUI Toolkits: Qt and wxWidgets are very mature and widely used. There are many more.
For C++ on windows, definitely learn Microsoft Foundation Classes (MFC). Without MFC, you have to implmenet all of the windows API stuff yourself, which is more C than C++ and can be quite a pain.
You also may want to get, learn, and use the boost C++ libraries. They aren't windows specific, but they are a great resource for anyone.
I highly recommend Stroustrup's Intro C++ book. It covers C++ and STL in a very approachable way.
After that you might consider looking into books on Qt, a multi-platform GUI toolkit, or WTL or MFC for Windows. You could do .NET + C++, but that would be a lot to learn. In my experience with Qt and MFC, books have not helped much. Tampering with sample apps, building small apps just to test out one kind of feature, and poking around the docs was the only way I could get my head around either library. The books I had tended to simply gloss over too much--they were not worth the money.