Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: General C++ Question  (Read 2531 times)

0 Members and 1 Guest are viewing this topic.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
General C++ Question
« 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?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: General C++ Question
« Reply #1 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: General C++ Question
« Reply #2 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.
Back to C++ gamedev with SFML in May 2023

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: General C++ Question
« Reply #3 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.
SFML.Utils - useful extensions for SFML.Net

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: General C++ Question
« Reply #4 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything