Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

02.07 - The Readiness Test

  • You cannot reply to this topic
215 replies to this topic

#1 Teej   GDNet+   -  Reputation: 176

Like
Likes
Like

Posted 20 April 2001 - 04:05 AM

Oh Goody, Code Time! Alright recruits, we’re about to test your compiling and linking skills. I’ve added a zipfile called BASECODE1 on my website that I’d like you to download now (don’t unzip it yet though!). The zipfile contains the following files:
  • Globals.h – the main header file for the game template
  • WinBase.cpp – the windows application overhead we’ve discussed
  • InitTerm.cpp – the initialization/shutdown functions
  • GameMain.cpp – where the game code goes
  • Utils.h – prototypes for our helper functions
  • Utils.cpp – the helper functions themselves
  • Resource.bmp – a sample bitmap
  • Sample.wav – a sample WAV file
Once you have this file in your possession, it’s time to create a project for our game template. Folks, the following discussion pertains specifically to those using the Microsoft Visual C++ (MSVC) IDE (a part of Microsoft Visual Studio). If you’re doing something else, you might need to raise a fuss by replying to this article if you need assistance. Create a New Project To create a project, Choose File|New , and select Win32 Application from the list of project types. Provide a name and location for this project (BaseCode1 would be a good idea) and let the IDE create an empty project for you. Once it’s done, there will be a new directory created for you with some standard project files already there. This is where we’d like the BaseCode1 files to end up, so go ahead and unzip the archive to there. The end result is that you’ll have a single directory (perhaps called BaseCode1 ) that contains all of these files. Adding these files to our new project involves nothing more than selecting the FileView tab on the bottom left of the IDE (or wherever you placed the project view) and right-clicking on BaseCode1 files . Add them all in by selecting them and there you have it! Ah, but wait! We’re not ready to attempt building the project yet. A couple more steps are involved. Tell the IDE Where to Look Move to Tools|Options|Directories , and you’ll see a list of locations that the IDE searches through when looking for project files. We’re not talking about our files here – they’re all in the project’s directory and therefore easy for the IDE to find. No, what the compiler is really going to have a hard time finding without our help is all of the DirectX header files that we intend to use. So, here’s what you do. Where did you install your DirectX SDK? Mine is at C:\DXVCSDK , so I’ll use that as an example (substitute with your own). All of the DirectX header files are located in the INCLUDE subdirectory, so you’d add an entry like this to the list: C:\DXVCSDK\INCLUDE Now that you have it in the list, and this is very important, move the entry up until it’s the very first one. The reason for this is because MSVC comes with some older DirectX header files, and if the IDE looks in the MSVC default directories before trying yours, things will be screwed-up. Tell the Linker Where to Look The IDE may now know where all of the header files are (in our project directory and in the DirectX SDK include directory), but it also needs to know where the ‘real’ DirectX code libraries are. After all, the header files only contain prototypes (kind of like usage instructions) for the DirectX components – the components themselves are in DLL files on your system. What the linker needs to do is know which libraries (files with linking instructions) are needed for our project. We’ll be looking at compiling and linking in a later article, but for now here’s what I’m talking about: Our project uses these files:
  • DDRAW.H
  • DINPUT.H
  • DSOUND.H
…which contains prototypes for the DirectDraw, DirectInput and DirectSound components we’re using. The actual components (the DirectX runtimes) are called:
  • DDRAW.DLL
  • DINPUT.DLL
  • DSOUND.DLL
…which are the files that everyone has for playing DirectX games with. Finally, we have library files that connect code using DirectX components:
  • DDRAW.LIB
  • DINPUT.LIB
  • DSOUND.LIB
