Jump to content
  • Advertisement
Sign in to follow this  
Flashthinker

I need some things cleared up...

This topic is 4087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm pretty new to C++ and I'm having trouble understanding exactly how it works... I know quite a few programming languages; Java, C#, VB and a bunch of web scripting languages and server-sides. Now I'm finding the concept of using external APIs confusing somehow... Can someone please answer the following questions: - What languages are APIs like the Windows API programmed in? Or is it just direct machine code... If the APIs are just machine-code, then how is it that we can access them in C++ using a C-like interface? Are APIs like Windows or OpenGL totally separate from C++? Am I totally off track? Please clear up whatever you can regarding external APIs. - Now, Seeing as I know C#, I noticed that it's a lot like Java and unlike C++... Is it because C# has an interface for popular APIs and is that the big difference between it and C++? - When making a game in C++ and OpenGL, how to you create the 3D models? Which programs do you use? Also, relating back to question one, I heard that Open-GL was procedural in nature... Wouldn't that mean that it's impossible to make a C++ OpenGL applications... Because it would pretty much be just C if it's procedural. Is there any other question which I have not asked which you think I might need answers to in the future? Please explain. Thanks a bunch!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Flashthinker
I'm pretty new to C++ and I'm having trouble understanding exactly how it works... I know quite a few programming languages; Java, C#, VB and a bunch of web scripting languages and server-sides. Now I'm finding the concept of using external APIs confusing somehow...


The first and most important thing you need to learn is that you don't know as much as you think you know. For example, the fact that you don't seem to think Java/C#/VB/etc involve using external APIs tells me quite a lot about your level of experience with those technologies.

Quote:

