Newbe question

This is a discussion on Newbe question within the Game Programming forums, part of the General Programming Boards category; I am completely new to writing code for any PC, so far I have only written code for pic micro ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    31

    Question Newbe question

    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.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    31
    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?

    http://www.amazon.com/gp/product/032...pf_rd_i=507846


    Another question
    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,

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    31
    Oh, didn't notice you said openGL is for 3D games.

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

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by RaisinToe View Post
    In openGL would I still be working in C code, or is it a little different?
    OpenGL has a C interface, so that would be fine (it's most likely written in C as well, but that's not really important).

    It would do me good to get a book; I came across this one before, has anyone here read it?
    This OpenGL Programming Guide is supposed to be the authority on the subject.

    Another question
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    31
    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?

    Code:
    #include <graphics.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    int main(void)
    {
    /* request auto detection */
      int gdriver = DETECT, gmode, errorcode;
    /* initialize graphics mode */
      initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
      errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
      {
        printf("Graphics error: %s\n", grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1); /* return with error code */
      }
    /* draw a line */
      line(0, 0, getmaxx(), getmaxy());
    /* clean up */
      getch();
      closegraph();
      return 0;
    }
    Last edited by RaisinToe; 01-27-2009 at 03:05 PM.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Jan 2009
    Posts
    31
    Quote Originally Posted by matsp View Post

    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?

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by RaisinToe View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by RaisinToe View Post
    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.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  12. #12
    Registered User
    Join Date
    Jan 2009
    Posts
    31
    Quote Originally Posted by Dae View Post
    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?

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by RaisinToe View Post
    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.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  15. #15
    Registered User
    Join Date
    Jan 2009
    Posts
    31
    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.

    It was just a free IDE/compiler from downloads.com.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbe question
    By Kitu in forum Windows Programming
    Replies: 1
    Last Post: 12-18-2004, 01:14 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21