Okay, so just read this next sentence very carefully and you’ll be fine: Our source code is compiled with instructions contained within header files, and linked with instructions contained in library files, which ultimately allow our code to use the components in the runtime (DLL) files. So, where was I? Oh yeah… Head to Project|Settings|Link , and you’ll see an edit field called Object/library modules . You may even see some entries already here, all ending in .LIB. All we need to do is add our library files here, and they happen to be located in a directory called LIB inside our main DirectX folder. What I do is add this to the front of the library list: C:\DXVCSDK\LIB\*.lib If there are other libraries in this list already, leave them after yours (separated by a space). Now, there happens to be one other library that we’re using (for our sound code), so you’ll need to add WINMM.LIB to this list as well. So, to recap, let’s say that when you first showed up in this dialog, the edit box showed something like: SOMELIB.LIB OTHERLIB.LIB YETMORE.LIB… (Whatever their names actually are, who cares). Now it should be: C:\DXVCSDK\LIB\*.lib WINMM.LIB SOMELIB.LIB OTHERLIB.LIB… Got it? Mission Control… Now for the big moment. Build the project (by hitting F7), and pray that you see ‘0 errors, 0 warnings ’ when it’s done. If you are having problems, first realize that the build process involves two stages, compiling and linking, both with their own types of errors. For instance, the link process won’t even begin if there were errors in the compile stage. Either you saw ‘Linking…’ in the output window or you didn’t. If you are getting complaints like:
Compiling...
GameMain.cpp
c:\gdn\basecode\globals.h(87) : error C2146: syntax error : missing ';' before identifier 'lpDD'
c:\gdn\basecode\globals.h(87) : error C2501: 'LPDIRECTDRAW7' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(87) : error C2501: 'lpDD' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(88) : error C2146: syntax error : missing ';' before identifier 'lpDDSPrimary'
c:\gdn\basecode\globals.h(88) : error C2501: 'LPDIRECTDRAWSURFACE7' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(88) : error C2501: 'lpDDSPrimary' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(89) : error C2146: syntax error : missing ';' before identifier 'lpDDSBack'
c:\gdn\basecode\globals.h(89) : error C2501: 'LPDIRECTDRAWSURFACE7' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(89) : error C2501: 'lpDDSBack' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(90) : error C2146: syntax error : missing ';' before identifier 'lpDDSRes'
c:\gdn\basecode\globals.h(90) : error C2501: 'LPDIRECTDRAWSURFACE7' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(90) : error C2501: 'lpDDSRes' : missing storage-class or type specifiers
c:\gdn\basecode\globals.h(94) : error C2146: syntax error : missing ';' before identifier 'lpDI'
c:\gdn\basecode\globals.h(94) : error C2501: 'LPDIRECTINPUT7' : missing storage-class or type specifiers
  
(…on and on…) then you probably need to make sure that you’re pointing the IDE to the DirectX header files (look in Tools|Options|Directories ). If you have other compile errors, try to get ahold of me (teej@gdnmail.net or 70816765 on ICQ) or post a reply to this article with your questions. As for the linking, well, that’s primarily the job of the LIB list we prepared under Project|Settings|Link. Here’s an example of having it entered incorrectly:
Linking...
InitTerm.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16
InitTerm.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw7
InitTerm.obj : error LNK2001: unresolved external symbol _c_dfDIKeyboard
InitTerm.obj : error LNK2001: unresolved external symbol _GUID_SysKeyboard
InitTerm.obj : error LNK2001: unresolved external symbol _IID_IDirectInputDevice7A
InitTerm.obj : error LNK2001: unresolved external symbol _DirectInputCreateEx@20
InitTerm.obj : error LNK2001: unresolved external symbol _IID_IDirectInput7A
InitTerm.obj : error LNK2001: unresolved external symbol _DirectSoundCreate@12
Debug/basecode.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

basecode.exe - 9 error(s), 0 warning(s)
  
As you can see, since the libraries weren’t included properly, the poor linker was lost when it came to including these symbols. Once again, let us know if you’re stumped. NOTE: When we added the libraries in for the linker, you may have noticed on the left side of the screen that there was a box that had ‘Settings for: Win32 Debug ’. Keep in mind that these libraries that you’re adding are only valid when in Debug mode. You can either change this box to read ‘All Configurations ’ before entering your libraries, or enter them a second time when in Release mode. So Far So Good… If you managed to reach the finish line, ‘0 errors, 0 warnings ’, run the program (CTRL-F5) and hopefully you’ll be rewarded with some text on the screen. The space bar will cause a sound to play, and ESCAPE will exit the program. If you aren’t here yet, don’t bother continuing in the forum! That’s why this is called the ‘Readiness Test’… if you can’t get this stuff to run you need to let us know so that we can help rectify the situation. What about the program itself? On the surface, it doesn’t seem to do much. In fact, it uses DirectDraw, DirectInput and DirectSound in proper form (initialization, use and shutdown), so it’s a good learning example. In later articles we will be using and building on this framework, so it’s a good idea to get your DirectX online documentation ready and try going through the code. Of course, the documentation provides excellent introductory material on each of these components, and if you take the time to read some of it you’ll be ahead of the game. The Ladder series was designed to represent ‘prerequisite knowledge’. You know have everything you need to start on your path to enlightenment:
  • An introduction to game development
  • A basic windows application framework
  • C language resources
  • A quick overview of some of the basic tools required
  • Some insight into how a game might be written
  • Information on resolutions, colors and pixel plotting
  • The role of DirectX in our games
  • A first run with some game template code
