Important alert: (current site time 7/15/2013 6:35:19 PM EDT)
 

winzip icon

A 3D World (OpenGL walk through city) *FIXED*

Email
Submitted on: 1/9/2001 7:23:42 PM
By: Dustin Davis 
Level: Advanced
User Rating: By 28 Users
Compatibility: C++ (general), Microsoft Visual C++
Views: 65420
(About the author)
 
     This code is the starting point of any 3d gamer's quest to design a 3d game. It will show you how to use openGL to load and display 3d models and show you basic keyboard input along with mouse input. Move around just like in UT or Half-Life. Use mouse look, strafe and take a nice walk around this very very small city. I got the textures working, i made a mistake...sorry. But since the file was almost 1mb with the textures as they were, i had to make em 256 color so they dont look all that pretty!

Make sre to extract the 3dworld folder to c:\windows\desktop otherwise the textures wont work! Sorry but this is the only way i could fix it.


 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :A 3D World (OpenGL walk through city) *FIXED*
//**************************************
Make sre to extract the 3dworld folder to c:\windows\desktop otherwise the textures wont work! Sorry but this is the only way i could fix it.
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/9/2001 7:25:54 PMDustin Davis

Hey guys. If this doesnt load right, or it doesnt look right when it does load, let me know. I left out the material files due to size of the zip but the program seems to run with out them...go figure. Anyways, Please Please let me know if there are any problems.
(If this comment was disrespectful, please report it.)

 
1/9/2001 11:08:19 PMMouse

i can load it allright.. but, the sky is black, and the building are all white.. i can see a sillouette of the buildings though... the mouse movements look good.. this is a neat example i hope you can give me some pointers on how to load the graphix correctly

(If this comment was disrespectful, please report it.)

 
1/10/2001 1:23:40 AM

wow nice picture. i dont know anything about c/c++ but can you make a .exe with the "material
files" so i can see how this looks like..... and than post a link where i can download the .exe.

Thanks alot.

Man, I love the picture its like a real 3d game.
(If this comment was disrespectful, please report it.)

 
1/10/2001 1:52:56 AMMouse

yeah this is too cool!! i wish i could figu±.Ð4ut why the textures dont load though =(

(If this comment was disrespectful, please report it.)

 
1/10/2001 1:58:28 AMASERB

Hey, Dustin

plz. upload the .zip i want to see how it looks with the textures. thx. alot. post the .zip or .exe link soon.
plz. thx.
(If this comment was disrespectful, please report it.)

 
1/10/2001 2:02:15 AMASERB

o and make a .exe for the project i also dont know about Visual C++. lol... thx.
(If this comment was disrespectful, please report it.)

 
1/10/2001 2:15:03 AMMouse

i figured it out (i think)
its looking for a LIB that doesnt exist located here:
D:\nt\private\windows\opengl\toolkits\libaux
it fails with this type:
AUX_RGBImageRec
something to do with IMAGE.C ?

(If this comment was disrespectful, please report it.)

 
1/10/2001 2:27:07 AMAndrew Heinlein (Mouse)

haha ok i gotta stop posting.. this is too cool though... The model you sent wont work cause it doesnt store the pictures internally. Its looking for the pictures on my computer, and they dont exist. So i made my own model and the textures are in BMP format. But when i load the model i get a bunch of errors saying "invalid DIB format" and im using bmp's saved by MSPaint. What format of picture did you use to make your model? atleast im making advances.. now i actually get errors =)

so can you let me know what format the pictures are supposed to be in?
thanks =)
(If this comment was disrespectful, please report it.)

 
1/10/2001 2:31:58 AM

hey mouse make a .exe and link it to me. plz. i have visual c/c++ but dont know what the codes lines and errors mean..... lol plz. help me out...
(If this comment was disrespectful, please report it.)

 
1/10/2001 2:37:10 AMDustin Davis

Hey guys, i uploaded the new zip with the textures. Sorry but they are in 256 colors due to zip size =( but you will get the idea. The sky is supposed to be black. I will update it tommorow with a sky and some fog if ya like. Let me know. Thanks for all your posts.
(If this comment was disrespectful, please report it.)

 
1/10/2001 3:27:11 AMMouse

YES!! THIS WORKED! woo whoo! thanks man this is too cool.. best code i have seen in a looong time!
imma have fun with this =)
(If this comment was disrespectful, please report it.)

 
1/10/2001 3:32:54 AMAndrew Heinlein (Mouse)

ok if you want to see a working EXE go here:
http://www.theblackhand.net/mouse/OpenGL.zip

Make sure you unzip this the correct way and retain the directory structure.

enjoy!
(If this comment was disrespectful, please report it.)

 
1/10/2001 3:35:38 AM

