SFML community forums

General => General discussions => Topic started by: MarcuzPwnz on March 07, 2013, 07:48:25 pm

Title: General C++ Question
Post by: MarcuzPwnz on March 07, 2013, 07:48:25 pm
Hey there everyone. :)

Before I came across C++ and SFML I use to program in Java.

As most of you probably know, in Java there's the ability to write graphics on the screen, for example in an applet. And all of this (applets, graphics, even audio) are all bundled with Java and work out of the box without downloading any external libraries.

Which brings me to my question. Why does C++ not include support for graphics, audio etc. right out of the box? Is it something to do with how Java runs using the JVM to provide cross platform applications etc. and C++ does not?
Title: Re: General C++ Question
Post by: zsbzsb on March 07, 2013, 08:00:40 pm
Not sure how to word my answer to this....  :o

C++ is designed as an all around, more generic type language that can run and work on most anything.  From low level to high level stuff. Stuff like graphics/audio can be either high level or low level depending on how you want to approach it. C++ provides ways for you to work with files, but it is up to you how you want to implement it.

I'm sure some of the other guys here can explain it better, but remember C++ comes with a standard template library which leaves everything up to the programmer of how he wants to implement stuff. Java is considered a high level language so it comes with more features in its standard library.
Title: Re: General C++ Question
Post by: FRex on March 07, 2013, 08:33:23 pm
Funny thing is.. hotspot vm is in C++.. ;D
http://www.stroustrup.com/bs_faq.html#gui
Same probably applies to graphics, audio ect.
Title: Re: General C++ Question
Post by: krzat on March 07, 2013, 08:47:08 pm
Java was developed by huge company. They had money to develop huge standard library.

If you want something similiar for C++, try Qt.
Title: Re: General C++ Question
Post by: eXpl0it3r on March 07, 2013, 11:09:13 pm
I think it's also important to understand the abstraction levels that are involved (although I'm not an expert either).

So you got some nice audio card and put it into your PC, but your system doesn't 'just' work and know how to use that piece of hardware, that's where drivers come in, that provide a common interface between hardware and the OS or similar. At this abstraction level it gets interesting for us programmers, because here we can start calling the driver directly or use some OS specific function or a library (e.g. OpenAL) that does the job for us. That's where C or C++ can show off their powers, because it's here were we can kind of directly access the hardware ('s driver).
The challenge for library builders now start here. Now the problem to include such a functionality in the standard of C++ can be probably split in two. On one side there are so many possibilities, so many different needs and so many different ways that it's nearly impossible to provide such a functionality in as standard. On the other hand C++ has always been a language that was a pure language and is hardware independent. This is one of the main reasons C/C++ runs probably on the most platforms. It doesn't require you to have a CPU of type XYZ or an audio card that follows the specification YX32. C++ is just a language with a standard runtime library for some basic features and at the bottom it's just a specification through a standard. If you'd now go and provide interfaces for specific hardware related stuff, you would not only start limiting the language to a certain platform type, but you'd also break the generality C++ is and has been representing.
So you can basically run C++ on any device for which exists a compiler.

With Java you go one abstraction level higher. The problem with C++ layer is, that every platform is different and thus we need a compiler for every platform. Java's approach is to have an environment that is always (about) the same and thus you can easily go and 'define' that this self-built environment should have an audio interface and then you'll be able to directly integrate it into the language, since you can always assume that there will some sort of audio interface. This 'environment' is then called a VM (Virtual Machine), since you basically abstract a 'standard' PC within your own machine.
So you can basically run Java on any device that provides a Java VM.

Here's a (bad & incomplete) ASCII drawing of the different abstraction levels:
  Hardware
     |
   Driver
     |
    'OS'
     |
 Libraries <- Compiler <- C/C++
     |
    VM     <- JIT <- Java

I hope that gave a bit more insight on the workings of a PC. ;)