I am completely new to writing code for any PC, so far I have only written code for pic micro controllers.

But I think I could get started if I just understood more about header files.

How do they function with the hardware in my computer?

Are there specific header files that I must have for my hardware?

How is a header file different from an include file?

Where can I find the header file I need? ( maybe a graphics header file ).

Sorry for the load of questions, I hardly even know what I am talking about:confused:.

01-27-2009

matsp

If you have a Windows or Linux OS on your PC, I'd say that it's unlikely that you will ever "touch" real hardware with your code - that's device driver land, which is in the "obscure" part of programming. Most people never get to do that (or have the interest to do so).

If we are discussing game programming, then certainly, you will not be dealing directly with the hardware - that's someone else's problem.

If you are programming 3D games for your PC, then DirectX or OpenGL would be the API's you are looking to use. DirectX is Windows only. OpenGL is fairly portable to various OS's and types of machines (e.g. mobile phones).

--
Mats

01-27-2009

RaisinToe

Thank you for the insight.

I will be doing my programming on a windows system.
For now, I will stick to game programming for learning purposes. But I'm affraid I'll have to understand a lot more than what a header file is.:)
OpenGL would be a good place to start since it works with other systems.

In openGL would I still be working in C code, or is it a little different?

It would do me good to get a book; I came across this one before, has anyone here read it?

Another question:rolleyes::confused:
Is it possible to work directly with the hardware of my computer, or would I need to do it through a whole other computer system?

Thank you,

It's not so much what hardware you have, but rather the fact that the OS prevents you from actually reaching to the hardware from application code. To reach the hardware, you would need to be inside the kernel level, which means writing driver code. This is not simple.

--
Mats

01-27-2009

RaisinToe

Thank you,

Now back to my original question. I was wondering what a header file does. Since I know now that it couldn't work direcly with my hardware, it must work according to the opperating system I am using.
In that case, one header file should work for any computer with the same opperating system. Right?

Here is a code I was going to try, but I didn't know anything about where to get the header files, or even what they do. I have used include files when working with micro controllers. They list the contents of the specific microcontroller. Is that the basic idea of a header file, does it list the elements of the opperating system so I can work easily with it?

A header-file will introduce functions and data types (structures, unions, typedefs and enums) to the source you are compiling.

It allows you to use code that isn't available as source code (or that isn't being compiled at this time).

The posted code looks like something for Turbo C. That compiler is nearly 20 years old, and in computer terms, that is a VERY old product. I would recommend using either gcc (perhaps in conjunction with Code::Blocks to get an integrated development environment [IDE]) or Microsoft Visual Studio - this is an IDE and a very slick one at that.

--
Mats

01-27-2009

RaisinToe

Quote:

Originally Posted by matsp

I would recommend using either gcc (perhaps in conjunction with Code::Blocks to get an integrated development environment [IDE]) or Microsoft Visual Studio - this is an IDE and a very slick one at that.

--
Mats

I have heard of gcc, but I hardly know what it is?

01-27-2009

matsp

Quote:

Originally Posted by RaisinToe

I have heard of gcc, but I hardly know what it is?

gcc is short for "Gnu Compiler Collection", and it is a C compiler that is Open Source - meaning that anyone can get the source code for the compiler [but be aware that the source code is very VERY far from "begginners easy read code"]. The compiler is close to compliance with the C99 standard, and it's a good compiler in the sense that it warns for many common mistakes.

--
Mats

01-28-2009

Dae

Quote:

Originally Posted by RaisinToe

Does that mean I can create a simple 2D game right now with a C compiler?

You can create a simple 2D or 3D game right now with a C compiler. You would still need a header file (API) either way though. You can do basic 2D (mipmap) with the operating system API (such as win32) which comes with your computer, or basic 3D with a graphics device API (such as opengl) which comes with your computer. SDL doesn't come with your computer, but that's nothing to worry about. Either way you need a header file/s, and either way your system will be using a library (DLL) in the background, which you need to tell your compiler to link (say "this code will work if you can find this library in the current directory or system directory").

Just so you know, diving straight into OpenGL or Direct3D is harder than using a wrapper such as SDL, Irrlicht, etc. Just like how Flash API (not C++) provides an easy 2D scene to code, as it wraps all the inner workings. If you're trying to create a game, you're not trying to learn OpenGL or Direct3D. They are just part of the required tools. Tools which have already been created. You should understand how these tools work before you create your own graphics engine, if you even want to.

01-28-2009

Elysia

Working on PCs, you will not work directly with hardware, nor should you. That task is handled by the operating system.
What a header is what already explained to you... but surely, you must have made your own header files sometimes?
And lastly a bit of advice. Both OpenGL and DirectX work with C. However, if and when you are aiming for bigger projects, you should study C++, since C is not a really good tool for big and complex projects, such as games.

01-28-2009

RaisinToe

Quote:

Originally Posted by Dae

Either way you need a header file/s, and either way your system will be using a library (DLL) in the background, which you need to tell your compiler to link (say "this code will work if you can find this library in the current directory or system directory").

Thank you, that helps.
But this is all still very new to me, how would I link my compiler to the DLL?

01-28-2009

matsp

Normally, by adding it to the "linker inputs" in your project settings or similar. Normally each DLL has a corresponding .LIB file that you link against, and it contains the information necessary for the program to use the DLL when it comes to running the executable file. As long as it can find the DLL that is.

--
Mats

01-28-2009

Dae

Quote:

Originally Posted by RaisinToe

Thank you, that helps.
But this is all still very new to me, how would I link my compiler to the DLL?

If you're using a command-line compiler (such as GCC) then you need to specify the necessary parameters. If you're using an IDE program (such as code::blocks or visual studio) they provide a GUI for those options and tell the compiler for you. The options can usually be found under project settings -> linking depending on the IDE.

Your IDE will automatically link DLL's when you create a common project. Code::Blocks comes with Win32, OpenGL, Irrlicht projects predefined. If it's not as common you'll have to create a blank project and manually link in the project options.

01-28-2009

RaisinToe

OK, thanks
I just have a goofy IDE. It has a place to put linker information, but I need to learn how to use it.