well no wo whoo! for me!!!!!!!!!!!!!
i need a .exe i dont know any visual c++ plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzz...................... help.........woo whooooooooo
(If this comment was disrespectful, please report it.)

 
1/10/2001 3:42:28 AMASERB

http://www.theblackhand.net/mouse
/OpenGL.zip
got it....... Thsnk alot. about to download it.
(If this comment was disrespectful, please report it.)

 
1/10/2001 4:00:23 AMASERB

ok it works! but its black and white?
i downloaded the fix version that is posted here, that doesn't work.

i also download the .exe form blackhand.net it works but no textures?

i tryed to put the images my the .exe and i also tryed to placed the default folder for the picures and still no texture.. any help? ?

o one more question: is there a way you can make this:
-
when i walk in to a building i dont go into it and get lost? Can you make me stop walking after i hit the wall.

anyway this is one of the best programs i have seen of PSC.
(If this comment was disrespectful, please report it.)

 
1/10/2001 12:43:07 PMMouse

there is something really wierd with how these type of models work. When you download the ZIP make sure you extract the exe to:
c:\windows\desktop\
and the path of the BMPs and
(If this comment was disrespectful, please report it.)

 
1/10/2001 12:48:59 PMAndrew Heinlein (Mouse)

ops! scratch that!
ok to get the ZIP to work do this:
open it in WINZIP
extract everything to:
C:\windows\desktop\testaga\
that will get the models to work right.
(it has to be that exact path, or the program wont find the BMPs and it will be black and white)
im working on making this program load from its own resources and not use external resources so its a tad more portable.

this is a kick butt example though, thanks for sharing it with us =)
(If this comment was disrespectful, please report it.)

 
1/10/2001 4:29:57 PMBen Jacobs

Okay, I unziped it to c:\windows\desktop\testaga\ and it still just shows black and white. Can someone tell me where to change the path to the images?

Anyway, this code rocks, many lesser coders wouldn't have put this on an open source website. You rock!

(If this comment was disrespectful, please report it.)

 
1/10/2001 5:08:43 PMMouse

make sure the model/bitmaps are in:
C:\WINDOWS\Desktop\testaga\models
and the EXE is on the desktop.
it should work, i just tested it again
(If this comment was disrespectful, please report it.)

 
1/10/2001 5:10:17 PMAndrew Heinlein (Mouse)

i mean, make sure the EXE is in:
c:\windows\desktop\testaga\
(If this comment was disrespectful, please report it.)

 
1/10/2001 5:15:25 PMAndrew Heinlein (Mouse)

The reason why this is such a pain to set up is cause the .MS3d file is a project file from the MilkShape3d program. It's not a real modle like from half life. This is like opening a MSVC++ .DSW file. If the files are in the wrong place, you get errors. Im thinking of writing a program that will store the bitmaps in the .md3d internally. Then rewrite this code to handle that. I think that will make this a little more portable.

good luck!
(If this comment was disrespectful, please report it.)

 
1/10/2001 7:40:50 PMMouse

as a matter of fact, im doing that now.
so this will be the .MS3d model, but with the images stored within the .MS3d file, instead of just the paths. Maybe Dustin would like to work with me on making this into a newer model format?
either way, im going to go nuts with this.. i have always wanted to do this stuff =)
(If this comment was disrespectful, please report it.)

 
1/10/2001 10:08:54 PMASERB

ok i downloaded the .zip i extracted it to C:\windows\desktop\testaga\ the bitmaps are in C:\windows\desktop\testaga\models and the exe is in C:\windows\desktop\testaga and it still doesnt show the bitmaps?

(If this comment was disrespectful, please report it.)

 
1/11/2001 2:55:10 PMDustin Davis

I dunno what this testtga stuff is, all u need ta do is extract the 3d world folder to your desktop not testtga!
(If this comment was disrespectful, please report it.)

 
1/14/2001 2:39:12 PMPsyVision

Wicked Demo. It works for me. Um, maybe some collision detection next :)
(If this comment was disrespectful, please report it.)

 
1/20/2001 6:10:21 PMwolvenwraith

This is an EXCELLENT example, it worked for me just fine. If I understand this code well enough I could combine it with what I'm good at and make a pretty cool program. If I do this, you of course will get a lot of credit, I'm giving you an excellent vote.
(If this comment was disrespectful, please report it.)

 
1/24/2001 8:58:24 PMRichard Szalay

Alright, I'll be mailing this to the author anyway, but I'll post it here. To fix the problem with the textures loading, replace the function LoadGLTexture (in 3dSWorldMain.cpp) with this one (see below). It basically takes the filename off the path, and then re-allocates the path (ie. the project doesnt need to be in c:\windows\desktop\ or whatever).

I like though bud :) Nice work.

UPDATE: Ermm.. ok, I can't paste the function here, it makes my message too long.
(If this comment was disrespectful, please report it.)

 
3/30/2001 6:02:24 PMPyRoTeKNiC

