Beginner questions: how to use these obscure commands like 'RenderWindow' in C++ - c++

This is kind of a beginner question, so please let me know if this is appropriate for this website and if not, where else I should be asking this.
I've just gotten into the basics of C++ (pretty much what's being taught in this video from FreeCodeCamp: https://www.youtube.com/watch?v=vLnPwxZdW4Y). Obviously, not everything there is to know is discussed in this tutorial and I've been running into a couple of things in other demonstration vids that I don't quite get yet.
For example, this quick demonstration of how Tetris can be coded: https://www.youtube.com/watch?v=zH_omFPqMO4&t=0m25s) you can see him use the command 'RenderWindow', which apparently creates a new window the size of his choice (320*480 pixels in this case). This doesn't seem to be a standard function in C++, so I assume he somehow imported it. How can I do this myself? Does it have to with the file inclusions written at the top of the file (#include <SFML/Graphics.hpp>)? If so, how can I learn more about such files, where can I find them (is it anything like the Python Package Index, or interfaces in Java) and can I create them myself? Any general explanatory words on this?
Thanks in advance.

This doesn't seem to be a standard function in C++
That is correct. There are no functions for graphics nor window handling in C++.
so I assume he somehow imported it. How can I do this myself?
Usually, you would pick a library of your choice (there are many), or do it yourself by using whatever API your operating system provides.
Does it have to with the file inclusions written at the top of the file (#include <SFML/Graphics.hpp>)?
Yes, SFML is one of those libraries.
If so, how can I learn more about such files
You would go to the library's homepage and read the documentation.
where can I find them
Try searching the web for lists of libraries, articles, projects, etc.
is it anything like the Python Package Index
No, there is no standard one for C++. There are several package managers, build systems, etc. Popular libraries are in most of them and support one or more build systems.

Related

Add to openFrameworks project external libraries?

I'm building a cross-platform mobile application and I was suggested to use OF environment and compile my application using Xcode. I'm a Mac user and I started programming few time ago (so I'm really a beginner).
I need some class to get information about position and rotation so I was thinking to have a look at some SDK such as MoSync or CMDeviceMotion in order to understand which one is the most suitable to my purpose.
I also noted here:
https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMDeviceMotion_Class/index.html#//apple_ref/doc/c_ref/CMDeviceMotion
that CMDeviceMotion is written for Obj-C and Swift.
So I have two question:
is it possible add to the main project libraries that are not part of OF?
should I use only C/C++ class?
Thanks.
I'm not sure if stackoverflow is the right place to ask a q like this, since any answer is very much prone to subjectivity.
I don't think there's a lot of valid reasons to even try to connect "MoSync" with OF, since they are both in a way "platforms" for developing apps, supporting different languages (javascript on the first and c++ on the latter). It is possible to mix objective-c (and swift) code with c++, so you can combine CMDeviceMotion with OF.
However to answer your question: It seems that if you want to have device information you don't need to go out of the scope of openFrameworks. Take a look at the "ofxIOSCoreLocation"class of OpenFrameworks/ofxIOS. It provides means for altitude, location, direction and so forth.
It is very possible to cross Objective-C and C++ with what is called Objective-C++ (by standard .mm instead of cpp), in openFrameworks.
Limitations and features: https://en.wikipedia.org/wiki/Objective-C#Objective-C.2B.2B
You can then from the Objective-C++ class (lets say for example ofApp.h), call Objective C delegates and functions directly.
You can not embed swift like this, however you there are some methods of using objective-c middle man class.

Reading DNxHD MXF files using Objective-C and mxflib

I'm trying to read MXF files (from Avid) into an Objective-C project and analyze some frames from video. Preferably getting them into a CGImage or NSImage.
I've been exploring the mxflib, but find myself at a bit of a standstill. I'm used to the mechanics of the standard video methods within Obj-c, but this package is C++ and not exactly something I'm familiar with.
Does anyone have experience working with this library or another similar one? There's not much information available on the subject (at least not that I can understand). And I'm not quite sure where to begin.
Actually, I'd say you're looking at it from a not so good way, as the mxflib is prepared to handle standard MXF files, not really Avid ones.
In short, for this to work, you need to extend the library as per Avid specs (it can be done!) or go with AMT, for which I understand you need to engage Avid to have it.
Finally, I think you're stuck with C++! ;-)

Reading/manipulating images in C++

I am a frustrated newbie of C++ who would like to do the simple task of extracting a pixel matrix from an image file, do some transformation, and then output the modified matrix to an image format of my choosing.
I've given libpng a try and it's API is a mess and hardly readable. Interestingly, some people said it's the best available for C++. I gave my software developer cousin a call and he told me to use OpenGL. So, I did some Googling and I still haven't found a straight answer.
It appears getting a simple "int* readPNG(char* path)" is too much to ask for when the likes of Java, Matlab, and python have these things included in their standard libraries. This is just ridiculous! How do you pros come by and what libraries do you use?
Also a few trivial C++ questions:
- Is there any way to organize classes in a hierarchy like how packages are used in Java? I tried filters in Visual C++ but they don't seem to be the same thing.
- Is there any way to get easily comprehensible stack traces for runtime failures?
Try OpenCV. It is an image processing library with very simple features for editing and saving the images. It will serve your purpose. It also comes with very elegant documentation.
I've found ImageMagick's Magick++ library to be the most useful tool for handling image formatted data programmatically.
C++ has namespaces like Java but they are much more difficult to use and may only make things less readable. As for stack traces, I recommend combing the existing stackoverflow answers for that. In short, it's not simple.
I suggest you improve your Google-fu. There are lots of image processing libraries for C++, including the Boost Generic Image Library, which is as close to standard as you'll get. If you don't have Boost installed and minimal fuss installing libraries, you can always try The CImg Library.
As for your other questions (e.g. stack traces), you'll need to ask separate questions.
I'd suggest Magick++, the C++ API to ImageMagick.
As for packages: you can use namespaces, but that's not nearly comparable to Java's packages (no package-level access etc). They're mostly what they're called: a means to organize names.
Stack traces are not trivial in C++. And there's no platform-independent way of implementing them that I'm aware of.
If you need these features, I just wonder why you don't stick with Java or Python or the likes ? ...
1) Try freeImage - very easy to use and the documentation is readable.
freeimage site
2) for stack traces: which environment are you working with? In Visual Studio there is Stack window (Debug/Windows/Call Stack - Alt 7),
You can also use DebugView and OutputDebugString - not really traces the stack, but can be very usable in debugging. .
I recommend DevIL (formerly known as OpenIL). It has read and write support for 17 formats, and supports many more for just reading.
This is my answer to my very own question here:
Some of the suggested libraries up there have issues with installation with Visual Studio 2010, offer practically no instructions for installation with Visual Studio (i.e. FreeImage), or simply have ridiculously messy API's (i.e. libpng).
If you are new to C/C++, please be careful about what library to choose. Even if there are technical forums roaming with gurus who knows all the answers, you are most likely on your own spending days experimenting and piecing up clues that experienced volunteers could've easily answered in 2 sentences (if they bothered).
Now, what works for me is the OpenCV image library (http://opencv.willowgarage.com/), which is introduced by Mister daerty0153 up there. When you go on the website, don't download the superpack from sourceforge. Instead, read the installation instructions (http://opencv.willowgarage.com/wiki/InstallGuide) and choose what platform you are using.
In my case, I use Visual Studio 2010 as my IDE and so this is the actual subpage that is relevant: http://opencv.willowgarage.com/wiki/VisualC%2B%2B
One problem I encountered is letting VS2010 recognize the .dll files and is not remedied by following those instructions. My solution was to copy all of them to my project folder and that solves all the problem. Some suggested it is a VS 2010 bug.
Hope it helps others suffering from the same situation.

How to populate a Listbox in C++ with all folders in a directory

I would like to know how to list all folder in a directory in a listbox. I am using Visual C++.
C++ is a language that does not specify any standard classes or functions for implementing graphical interfaces. It also doesn't provide a standard way of getting lists of files and directories from the operating system!!! In fact...for a long time there wasn't even a standard for string classes, and every project chose different incompatible strings.
Note: Even though there's now a standard string class, the fragmented legacy continues: Why is there a different string class in every C++ platform out there?
So when you tag something "C++" or use that term, it refers only the language engine itself. As limited as that may sound, one of the great strengths is that this engine is so (relatively) powerful that you don't need to build things in to make them efficient or have a deep coding interface. Users of the language have nearly as much power to create cool language features as if they were able to modify the compiler itself.
It's a steep hill to climb for beginners, though.
All of that means that a question like "How to populate a Listbox in C++ with all folders in a directory?" is very open-ended. It depends on what toolkits you're choosing to use for the GUI, and for talking to the filesystem. Some toolkits are "big" and offer comprehensive classes to cover both areas:
http://doc.qt.nokia.com/latest/qdir.html#navigation-and-directory-operations
http://doc.qt.nokia.com/latest/itemviews-dirview.html
Other libraries are more narrow and provide just one function or another. For instance, "boost" is a set of almost standard libraries that haven't yet made it into the C++ spec. There's a way to enumerate files and directories with C++ using boost::filesystem. It's daunting for beginners, though:
http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/tutorial.html
If you're willing to chain yourself to a particular operating system or implementation--such as make calls to functions only available on Windows, or only on Linux under GTK, or only on MacOS--then you have access to what that platform+toolkit provides. But because C++ is platform-independent, once you cross that line you're no longer programming in "just C++" and your question and tags on StackOverflow need to clarify what choices you've made.
Your other questions on SO are about Visual Studio and VB so I'm assuming you're using Windows.
One related topic you should be aware of are "common dialogs". These are conveniences provided so that everyone doesn't have to write their own "File->Open" logic, or color picker, or search dialog. Microsoft has some of them defined on Windows:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646960(v=VS.85).aspx
So if picking a file, files, directory, or directories is the simple purpose of some code...those save you the trouble. Qt has similar things:
http://doc.qt.nokia.com/stable/qfiledialog.html#details
You can edit your question to add more about your purposes. If you are curious about C++ and just want to dive in and have a well-documented set of functionality that will work on Windows, Mac, or Linux... consider trying Qt Creator:
http://www.qt.io/ide/
Microsoft has really hinged their strategy on .NET and C#, so at least right now you'll stand on firmer ground as a C++ GUI programmer if you go with Qt.
There is an alternative one, free and open-source, called Nana C++ Library(http://stdex.sourceforge.net), a pure C++ GUI library.
There is a tutorial to populate a treebox with folders.
The status of the library is active, and it is updated monthly. This is a new library, it would be a choice for your hobby project.

What Linux Full Text Indexing Tool Has A Good C++ API?

I'm looking to add full text indexing to a Linux desktop application written in C++. I am thinking that the easiest way to do this would be to call an existing library or utility. This article reviews various open source utilities available for the Gnome and KDE desktops; metatracker, recoll and stigi are all written in C++ so they each seem reasonable. But I cannot find any notable documentation on how to use them as libraries or through an API. I could, instead, use something like Clucene or Xapian, which are generic full text indexing libraries. They seem more straightforward but if I used them, I'd have to implement my own indexing daemon, an unappealing prospect.
Also, Xesam seems to be the latest thing, does anyone have any evidence that it works?
So, does anyone have experience using any of the applications or libraries? How did you use it and what documentation was useful?
I used CLucene, which you mentioned (and also Lucene.NET), and found it to be pretty good.
There's also Strigi which AFAIK works with Xesam and is the default used in KDE.
After further looking around, I found and worked with Recol. It believe that it has the best C++ interface to a full text search engine, in this case Xapian.
It is important to realize that clucene and Xapian are both highly complex libraries designed primarily for multi-user server applications. Cutting them down to a level appropriate for a client-system is not easy. If I remember correctly, Strigi has a complex, pure C interface which isn't adapted.
Clucene also doesn't seem to be that actively maintained currently and Xapian seems to be maintained. But the thing is the existence of recol, which allows you to index particular files without the massive, massive setup that raw Xapian or clucene requires - creating your own "stemming" set is not normally desirable, etc.