A simple 3D render method

AndT
Posts: 26
Joined: Aug 01, 2007 10:05

A simple 3D render method

Over 100 FPS (ca. 300-600) and highres ;)

Code: Select all

`' A simple 3D demo written by AndTtype xycor    x as double    y as doubleend typetype polygon    p1 as xycor    p2 as xycor    p3 as xycorend typedim as polygon poly(1 to 2)sub drawpolygon(byval p1 as xycor,byval p2 as xycor,byval p3 as xycor,byval col as uinteger)    line (p1.x,p1.y)-(p2.x,p2.y),col    line (p2.x,p2.y)-(p3.x,p3.y),col    line (p3.x,p3.y)-(p1.x,p1.y),colend sub'Main programmresx=1024resy=768screenres resx,resy,,,1dim as integer mode,mode2,mode3,mode4,mode5,mode6,mode7,mode8' FOR FPSVIEWDIM AS INTEGER frameDIM AS SINGLE t = TIMER DIM AS INTEGER FPS' Main loopdo' Drawdrawpolygon (Poly(1).p1,Poly(1).p2,Poly(1).p3,15) ' Polygon1drawpolygon (Poly(2).p1,Poly(1).p2,Poly(1).p3,15) ' Polygon2sleep 1,1 ' remove this to see the real FPS xD' Removedrawpolygon (Poly(1).p1,Poly(1).p2,Poly(1).p3,0) ' Polygon1drawpolygon (Poly(2).p1,Poly(1).p2,Poly(1).p3,0) ' Polygon2' Simple Animation Code ;)if poly(1).p1.x > resx then mode2 = 0if poly(1).p1.x < 1 then mode2 = 1if poly(1).p2.y > resy then mode3 = 0if poly(1).p2.y < 1 then mode3 = 1if poly(1).p2.x > resx then mode4 = 0if poly(1).p2.x < 1 then mode4 = 1if poly(1).p1.y > resy then mode5 = 0if poly(1).p1.y < 1 then mode5 = 1if poly(1).p3.x > resx then mode6 = 0if poly(1).p3.x < 1 then mode6 = 1if poly(1).p3.y > resy then mode7 = 0if poly(1).p3.y < 1 then mode7 = 1if poly(2).p1.x > resx then mode = 0if poly(2).p1.x < 1 then mode = 1if poly(2).p1.y > resy then mode8 = 0if poly(2).p1.y < 1 then mode8 = 1if mode = 1 then poly(2).p1.x + = 1 else poly(2).p1.x - = 1if mode2 = 1 then poly(1).p1.x + = 2 else poly(1).p1.x - = 2if mode3 = 1 then poly(1).p2.y + = 3 else poly(1).p2.y - = 3if mode4 = 1 then poly(1).p2.x + = 2 else poly(1).p2.x - = 2if mode5 = 1 then poly(1).p1.y + = 1 else poly(1).p1.y - = 1if mode6 = 1 then poly(1).p3.x + = 2 else poly(1).p3.x - = 3if mode7 = 1 then poly(1).p3.y + = 2 else poly(1).p3.y - = 2if mode8 = 1 then poly(2).p1.y + = 1 else poly(2).p1.y - = 1' FPSVIEWframe += 1  IF frame >= 50 THEN    cls    FPS = INT(frame / (TIMER - t))    t = TIMER    frame = 0    locate 2,2    print "FPS : ";FPS    end if    loop until inkey <> ""`
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:
It only compiles with -lang deprecated :P

Well not bad, but it doesn't really do a whole lot. Drawing wireframe is one thing. drawing shaded models is entirely different (due to the complications raised by HSR and other things - and if you want proper lighting, materials, and texturing - forget about it in real time.) Nice example, but in the end for real 3d OpenGL or DirectX are pretty much the best options.
elsairon
Posts: 207
Joined: Jul 02, 2005 14:51
Nice!

Add texture support for the poly's and non visible poly culling you're set ... :P
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:
That's not a very simple thing to do, besides as I said by the time he does that the FPS will plummet.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
I don't know why people insist on doing 3d in software anymore.