- What languages are APIs like the Windows API programmed in?
The bulk of the API is written in C, and can be consumed by C and C++ code (as it happens the API is valid C++ even though it wasn't originally written as such). There are ways of working with it from other languages, though; plus, some parts of the API are exposed via COM, which can be consumed by a large number of languages.

Quote:
Are APIs like Windows or OpenGL totally separate from C++?
Yes.

Quote:
- Now, Seeing as I know C#, I noticed that it's a lot like Java and unlike C++... Is it because C# has an interface for popular APIs and is that the big difference between it and C++?
My guess is that by "interface for popular APIs" you're talking about the .NET Framework, yes? The .NET framework is not 'part' of the C# language, the two just come packaged together. You can write C# code that doesn't make use of it.

Quote:
- When making a game in C++ and OpenGL, how to you create the 3D models? Which programs do you use?
Personally, I use Wings3D and Blender; others use things like 3D Studio Max, Maya, or SoftImage XSI.

Quote:
Also, relating back to question one, I heard that Open-GL was procedural in nature... Wouldn't that mean that it's impossible to make a C++ OpenGL applications... Because it would pretty much be just C if it's procedural.
The OpenGL API on Win32 is written in C, but can be consumed by both C and C++ applications just like the rest of the Win32 API.

And if you think that the API being procedural means you can't use it in C++, then you need to revise your definitions. Specifically, you need to consider that C++ is not an object-oriented language; it's a hybrid language that allows a number of paradigms, including both object-oriented programming and procedural programming.

Share this post


Link to post
Share on other sites
API - Application Programming Interface

It's an abstract term, and as such isn't defined by code. It is a contract between user and some logic. API provides definition of one system interacting with other.

Historically, many APIs are language and platform dependant. Reason for this is that they provide simplest and least-overhead method for connecting various separate systems. Alternative would obviously be some external communication method, such as sockets or pipes.

API can be defined regardless of language ( CORBA IDLs ).

Java, C++, C# and VB are languages. Each provides a set of language libraries, which are generally considered to be part of language. While Standard C++ library has an API, it's considered part of language.

Majority of languages provide ability to create self-sufficient libraries or modules with certain functionality. In order for others to use them, they provide a language-specific or platform neutral API (if accessed remotely).

Windows provides a huge set of interfaces that allow a large number of applications to interact with various parts of operating system at different levels. These go from lowest level kernel access to highest level abstractions such as ActiveX, or even higher, like VB for Applications.

API in this case serves as boundary between user and implementation (which is proprietary and not accessible to user).

OpenGL, for example, is an API. It defines a contract of how to render graphics (among other things). This API is provided for various platforms and various languages. In addition, various chipset developers provide their own implementations. But the user only knows about API, regardless of language or platform.

Windows API isn't programmed in anything. Windows API defines how Windows OS can be accessed from most MS supported languages (VB, C#, C++).

What the Windows OS itself is written in is mostly irrelevant. Probably C and C++.

This is the key advantage of providing an API for a piece of software. Users can develop their own software without knowing anything about your implementation or even the language used. They are given an interface which defines how to do it.

Whether something is procedural, OO, functional, ... is completely irrelevant here.

Share this post


Link to post
Share on other sites
Quote:

The first and most important thing you need to learn is that you don't know as much as you think you know. For example, the fact that you don't seem to think Java/C#/VB/etc involve using external APIs tells me quite a lot about your level of experience with those technologies.


Really? How would I go about invoking a native system API in Java? I knew that you can use external APIs as in not-built-in system APIs, or maybe I didn't word my question properly, what I meant by *external* APIs was "Native APIs" like those C++ invokes; Win32 and OpenGL, I noticed that in Java, I can only use Java-specific APIs like Java3D and JOGL, can I use true OpenGL though?

About your attack on my over-confidence, I never said that I was a "PRO" I just said that I "know" them as in; I am quite familiar with their structure and API. I do not know many advanced features. I only know what I need to know at this stage. I will look into what you mentioned though (about external APIs, not about my level of confidence :p)
I didn't mean to boast btw, I just thought it might give people common grounds on which to base their answers.

Quote:

My guess is that by "interface for popular APIs" you're talking about the .NET Framework, yes? The .NET framework is not 'part' of the C# language, the two just come packaged together. You can write C# code that doesn't make use of it.


No, I was talking about the functions of APIs like the Windows API (Win32 is it?), I'm under the impression that the .NET framework is just a "reformating" layer that groups calls to popular system APIs in a more OOP manner.
Also, I have to admit, I don't fully understand how the .NET framework works, I'm going to do some research, but if you'd like to share your thoughts, I'd appreciate it.

Quote:

And if you think that the API being procedural means you can't use it in C++, then you need to revise your definitions. Specifically, you need to consider that C++ is not an object-oriented language; it's a hybrid language that allows a number of paradigms, including both object-oriented programming and procedural programming.


Ok, thanks a lot :)
Things are much clearer now.

