Important alert: (current site time 7/16/2013 3:36:54 AM EDT)
 

winzip icon

REAL TIME TEXTURE MAPPED 3D IN PURE VB CODE!!!

Email
Submitted on: 7/26/2000 4:31:24 PM
By: Simon Price  
Level: Intermediate
User Rating: By 46 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 33737
author picture
(About the author)
 
     The most successful program of all time on Planet Source Code is RJSoft's textured 3D cube, it has had 176 excellent votes for it including my vote. People obviously were impressed by real time 3D texture mapping - it's the best graphics you can get. RJSoft's program produced these cool graphics using DirectX 7, it is a very well written program. But what if I were to tell you that it is possible to do this WITHOUT DIRECTX?! Yep, this is texture mapped 3D in PURE VB CODE! It doesn't use DirectX, no OpenGL, no DLL's, just label and image controls, and NO DRAWING API's - not even Windows ones. It doesn't use ANY API's in the main rendering loop!!! Yet it still has several rendering modes to choose from and runs at the following frame rates (on my 400Mhz PC). Corners Only - 135 FPS WireFrame - 120 FPS Outline - 110 FPS Flat Colour Polygons - 40 FPS Single Texture Mapped Polygons - 20 FPS Multiple Texture Mapped Polygons - 11 FPS That's FAST! I don't promise the graphics to be as good as RJSoft's program, but I do promise they're done in pure VB code. You can spin the cube on the x,y and z axis and stop it too. You can change the rendering mode by pressing the spacebar. So, 176 of you voted for RJSoft's program using DirectX, I hope you think this deserves a vote too. NOTE - for best performance run the compiled .exe (supplied) and close all other programs. This doubles the frame rates!
 
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.
  3. Scan the source code with Minnow's Project Scanner

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 30 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 Intermediate 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

7/26/2000 4:36:16 PMSimon Price

To RJSoft

I hope you didn't mind me refering to your program, but I had to since it was your program that made me write my one - I thought I'd copy whatever was the best program on PSC and it was your's! Ofcourse, I like to do things without DirectX so the program changed dramatically, if you look at the source code I'm sure you'll see that I haven't copied a word of your code. NEway, thanks 4 your prog, it inspired mine!
(If this comment was disrespectful, please report it.)

 
7/27/2000 9:08:27 AMErik Forbes

This is pretty sweet. :) Usually, I don't download Rotating Cube examples, but I thought I'd check it out anyway.

If you can find a more constructive way to use this knowledge, I'd be more inclined to vote for it... Perhaps do what one other author did and make a 3D Landscape Engine.

Just thought I'd add my 2 cents worth. :) Good job, hehe :)

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

 
7/30/2000 1:34:36 PMRJ Soft of West Tennessee

No, I don't mind at all. I have looked at your code and ran your program. While the idea is ok, the results are not as good as using DirectX. DirectX was created to make graphics fast and easier to use then direct code. Trying to do this in pure VB is ok but not very practical. You did a fine job on this example so dont take this in bad light. Your example shows you can work with graphics without use 3rd party dlls.
(If this comment was disrespectful, please report it.)

 
7/30/2000 1:54:40 PMSimon Price

You're right, it's a bit dumb to make 3D stuff in VB. But if I ever get that C++ and assembler stuff in my head it might be a bit more useful...
(If this comment was disrespectful, please report it.)

 
8/5/2000 7:43:09 AMNick Thompson

Well done - I've been trying to work out how to do this for years, and now after looking at your code... I'm still trying to workout how the texture mapping thingy works. Excellant code however it works
(If this comment was disrespectful, please report it.)

 
8/12/2000 8:02:31 AMrino_2

Very good although it would be much better using DX.
(If this comment was disrespectful, please report it.)

 
8/12/2000 11:18:26 AMMarc Burgess

Wow, great, and stuff... Your coming up with alot of decent stuff, but can't use use that giant brain of yours to come up with a full game, rather than a spinny cube thing. From what i've seen, you should be able to do more than this, even if it means losing textures or somthing.. And what happened to the VBDoom game? If you put monsters on it, I would like to see it. And anyway, I don't see how you can call it VBDoom, when it is nothing like Doom, and everything like Wolvenstine. You don't see me calling my tank game VB Unreal Tornement do you?
(If this comment was disrespectful, please report it.)

 
8/12/2000 11:26:38 AMMarc Burgess