Welcome to 1993.
Mysoft
Posts: 778
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:
year 2057: "we need to make a new graphic card... but no one in the world remember how to program the 3D software for the graphic card..."

maybe this can be a reason... (the same with ASM), i guess in my opinion forget those things only will make a few BAD try to control people knowing those things that everyone else dont care to know... (welcome to matrix)...

ofcourse that is a Exaggeration, but in a scale of time... it's clearly true... (gladly we have books and... storage devices... but... this happened before)
counting_pine
Posts: 6219
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs
1000101 wrote:I don't know why people insist on doing 3d in software anymore.
There are people who like to mess around with ideas and algorithms, to get to know their way around basic concepts and build up their knowledge around them.
There are also people who prefer to maximise what they can accomplish, by using established ideas and methods. They're not as interested in "how does it work?", so much as "how can I use it?"
Both are perfectly acceptable schools of thought, but without the former, there wouldn't be the latter.
redcrab
Posts: 619
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:
Sorry but I do not see anything in 3D ...
Just bouncing tied lines ...

Did I miss something ???
dabooda
Posts: 112
Joined: Aug 28, 2006 21:35
Location: Texas
Contact:
You didn't miss anything, there is no 3-d there. Just some tied lines with pong bouncing ends. There is not rotation, scale or rather perspective here. This is not 3-d, just an optical illusion if even that. The only true thing shown here is how to draw a triangle. I was wondering why your DrawPolygon() routine isn't set up where you simply pass a pointer to your polygon instead of feeding all 3 corners?

Code: Select all

`'DrawPolygon SubSub drawpolygon( poly as polygon ptr, col as UInteger)     Line (poly->p1.x, poly->p1.y)-(poly->p2.x, poly->p2.y), col     Line (poly->p2.x, poly->p2.y)-(poly->p3.x, poly->p3.y), col     Line (poly->p3.x, poly->p3.y)-(poly->p1.x, poly->p1.y), colEnd Sub'To call it simply do thisdrawpolygon @poly(0), 15drawpolygon @poly(1), 15`

You could probably even set it up to pass the polygon by reference, anything is better than feeding it each corner. That kind of defeats the purpose of setting it up as a type.

DaBooda out...
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:
It is what it is. I don't understand the harsh criticism. This wasn't advertised as a new 3D rendering system. Just a very simple raster gfx example. Jeez!

Thanks for the submission AndT. I'm sure some will find it intersting.

-Vince
Dr_D
Posts: 2398
Joined: May 27, 2005 4:59
Contact:
I also think that doing 3d in software mode is excellent practice and keeps your math skills sharp. Also, it's just plain fun. I think most people that do neat things with hardware accelerated libraries, like OpenGL or DirectX, have some background in software rendering.

Speaking of software...
Now for the obligatory FBEXT reference! :D We've recently added a flat shaded triangle primitive rendering function, and I made a demo using it. You can hit space to toggle vsync... and that's pretty much it.

http://dave-stanley.dyndns.org/programs/fbext_demo1.rar
dabooda
Posts: 112
Joined: Aug 28, 2006 21:35
Location: Texas
Contact:
'A Simple 3D Render Method' implies that it is 3D, which it is not. That isn't criticism but rather pointing out a fact. It simply needs to be renamed.

I also agree doing software 3d is essential for anyone wishing to program 3d with hardware. Not to mention its just fun. Who cares if it is nowhere near today's standards. I'm more impressed with someone who renders a shaded polygon with code, than simply feeding a description to HAL.

DaBooda out...
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:
hello Dr_D
nice example but why are the fps so low?

Joshy
DaveUnit
Posts: 239
Joined: Apr 20, 2006 15:47
Location: Central MA
Contact:
awesome example Dr_D. FB Ext is really cool.
dabooda
Posts: 112
Joined: Aug 28, 2006 21:35
Location: Texas
Contact:
I was being critical earlier and I apologize, don't want to come off like some around here. It was counter productive and again I apologize.

If you are interested in software 3d I can recommend a great book: Flights of Fantasy by Christopher Lampton. Its main concept is the building of a flight simulator and the code snippets are in c. But it is an excellent source and teaches you about 3d rendering from the ground up. Good Stuff.

DaBooda out...