[Edited by - Flashthinker on May 8, 2007 8:11:24 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
...

Windows API isn't programmed in anything. Windows API defines how Windows OS can be accessed from most MS supported languages (VB, C#, C++).


Oh, so do "system APIs" like Windows API's actual implementation define various Interfaces which are language-specific. So far, I'm thinking that the actual implementation (which as you said, is hidden) of the API is responsible for setting up ways by which it can comunicate with programming languages... And these "Ways" are what we, as programmers call the API. This would make a lot of sense, but am I on the right track?

I appreciate the amount of detail you used in your descriptions.

Thanks.

Share this post


Link to post
Share on other sites
Quote:

I am quite familiar with their structure and API. I do not know many advanced features. I only know what I need to know at this stage.


Quote:

The first and most important thing you need to learn is that you don't know as much as you think you know.


It's not a slight or an attack. Just a cautionary suggestion that people without a broad knowledge of the subject are ill-equipped to judge their own relative knowledge of the subject. There was a link semi-recently which described this a lot more eloquently than I, but alas I cannot find it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Flashthinker
Quote:
Original post by Antheus
...

Windows API isn't programmed in anything. Windows API defines how Windows OS can be accessed from most MS supported languages (VB, C#, C++).


Oh, so do "system APIs" like Windows API's actual implementation define various Interfaces which are language-specific. So far, I'm thinking that the actual implementation (which as you said, is hidden) of the API is responsible for setting up ways by which it can comunicate with programming languages... And these "Ways" are what we, as programmers call the API. This would make a lot of sense, but am I on the right track?


Today, if you want to draw something on screen with all the bells and whistles, you have DX and OpenGL, along with SDL and all that.

But before then, clearing screen buffer was different. On FooGraphics2000 card, clearing a screen was done with interrupt 56. On FooGraphics1200 card, it was interrupt 34, unless the user was in EGA compatibility mode, then it was 56 with parameter 0x023a.

But, BarVision required user to clear the memory by filling 0xA000 with zeroes, then calling interrupt 12. If user was in text mode, then they needed to fill 0xB000 with zeroes.

See the problem...

When VESA was introduced, it was sort of an API for graphics cards. It standardized common functionality. And while it was still obscure (interrupts, addressess, etc.), it was at least to a degree consistent.

Under VESA, clearing screen buffer as assigned interrupt 15. Calling that would work on all cards consistently.
Note: these numbers and the rest are made up.

But, whether you used assembler, Pascal, C++ or anything else, the only thing that was different, was how you issued an interrupt. The interrupt was always '15', but each language required different call to perform that. Function and logic remain the same, syntax differs.

Today, with processing constraints no longer being a problem, most functionality can be provided through a semantic high-level API. Types, calling conventions, transformations, they are all provided under the hood as needed.

Flexibility of an API however depends on its purpose. A C++ library doesn't need to be callable anything but C++. Microsoft Word API however needs to be language independant, and possibly even cross-platform, either via RPC or other means.

Quote:
Really? How would I go about invoking a native system API in Java?


You generally don't want to do that, but if you insist and abandon portability, look up JNI.

It's ugly, it's horribly ugly, it's incredibly ugly, but it works. You create piece of native code (C++ or C, it's been a while), compile it with your native compiler, then call that code from Java as it were a regular class or function.

It also provides means of passing Java types to and from native system.

But it's ugly. It's worse than ugly, it's fugly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
It's not a slight or an attack. Just a cautionary suggestion that people without a broad knowledge of the subject are ill-equipped to judge their own relative knowledge of the subject. There was a link semi-recently which described this a lot more eloquently than I, but alas I cannot find it.



It is an attack, but it was delivered with good intentions.
I'd like to think that I'm pretty humble, but I understand that some people do over-estimate their capability and I would appreciate being critisized if it were the case for me. But in my wording, I understand how it could seem like I was boasting, I was in fact just saying that, I "know" the languages in a casual manner, not in a "I'm the pro and James Gosling's knowledge in Java is like a pixel on a 22" LCD when compared to mine" kind of way.

Share this post


Link to post
Share on other sites
Quote:
Original post by Flashthinker
Really? How would I go about invoking a native system API in Java? I knew that you can use external APIs as in not-built-in system APIs, or maybe I didn't word my question properly, what I meant by *external* APIs was "Native APIs" like those C++ invokes; Win32 and OpenGL, I noticed that in Java, I can only use Java-specific APIs like Java3D and JOGL, can I use true OpenGL though?

If you use Jogl (or, my preference, LWJGL, then you're pretty much using OpenGL directly. All they really do is provide a bit of glue code between the C interface and the Java language. 99% of all OpenGL documentation still applies, and the bits that don't are usually trivial to convert.

Lots of APIs just provide a C interface as it's a good low-level common denominator. Then higher level languages just have to write a bit of glue to present the C functions as Java/Python/Whatever functions.

Share this post


Link to post
Share on other sites
Superpig is the highest rated member on these boards... He didn't get there by making remarks to put people down or attack them; he got there by being helpful and spend his time writing elaborate replies to peoples questions, as is the case here.

Try putting this 'attack' behind you and focus on the replies that you got that were on topic, since people are trying to help you here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!