forums

TNT Basic Forums > Beyond Basic
Fast Polygon Drawing
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-30-2002 23:21

Posted by:
Douglas O'Brien

Find more posts by Douglas O'Brien

This mainly applies to making fast 3D engines, in which case TNT Basic would probably not be the choice, but I want to know a fast way to draw polygons on the screen and have them properly overlap. The obvious method is to draw the ones in back first and work your way up. This is bad because some pixels may get drawn over many many times.

I came up with some ways, one being storing "jumps" into another "screen" to skip huge clusters of pixels at a time, however it has drawbacks. Another is to jump without needing another "screen" but it has drawbacks. Breaking up polygons into many small polygons based on the ones drawn over it sucks. And saving the endpoints of the rows of polygons and comparing them will be too slow too.

Is there a fast way to draw polygons to the screen?

01-31-2002 10:27

Posted by:
Mark Tully

Find more posts by Mark Tully

Polygons sorting

Hi Douglas,

What you're talking about here is depth sorting, you want polygons that are futher into the screen to be obscured by polygons that are further forward.

Drawing the ones that are furtherst back first, and then drawing subsequent ones over them, is called the painter's method, and although it sounds inefficient is actually quite popular.

Another popular method is the z-buffer. This method involves recording the colour and depth (z-value) of each pixel on the screen, and only overwriting pixels that are further back with pixels that are closer to the screen. This is able to handle intersecting polygons where half is in front of a polygon and half is behind.

There are other methods, but searching for info on these two on the internet should get you started.

As you say, TNT Basic isn't the best language for doing 3D in, but if you pioneer it, we can improve things on the TNT Basic side as needed.

Good luck!

Mark

02-15-2002 23:29

Posted by:
Douglas O'Brien

Find more posts by Douglas O'Brien

3D Program

As you say, TNT Basic isn't the best language for doing 3D in, but if you pioneer it, we can improve things on the TNT Basic side as needed.
=====================================
Well, I made a little 3D program to "pioneer". It is in a 640x480 screen. One version uses just wire frame (so you can see through things) and it gets over 600 FPS on my 600 MHZ iBook for a quite a few lines all on the screen.

The, I made a version that uses actual polygons (so you can't see through things). For 16 polygons on the screen it gets about 30 FPS. Each polygon makes a pretty big hit on the speed. And, it needs a better back to front sorting method, and it needs polygon clipping when they go off the screen (as opposed to not drawing a polygon if any of the vertexs are off the screen). This will slow it down some.....but the main thing is color. All my polygons are white, the color of the background. So I never erase the screen, just the edges of the polygons. If they were to have color, then I would have to clear the screen with a Paint Canvas command which would knock the FPS down to about 20 for 16 polygons.

As for possible improvements on the TNT Basic side of things. A built in polygon command would be nice. To draw a polygon requires too much code in TNT and a premade low level routine would really speed things up.


Also-TNT would be fast enough for a raycaster. Probably not one that casts actuall rays(those are slow) but one that uses semi-polygon walls. I also came up with a little routine I call "jump drawing" that works great for something like this. It draws walls from back to front, and stores jumps in an array and skips thousands and thousands of pixels that are known to be overlaped when it gets to the back walls.

However, texture mapping would be really slow since it would have to be done with TNT code. If you added the quickdraw copyrect command, it scales for you then each colum of pixels on the wall could call copyrect to scale that colom. However, the are 640 colums in a standard game screen. Thats 640 small copyrects. It would still probably be fast enough though. It would go even faster if there were a command to actomatically warp a square picture to a distorted quadrilateral, however, this wouldn't be a very used command so don't bother. But a polygon drawing command would be nice!


04-02-2002 13:09

Posted by:
ERaZer

Find more posts by ERaZer

Polygon

I think there is a built in polygon drawing method, check again.

10-11-2002 07:27

Posted by:
Peter Gosling

Find more posts by Peter Gosling

Do you think that TNT could turn into a 3D programming language? Then some really awesome games could come out. Not the 2d is bad :)

10-11-2002 08:47

Posted by:
Mark Tully

Find more posts by Mark Tully

3D

It remains a long term goal for us, but it's not going to appear in the immediate future as it relies on several improvements that are yet to come, such as > 16Mb limit on resources and a faster interpreter capable of crunching all the maths for the 3D physics.

Cheers,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.