Beginning Direct3D Game Programming Prima Tech S Game Development 1st Edition Wolfgang Engel Download
Beginning Direct3D Game Programming Prima Tech S Game Development 1st Edition Wolfgang Engel Download
https://ebookultra.com/download/beginning-direct3d-game-
programming-prima-tech-s-game-development-1st-edition-wolfgang-
engel/
https://ebookultra.com/download/beginning-java-game-programming-2nd-
edition-jonathan-s-harbour/
https://ebookultra.com/download/beginning-game-level-design-premier-
press-game-development-1st-edition-john-harold-feil/
https://ebookultra.com/download/beginning-ios-game-development-1st-
edition-patrick-alessi/
https://ebookultra.com/download/beginning-c-game-programming-2nd-ed-
edition-john-horton/
Beginning OpenGL Game Programming Second Edition Luke
(Luke Benstead) Benstead
https://ebookultra.com/download/beginning-opengl-game-programming-
second-edition-luke-luke-benstead-benstead/
https://ebookultra.com/download/fable-prima-official-game-guide-casey-
loe/
https://ebookultra.com/download/beginning-android-c-game-
development-1st-edition-bruce-sutherland-auth/
https://ebookultra.com/download/special-effects-game-programming-with-
directx-the-premier-press-game-development-series-1st-edition-mason-
mccuskey/
The Orange Box Prima Official Game Guide 1st Edition David
S. J. Hodgson
https://ebookultra.com/download/the-orange-box-prima-official-game-
guide-1st-edition-david-s-j-hodgson/
Beginning Direct3D Game Programming Prima Tech s
Game Development 1st Edition Wolfgang Engel Digital
Instant Download
Author(s): Wolfgang Engel, Amir Geva
ISBN(s): 9781417541904, 1417541903
Edition: 1
File Details: PDF, 7.01 MB
Year: 2001
Language: english
Beginning
Direct3D®
Game
Programming
Check the Web for Updates:
To check for updates or corrections relevant to this book and/or CD-ROM visit our updates page on the
Web at http://www.prima-tech.com/updates.
How to Order:
For information on quantity discounts, contact the publisher: Prima Publishing, P.O. Box 1260BK, Rocklin,
CA 95677-1260; (916) 787-7000. On your letterhead, include information concerning the intended use
of the books and the number of books you want to purchase.
Beginning
Direct3D®
Game
Programming
Wolfgang F. Engel
Amir Geva
Series Editor
André LaMothe
CEO Xtreme Games LLC
©2001 by Prima Publishing. All rights reserved. No part of this book may be reproduced or transmitted in any form or
by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval sys-
tem without written permission from Prima Publishing, except for the inclusion of brief quotations in a review.
A Division of Prima Publishing
Prima Publishing and colophon are registered trademarks of Prima Communications, Inc. PRIMA TECH is a
trademark of Prima Communications, Inc., Roseville, California 95661.
ISBN: 0-7615-3191-2
Library of Congress Catalog Card Number: 0-011047
Printed in the United States of America.
00 01 02 03 04 II 10 9 8 7 6 5 4 3 2 1
Für meine Frau, Katja Engel
vi Beginning Direct3D® Game Programming
Acknowledgments
This book couldn’t have been completed without the help of many people. In particular, I want to thank
my parents, who gave me a wonderful and warm childhood.
The first 90% of a book is normally easy to write. The problems arise in the second 90%. That was the
case with this book. The last four weeks of finishing up this project were really hard, both in my private
and professional life. So my corrections and reviews of edits were sometimes a little bit behind schedule.
Nevertheless, the team at Prima Publishing was very friendly and sensible. I would like to thank those peo-
ple, who also helped to make this book possible: Caroline Roop, Emi Smith, and Eve Minkoff.
I would also like to thank André LaMothe, for teaching me game programming with his books.
A lot of people wrote tutorials on game programming and published them on the Internet. I learned a lot
from these. So I would like to thank all those people on the Internet, for giving away their knowledge of
game programming for free.
—Wolfgang Engel
Contents at a Glance vii
Contents at a Glance
Introduction ...........................................xiv Part III Hardcore DirectX Graphics
Part I DirectX Graphics: Programming..............................209
Don’t Hurt Me ...............................1 Chapter 9: Working with Files................211
Chapter 1: History of Direct3D/DirectX Chapter 10: Quake 3 Model Files ...........247
Graphics................................................3 Chapter 11: Game Physics (written by
Chapter 2: Overview on DirectX Amir Geva) ........................................291
Graphics/HAL/COM .............................7 Chapter 12: Collision Detection (written by
Chapter 3: C++/COM Programming Rules Amir Geva) ........................................301
for Direct3D .........................................15
Part IV Appendices ....................343
Chapter 4: Geometry/Shading/Texture
Appendix A: Windows Game Programming
Mapping Basics ....................................23
Foundation.........................................345
Chapter 5: The Basics .............................35
Appendix B: C++ Primer........................373
Chapter 6: First Steps to Animation ..........73
Appendix C: The Common Files
Part II Knee-Deep in DirectX Framework .........................................401
Graphics Programming ..............125 Appendix D: Mathematic Primer............463
Chapter 7: Texture Mapping Appendix E: Game Programming
Fundamentals .....................................127 Resource.............................................485
Chapter 8: Using Multiple Textures.........153 Index ....................................................489
viii Beginning Direct3D® Game Programming
Contents
Introduction ..................................................xiv Render() ..................................................51
InvalidateDeviceObjects() ......................55
Part I: DirectX Graphics: DeleteDeviceObjects()............................55
Don’t Hurt Me......................1 FinalCleanup() ........................................55
Basic2 Example ............................................55
Chapter 1: History of Direct3D/ InitDeviceObjects().................................57
RestoreDeviceObjects() ..........................60
DirectX Graphics........................3 Render() ..................................................62
Chapter 2: Overview of DirectX InvalidateDeviceObjects() ......................64
DeleteDeviceObjects()............................65
Graphics/HAL/COM .................7 FinalCleanup() ........................................65
Direct3D HAL ................................................9 Basic3 Example ............................................65
Pluggable Software Devices.........................11 RestoreDeviceObjects() ..........................68
Reference Rasterizer....................................12 Render() ..................................................70
Controlling Devices......................................12 InvalidateDeviceObjects() ......................72
COM..............................................................13
Chapter 6: First Steps to
Chapter 3: C/C++ and COM Animation ................................73
Programming Rules for The Third Dimension .....................................75
Direct3D ..................................15 Transformation Pipeline .................................77
Code Style .....................................................18 Transformation Math.......................................80
Debugging DirectX......................................20 Matrices.............................................................80
Return Codes................................................21 The World Matrix.........................................82
The View Matrix...........................................86
Chapter 4: Geometry/Shading/ Camera Rotation about a Camera
Texture-Mapping Basics.............23 Axis .........................................................88
Orientation ...................................................26 Camera Rotation with Quaternions ......92
Faces ..............................................................27 The Projection Matrix .................................95
Normals.........................................................29 Lighting.............................................................96
Normals and Gouraud Shading..................29 Material .........................................................97
Texture-Mapping Basics...............................31 Lighting Models ...........................................97
Vertex Color (Optional)..............................99
Chapter 5: The Basics.................35 Depth Buffering .............................................100
The DirectX Graphics Common Down to the Code..........................................104
Architecture................................................37 OneTimeSceneInit() .................................105
Basic Example ..............................................38 InitDeviceObjects()....................................110
OneTimeSceneInit() ..............................40 RestoreDeviceObjects().............................110
InitDeviceObjects().................................41 FrameMove()..............................................113
RestoreDeviceObjects() ..........................41 Render() .....................................................117
FrameMove()...........................................51 InvalidateDeviceObjects().........................118
Table of Contents ix
Dear Reader,
The 3D API wars on the PC are over. And no matter how you feel, Direct 3D is the victor on the PC
platform. Amazingly enough, it sure didn’t have to do with an over-abundance of clear documentation
about Direct 3D! In fact, after years of the Direct 3D API being available, only one or two books are of
any merit on the subject. With this in mind the Author of Beginning Direct 3D Game Programming, Mr.
Wolfgang Engel, set out to write a beginner’s book on Direct 3D that also covered Direct X and General
Game Programming theory. I can without hesitation state that he has succeeded, and succeeded where oth-
ers have failed.
This text is fantastic; it has a pace that is both challenging and cutting-edge, but not intimidating. You will
find yourself learning very complex ideas very easily. Moreover, this book is one of the most graphically
annotated books on Direct 3D, so you won’t be left wondering what something is suppose to look like!
Additionally, although this book is for beginners it doesn’t mean that the material is basic. In fact, as the
chapters progress you will cover advance concepts such as multitexturing, lighting, TnL, 3-D file formats,
and more!
André LaMothe
March 2001
xiv Beginning Direct3D® Game Programming
Introduction
When I finished my first degree in law back in 1993, I was very proud and a little bit exhausted from the
long learning period. So I decided to relax by playing a new game called Comanche by NovaLogic.
I started the night of January 11 and ended up about three days later with only a few hours of sleep. With
the new experience in my head, I decided to start computer game programming. My target was to program
a terrain engine like Comanche.
My then-girlfriend—now my wife—looked a little bit confused when a young, recently finished lawyer
told her that he’s going to be a game programmer.
About two years later, after becoming a member of the Gamedev Forum on Compuserve and reading a
few books on game programming by André La Mothe and a good article by Peter Freese on height-map-
ping engines, I got my own engine up and running under OS/2. I wrote a few articles on OpenGL and
OS/2 game programming in German journals, coauthored a German book, and started with the advent of
the Game SDK (software development kit) on Windows game programming.
In 1997 I wrote my first online tutorials on DirectX programming on my own Web site. After communi-
cating with John Munsch and the other administrators of www.gamedev.net, I decided to make my tutori-
als accessible through this Web site also. In the summer of 1998, as a Beta tester of the DirectX 6.0 SDK,
I decided to write the first tutorial on the Direct3D Immediate Mode Framework. At that time I used
www.netit.net as the URL of my Web site. There was a mailing list with a lot of interested people, and I
got a lot of e-mails with positive feedback.
It started to be real fun. In 1999 I fired up my new Web site at www.direct3d.net, which is now also
accesible through www.directxgraphics.net, with the sole purpose of providing understandable and
instructive tutorials on Direct3D programming.
This is also the target of the book that lies in front of you; it should help you to understand and learn
DirectX Graphics programming.
If you have any questions, don’t hesitate to e-mail me. A lot of things are implemented with the questions
of readers in mind.
Mainz, Germany, December 2000
Wolf ([email protected])
FOOTNOTE:
[13] I use the term “suggested hallucination” to indicate the
character and origin of the latter. The term seems to me
convenient and may prove acceptable.
CHAPTER XXVI
The hypnoidal state into which man is apt to fall so easily, is well
adapted to fear suggestions, since the fear instinct and the impulse
of self-preservation are present in the subconsciousness, exposed
during trance states to all sorts of fear suggestions and
superstitions. It is during these brief periods of primitive hypnoidal
states that the animal is exposed to attacks of enemies whose
senses become sharpened to detect the weak spots in the armor of
their victims, immersed in the momentary rest of the hypnoidal
state.
During these periods of repose and passivity or of sleep stage, the
animal can only protect itself by all kinds of subterfuges, such as
hiding in various inaccessible places, or taking its rest-periods in
shady nooks and corners, or in the darkness of the night. Each
hypnoidal period closely corresponds to the larval stage of the
insect, reposing in its cocoon,—the most critical time of the insect
organism, most exposed to the depredations of its enemies. And still
the hypnoidal state is requisite to the animal in order to restitute its
living matter and energy which have been wasted during the active
moments of its life activities. Hence the weakness of the animal
depends on the very constitution of its organism.
The hypnoidal state, although absolutely necessary in the process
of metabolism, is also the moment of its greatest danger, and the
fear instinct is specially intense at the onset of that hypnoidal
moment, the lowest point of the weakness of the organism. The
animal, after taking all precautions, is finally paralyzed into
temporary immobility at the risk of its own existence.
The fear instinct determines the nature and character of rest and
sleep. The lower the animal, the scantier are its means of defense in
the ceaseless struggle for its preservation. The simpler the animal,
the greater and more numerous are the dangers menacing it with
total extinction,—hence it must be constantly on its guard. A state of
sleep such as found in the higher animals is rendered impossible.
The sleep must be light, and in snatches, rapidly passing from rest
into waking,—the characteristic of the hypnoidal state. The fear
instinct is the controlling factor of sleep and rest. When we are in
danger the sleep is light and in snatches, and we thus once more
revert to an ancient form of rest and sleep.
The insomnia found in cases of neurosis is a reversion to primitive
rest-states, found in the lower animals. The insomnia is due to the
fear instinct which keeps dominating the conscious and subconscious
mental activities, a state which has prevailed in the early stages of
animal life. That is why the sleep of neurotics is unrefreshing and full
of dreams of dangers and accidents, and peopled with visions of a
terrorizing nature. Hence the neurotic fear of insomnia which is itself
the consequence of the obsession, conscious and subconscious, of
the fear instinct.
In my work on sleep I was greatly impressed with the place fear
holds in animal life existence. From the lowest representative, such
as the insect to the highest, such as man, fear rules with an iron
hand. Every animal is subject to cataplexy of fear and to the
hypnoidal state itself, the consequence of fear-adaptations to the
external conditions of a hostile environment. Cataplexy and the
consequent hypnoidal state which paralyze the animal, depriving it
of all defense, are grounded in the imperfections of living
protoplasm.
Man is subject to the hypnoidal periods of primitive life. It is
during those periods that the shafts of suggestion are most apt to
strike his subconsciousness, divorced as it is during those moments
from the nodding self consciousness. During these nodding moments
of his life he is exposed to harmful suggestions, since they are apt to
arouse the fear instinct, the most sensitive of all human instincts. It
seems as if the fear instinct is never fully asleep, and is the easiest
to arouse. It seems to be watchful or semi-watchful during the most
critical moments of man’s helplessness.
Fear of darkness and fear of invisible foes are specially strong in
man, because of the deeply rooted fear instinct, but also because of
his memories of accidents and dangers that have befallen him, and
which may befall him. Man’s fears hang round dark places, gloomy
corners and nooks, caves and forests, and more especially during
the darkness and shades of night, appearing as treacherous visions
and specters of lurking dangers. And still from the very nature of his
being man must rest and sleep, hence the association of terrors with
night time. He can only overcome his night terrors by living and
sleeping in more or less secure corners, in the neighborhood of his
fellow-beings who by the mere fact of numbers multiply not only the
means of defense, but actually increase susceptibility for the scent of
danger and possible speedy defense. In the society of his fellows the
sense organs of the individual are increased by the presence of
others who are in various stages of vigilance, and hence there is
greater protection against dangers and invisible foes that lurk in the
darkness of night, foes of which primitive man is in terror of his life.
The fear of the unknown, the mysterious, and the dark, peoples
the mind of primitive man with all sorts of terrible spectres, ghosts,
spirits, goblins, ghouls, shades, witches, and evil powers, all bent on
mischief, destruction and death. Primitive man suffers from chronic
demonophobia. Fear states are specially emphasized at night when
the “demons” have the full power for evil, and man is helpless on
account of darkness and sleep which paralyze him. Hence the terrors
of the night, especially when man is alone, and defenseless.
The fear of solitude comes out strongly in the intense fear that
obsesses man in the gloomy darkness of the night horrors. Fire and
fellow-beings can alone relieve his night terrors. The fear of foes, of
demons, of evil powers does not abate in the day, only it is relieved
by reason of light, of association, and of wakefulness. Man, more
than any other animal, is the victim of the fear instinct. Many tribes,
many races of men perished, due to superstitions and fear
obsessions.
The Homo sapiens is rare. We may agree with Tarde that Homo
somnambulis would be a proper definition of the true mental
condition of most specimens of the human race. For the human race
is still actuated by the principle of “Credo, quia absurdum est.” I
need not go far to substantiate the fact that this principle still guides
the life of the average specimen of civilized humanity. Spiritualism,
theosophy, telepathy, ghost hunting, astrology, oneiromancy,
cheiromancy, Christian Science, psychoanalytic oneiroscopy
employed in events and situations of individual and social life, and
many other magical practices whose name is legion, based on the
mysteries of communication with ghosts, spirits, demons, and
unknown fearsome powers, still haunt the credulous mind, obsessed
with conscious and subconscious horrors of the terrible, invisible
spirit world.
Against the fears of diseases, the scares of the day and terrors of
night, civilized man still uses the magic arts and mysterious,
miraculous powers of the magician, the wizard, the witch, the
mental healer, the shaman, the medicine man, the miracle man, and
the psychoanalyst. Just at present under my own eyes I witness the
pitiful credulity of man, driven by the terrors and horrors of the fear
instinct. In San Jose, San Diego, in Los Angeles, and in many other
Western “culture” centers mystic cults hold high carnival, swaying
the minds of fear-crazed, deluded humanity. As typical specimens of
superstitious fears and absurd beliefs, due to the fear instinct, we
may take as illustrations the following occurrences in the centers of
the far West, obsessed by the aberrations of the fear instinct (I
quote from Los Angeles papers):
“Faith Healer at Los Angeles, Venice, California, after several
wonder cures, orders sun’s rays to be darkened. ‘Brother Isaiah,’
called by thousands the ‘Miracle Man,’ claimed to have repeated the
marvel of dimming the sun at Venice yesterday evening.
“At 6 o’clock the disciple of healing by faith raised his hands and
announced that as evidence of his power he would blot out the
brilliant solar rays. He gazed at the dazzling red ball above the
waters of the Pacific, and his lips moved in low murmurs.
“‘It is done,’ he said. ‘I have clouded the sun. All those who have
seen this miracle raise your hands.’ Hundreds of hands waved in the
air.
“The first time ‘Brother Isaiah’ claimed to have dimmed the sun’s
rays was at Miracle Hill, when he had been in Los Angeles but a few
days.
“Brother Isaiah stepped to one side of his wooden platform on the
Venice Beach yesterday. He placed a silver police whistle to his lips
and blew. The piercing crescendo sent a shiver through the tense
mass of humanity which stretched from the sand back to the ocean
walk.” Similar miracles and cures were carried on by Mrs. Amy
McPherson in San Diego, San Jose, and all along the Pacific coast.
The self-impulse and the fear instinct, in their intensified forms,
are the bane of deluded, neurotic humanity.
CHAPTER XXVII
FOOTNOTE:
[14] Darkness and terror of the soul are not dispelled by the rays
of the sun and glittering shafts of the day, but by the rational
aspect of nature.
CHAPTER XXIX
P RIMITIVE FEARS
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com