Well done for putting such amazing code up for free! Thx! I'm having a little trouble downloading it, but from the shot it seems just like the HL engine. With any luck it might download before i fall asleep...
(If this comment was disrespectful, please report it.)

 
4/2/2001 11:51:17 PMSean

I am on Windows 2000 and there is no C:\windows\desktop there is only C:\Documents and Settings\Administrator\Desktop so this sample will not work on my computer. :(
(If this comment was disrespectful, please report it.)

 
7/3/2001 3:42:10 AMRaX

Sean, it's an obvious awnser. make a windows\desktop directory :/
(If this comment was disrespectful, please report it.)

 
7/11/2001 2:06:43 PMMiah

If you guys are having that "black and white" error, view the .msd or whatever file in there in text, you'll the see what directory this file looks for when trying to open those bitmaps! Hmmm, now i just need to make this program work faster, or maybe its just my 133Mhz computer!
(If this comment was disrespectful, please report it.)

 
8/14/2001 2:11:42 PMMike Mc

help!I was experimenting and want2 change the bitmaps but the program wont accept any different bitmaps besides the ones given.The new bitmap textures show up in MilkShape3d but when the program is compiled they are not there -just white!Whats going on?
(If this comment was disrespectful, please report it.)

 
9/12/2001 11:36:19 AMMikael

Why did everyone write 'C:\windows\desktop\testaga\' etc.?

It should be:
'C:\windows\desktop\3DWorld\'
then it works...
(If this comment was disrespectful, please report it.)

 
9/12/2001 11:36:52 AMMikael Nordfelth

(Please answer via e-mail)
(If this comment was disrespectful, please report it.)

 
11/21/2001 11:18:40 PMLord Tenchi

Ya know, if I didn't work next to Dustin every day, I'd have to think he was cool for putting this up...

DARN YOU DUSTIN!! Ya beat me to it!
heh heh
(If this comment was disrespectful, please report it.)

 
12/17/2001 2:32:50 PMthamuz

Thanks much for making this awesome code. Im using it as a 'self-tutorial' in OpenGL etc... I like it alot. 5 little planet thingies...
(If this comment was disrespectful, please report it.)

 
4/3/2002 4:10:00 AMElie

Request: More info on file stuff.ms3d
how to understand this binary file?
please reply at vipers58@hotmail.com
N.B:This file contains the bitmaps
location.
(If this comment was disrespectful, please report it.)

 
5/29/2002 10:39:02 AMMukade

EXELLENT!!
17 - MAN - KUWAIT
I WILL BE ABLE TO DO SO AFTER 2 YRS, AND TELL ME WHAT U EAT?? ;-/
(If this comment was disrespectful, please report it.)

 
6/7/2002 7:38:07 AMElie

I have added to the game's model a small animation (destruction of one of the buildings). I need to know how to activate it in the c++ code.
Please reply at vipers58@hotmail.com
(If this comment was disrespectful, please report it.)

 
6/9/2002 11:27:32 AMRICH

Hey,
This is excellent!
Great work :)
I'd be perfect with collision detection though, and also if you can't turn upside down (You can only look straight up or down, not do a 360 ;))
So great work =D
(If this comment was disrespectful, please report it.)

 
7/10/2002 11:15:23 AMJefff

I love it. Cool!
(If this comment was disrespectful, please report it.)

 
8/10/2002 9:18:57 PMM DeKrey

I've figured out this code and made an editor in VB. It works quite well, and makes it so that your files don't have to be in the proper directory as specified by the first comment. Unfortunately, I can't get it posted (I'm headed out for a week). Thank you to Dustin for posting this!

(If this comment was disrespectful, please report it.)

 
8/14/2002 10:05:09 AMx_darkdude_x

cool dude can you make it so it stops a a wall or a building plz
(If this comment was disrespectful, please report it.)

 
9/21/2002 3:15:07 AM

http://www.theblackhand.net/mouse
/OpenGL.zip doesnt work for me
does the file still exist?
(If this comment was disrespectful, please report it.)

 
11/14/2002 8:13:59 PMPaul Barron

Yes the file is no longer there :(... Email it to me and ill host it on my site.
(If this comment was disrespectful, please report it.)

 
11/24/2002 11:57:23 AM

I fixed it :)
Go into the MilkshapeMoel.cpp and then choose the loadModelData() Method. Go to the Part where the Textures are loaded.
Somewhere you will find:

strcpy( m_pMaterials[i].m_pTextureFilename, pMaterial->m_texture );