Congratulations… You have your compiler/linker in order, the DirectX runtimes and SDK installed, the online documentation at your fingertips, and some template code that sits before you like an open book with blank pages – ready to be filled in with the knowledge and practice that is the rite of passage for any apprentice. Get ready folks, because next up is the proverbial ‘Square One’. See you there. Questions? Comments? Can’t get the damned code to build? Reply to this article – help is on the way! Edited by - teej on April 20, 2001 11:10:00 AM

Sponsor:

#2 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 10:10 AM

i can build the program fine errors 0 and warnings 0
but when i try to run it says DD_init faild.|-7
please help!

Fighterdude(A Baldurs Gate Fan)

#3 Lord Maz   Banned   -  Reputation: 110

Like
Likes
Like

Posted 20 April 2001 - 10:26 AM

I can''t get my modem to download those directx files.. the connection is too slow, and it stoppes after a while
If anyone could upload the files on a better server (or buy me a better modem!), I would be gratefull!



-Lord Maz-

#4 Qunu   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 11:06 AM

Fighterdude: make sure you have the resource.bmp and sample.wav files in the same directory as your executable.

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 20 April 2001 - 11:07 AM

Fighterdude: make sure you have the resource.bmp and sample.wav files in the same directory as your executable.

#6 Crox_guldtand   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 11:29 AM

Hey Fighter dude!

You haven´t got the "resource.bmp" file in the same catalog/dir.
as the other files.
Just put it there and it´ll work fine.





#7 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 02:27 PM

i have them all in the same directory
and it still does the same thing.
please help

Fighterdude(A Baldurs Gate Fan)

#8 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 02:30 PM

Forget the last post i just got what you were saying and it works now Thanks Guys

Fighterdude(A Baldurs Gate Fan)

#9 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 03:01 PM

Just wonderin Teej is the next artical the C LANGUEGE or you gonna post a new one? Great job Teej i realy like it!

Fighterdude(A Baldurs Gate Fan)now that''s a good Game

#10 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 03:01 PM

Just wonderin Teej is the next artical the C LANGUEGE or you gonna post a new one? Great job Teej i realy like it!

Fighterdude(A Baldurs Gate Fan)now that''s a good Game

#11 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 03:03 PM

sorry for Multi-Post

Fighterdude(A Baldurs Gate Fan)

#12 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 05:14 PM

do i have to get the online version or can i get it in word format?

Fighterdude(A Baldurs Gate Fan)

#13 Fighterdude   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 05:16 PM

The Docs i mean!

#14 Mucman   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 April 2001 - 06:59 PM

Well I''ll be darned! It worked at the first build! Should I be surprised



"You won''t get wise with the sleep still in your eyes." - Neil Peart

#15 Thalion   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 April 2001 - 07:59 AM

Why do I get this error?

Compiling...
WinBase.cpp
InitTerm.cpp
Utils.cpp
GameMain.cpp
Linking...
LINK : fatal error LNK1104: cannot open file "C:\program.obj"

#16 Higgenkreuz   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 April 2001 - 08:05 AM

Please help!
I get the following messages while I try to compile:
Linking...
d:\dxvcsdk\lib\ddraw.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x389bc793
Error executing link.exe.

I checked the path to my lib file, it is fine, also, I still have some 150MB of free space on my HD.

Any ideas?

Thanks in advance.

#17 Scogs   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 April 2001 - 11:42 AM

Thalion,

I had the same error as you, so I deleted the project, re-installed the SDK, followed Teej''s instructions again and it all worked fine. Try it, you never know it might work?

Scogster.

PS. Teej your a top man.



#18 thadarkangel   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 April 2001 - 02:42 PM

i cant find the site if you can send me the adress or the files to my email i will apreciate it.


you are doing a good job

my email is thadarkangel@hotmail.com

Edited by - thadarkangel on April 21, 2001 9:44:42 PM

#19 Mucman   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 April 2001 - 04:59 PM

As for readiness, are we expected to know and understand what the heck all those utility functions do? Or know exactly how the implementation works?

"You won''t get wise with the sleep still in your eyes." - Neil Peart

#20 Piotyr   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 April 2001 - 05:25 PM

At this point, just think of it as a black box "template" to program your game code in. The only function you need to worry about if you use the template is really the Game_Main function, and perhaps a bit about the shutdown and/or init functions. Don''t get overwhelmed. If you''re completely lost, there are some good tutorials around on DirectX to learn more than what Teej overviewed thus far, and he might even go more in-depth at a later time.





PARTNERS