Hey, don't get my wrong, I like all your stuff, but you gotta admiit, a game would be better than a spinny cube. And keep up coding in VB, its the best language in the WORLD!! Thats why 90% of planet source code in for VB!! After all, last year, there was about one 3D example on PSC, now there are loads, with Texture maps, full games, and DriectX - give it another 12 months, and people will be writing 3d games in VB and selling them on the open market. Every thing but VB s'ucks ass!
(If this comment was disrespectful, please report it.)

 
9/24/2000 5:16:02 AMMichael L. Barker

Nice job! I'd vote but I hate demos that nag me.
(If this comment was disrespectful, please report it.)

 
9/24/2000 5:26:01 AMRichard Hayden

It runs VERY fast on my 950MHz.

Corners Only: 400 fps.
Wire Frame: 351 fps.
Outline: 356 fps.
Flat Colour Filled Polygons: 170 fps.
Affine Single Texture Mapped Polygons: 50 fps.
Affine Multiple Texture Mapped Polygons:
32 fps.

That IS fast!

Well done on another excellent project!

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

 
9/24/2000 11:21:13 AMAllen Clark Copeland Jr.

I don't know if this has happened to other people, but I'm running windows 2000, and when I ran your example, I got a nasty surprise. The entire cube was tilted on its side, I'm not sure if it's supposed to do that, or if it's something to do with my computer's configuration in general.
(I have a 500mhz computer, and I got only 32fps with corners only, which was tilted as well...)
(If this comment was disrespectful, please report it.)

 
9/24/2000 12:44:56 PMThe REAL SESoftware

To Erik Forbes (the second feedbacker),
I hate to break it to you, bro, but Simon IS the author of the 3D Landscape Generator. Just thought I'd point and laugh. No harm meant.
(If this comment was disrespectful, please report it.)

 
9/24/2000 12:48:46 PMThe REAL SESoftware

§hit Simon... Are you ever going to stop creating kick a§§ programs! WHO'S THE MAN?!?!?!
(If this comment was disrespectful, please report it.)

 
10/12/2000 6:00:34 PMBill Soo

I liked your code quite a bit. I was toying with ways to do this for some time now. However, in dissecting your code, I came across 2 errors.

1) After awhile, the code can lock up in an infinite loop in the AffineScanPolyEdge routine. It's caused by the program looking for x = x2 or y = y2 when it should be something like x >= y2, since you are using variants instead of bytes.

Which brings up
2) you are using variants instead of bytes in two of your most code intensive routines. The statement
dim x,y,z,i as byte
actually declares x,y,z as variants and only i as a byte.

After redeclaring your variables, I went from 11fps to 17fps.
(If this comment was disrespectful, please report it.)

 
4/22/2002 8:59:46 AMVirtLink Software Productions

Looks great, but it can be a bitty faster when you remove the 'setpixel' statement. Looks the same, but draws also negative.
(If this comment was disrespectful, please report it.)

 
7/4/2002 11:31:38 AMArtist

Tutorial is great man, if you need an artist, contact me (alas@EUnet.yu), I wanna help for skeletonX, but I can't reach your mail... <:-(
(If this comment was disrespectful, please report it.)

 
8/3/2004 9:44:11 AMKRADLE OF FILTH

Use FillMemory (byte set at 0) to clear the array fast.
(If this comment was disrespectful, please report it.)

 
8/16/2004 1:40:15 AMMichael Vainshtein

BEAUTIFUL!!!
gr8, nice job!
maybe make the cube rotate according to mouse movments - that would be even cooler!

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

 
3/4/2007 4:30:29 AMRyan27

Very nice code! How would you make it so you can create a polygon or a square using a mouse? Maybe a starter for a mapping/model program? Email me the answer please at termx261975@yahoo.com Thanks! :) 5 from me
(If this comment was disrespectful, please report it.)

 
11/30/2009 9:11:54 AMSaed abumokh

that isnt the correct perspective
(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.