after this you just paste:
char dir[_MAX_PATH];
int t_char = '\\';
_getcwd( dir, _MAX_PATH );
strcat(dir,
(If this comment was disrespectful, please report it.)

 
11/24/2002 11:58:49 AM

char dir[_MAX_PATH];
int t_char = '\\';
_getcwd( dir, _MAX_PATH );
strcat(dir,"\\models");
char *dest = strrchr( m_pMaterials[i].m_pTextureFilename, t_char);
strcat(dir,dest);
strcpy(pMaterial->m_texture, dir);
strcpy(m_pMaterials[i].m_pTextureFilename,dir);

Recompile. Now it should search all BPM-Files in the models directory. If you like another one. It should be easy to change it.
==========================
contact: www.intercompu.de
(If this comment was disrespectful, please report it.)

 
11/26/2002 12:15:38 PM

i know c++, can u teach me how did you create the 3d world.. its kinda intresting...
(If this comment was disrespectful, please report it.)

 
1/13/2003 6:06:54 PMDark_Dude34

Hey code all ok but on your next one can you have collision on it it would help thanks

Great Code :>
(If this comment was disrespectful, please report it.)

 
1/27/2003 3:29:24 PMAndrei Krotkov

Nice.

I just wonder how you are going to determine collision detection. I tried something like this, but then I gave up and made it tilebased. Very good code.
(If this comment was disrespectful, please report it.)

 
3/26/2003 11:38:31 AM

Pls add something like this at line 212 in MilkshapeModel.cpp to provide textures in every directory:

int j,k=0,s;
for (k=0;ModelPath[k]!=0;k++) {m_pMaterials[i].m_pTextureFilename[k]=ModelPath[k];}
for (s=0;pMaterial->m_texture[s++]!=0;) {if (pMaterial->m_texture[s]=='\\') {j=s;}}
for (j=j;j++m_texture[j]);

whil e
you defined a
const char *ModelPath=
(If this comment was disrespectful, please report it.)

 
3/26/2003 11:40:12 AM

Pls add something like this at line 212 in MilkshapeModel.cpp to provide textures in every directory:

int j,k=0,s;
for (k=0;ModelPath[k]!=0;k++) {m_pMaterials[i].m_pTextureFilename[k]=ModelPath[k];}
for (s=0;pMaterial->m_texture[s++]!=0;) {if (pMaterial->m_texture[s]=='\\') {j=s;}}
for (j=j;j++m_texture[j]);

whil e
you defined a
const char *ModelPath="models\\";
somewhere :)
(If this comment was disrespectful, please report it.)

 
4/17/2003 5:00:24 AM

i'm crazy abt game developement and would like to see ur pgm run.But I lack the windows.h gl, &glu.h (some others also i think)....so kindly provide them also along with ur code.
also a .exe
(If this comment was disrespectful, please report it.)

 
4/24/2003 6:03:32 AM

Alot of this code comes from here ...http://nehe.gamedev.net ...if you want it to work in any directory, you should be able to move the bmp files into the same place the exe file is, actually i edited the stuff.ms3d file in milkshake 3d too and changed the location of the bmp files. Do check out nehe website some excellent work in there, this would be a much better eg if it had collosion detection.
(If this comment was disrespectful, please report it.)

 
6/23/2003 2:02:39 AM

I'm Begginer Proggramer.it was very nice
It was helpfull me learn C++
Thank's
(If this comment was disrespectful, please report it.)

 
7/6/2003 8:30:17 PM

get milkshape export model to ascii change all the files to ./models/insertname.bmp
(If this comment was disrespectful, please report it.)

 
8/7/2003 5:19:41 PMTi_fran

it work but it s all in black and blue-green like color
(If this comment was disrespectful, please report it.)

 
9/28/2003 2:24:05 AMWolf McCloud

Very nice. If you could add collisions it would be even better.
(If this comment was disrespectful, please report it.)

 
12/23/2003 12:25:15 AMZ Dog

I found out how you load the textures from a custom directory. HEre is where they are originally set to open from:

C:\WINDOWS\Desktop\3dWorld\models\

Yet if you open up the stuff.ms3d, and you find that text, you can change the path!!!

But i have a question, how do you create an ms3d file???
(If this comment was disrespectful, please report it.)

 
4/24/2004 4:13:58 AM

umm... could you include the classes you used with that becos im not sure if i have all of them :\
(If this comment was disrespectful, please report it.)

 
5/22/2004 1:41:27 PMSufyan Jabr

Man its really a great work and they deserve winning the contest, any its a bit slow i think its the graphics, but man it great

(If this comment was disrespectful, please report it.)

 
6/22/2004 3:57:56 PM

very good example!
(If this comment was disrespectful, please report it.)

 
12/13/2005 8:49:59 AMsajeev

Open it in winrar. click Extract to : c:\windows\desktop . Go to that folder and compile. You will get a good graphic
(If this comment was disrespectful, please report it.)

 
7/20/2006 6:34:46 AMGeoriege

I am trying to compile the project with visual studio 2005 , and i get the error : Cannot open include file: 'fstream.h': No such file or directory.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.