Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / Software 3D Graphics Engine Tutorial Source (JavidX) - AppGameKit v2 & Studio

Author
Message
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 17th Mar 2020 03:20 Edited at: 17th Mar 2020 03:24
For anyone looking to get into the Nuts & Bolts of 3D Graphics, then building a Software 3D Renderer is an excellent way to learn.
As with most things today, a lot of the fundamental ideas end up a bit of a Black Box because these are such common things that most Graphics APIs come with this stuff built-in...
I'd further argue that while there are typically a lot of Tutorials Online that go over what and the Algebraic Mathematics to do various things., converting Algebraic Terms into Working Code isn't always the easiest thing, especially for those who haven't actually done Higher Level Mathematics (which things like Quadratics, Matrices, etc.) are.

This is where I'd say JavidX' "Code it Yourself! 3D Graphics Engine" Tutorial Series comes in.
Because he walks you through how and why something is being done, typically with a cutaway to a Whiteboard to Visualise it.

Now in his tutorials he uses his Console Game Engine, which is a basic interface for Creating Graphics, Getting Input and Outputting Audio., but this is written in C/C++
I thought that it might be cool to convert all of his Tutorial Source (which is freely available) into an AppGameKit Compatible Format... so you can watch the tutorials, and see how you'd do some of the things he does in AppGameKit.

---------------------------

agkCommon.agc


AppGameKit Common Framework, will eventually echo all of the same features as the olcConsoleEngine ... so that you can use it identically as in JavidX's Tutorials.
Now I still don't know why after 21 Years, TheGameCreators BASIC doesn't have built-in True and False.
These however are predefined as AGK_TRUE and AGK_FALSE in the agkCommon.agc

Function OnCreate( )
// This is called only at Creation
EndFunction AGK_TRUE

Function OnUpdate( fElapsedTime As Float )
// This is called every Frame
EndFunction AGK_TRUE

These are not defined in agkCommon.agc because these are specifically for you to Override; and as AppGameKit doesn't have a "Virtual" (i.e. Placeholder) ... this does mean you have to make these yourself.

In order to Begin the Runtime you want to use the agc_Create( )
So a basic Hello World would be:



fElapsedTime is the time in milliseconds between each Update.
So if you want to have Updates based upon the Framerate, then just Multiply any "Per Frame" Update by the fElapsedTime and every Second that's how many Units said Object will have Transformed / Rotated / Scaled.

--------------------------------------------------------------------

3DGraphicsEngine_Part_1.agc / Part 1 - Triangles & Projection


This is the AppGameKit Version of Part 1 ... and here's the Video for it.



As a side note., I've included at the end a Cube Mesh Function (I'll be adding more primitives with each Part) but it isn't part of the Tutorial.
These will just be to see how to create such things in Code.

I hope you all enjoy. I will be posting the other 3 Parts over this week, so keep an eye out.
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 17th Mar 2020 16:50
Thanks Raven.... Very interesting..
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 19th Mar 2020 10:19
So as a quick preface here... my Fill Triangle Routines for some reason is a little "Janky" in AppGameKit and I've been scratching my head over why exactly.
It's good enough for now, and I'll try to fix it later.

3DGraphicsEngine_Part_2.agc / Part 2 - Normals, Culling and Object Files


This covers everything that's in the next part of the series



As noted I'll see about improving the Triangle Fill Routine to work better (hopefully by the next part)
And the Source will get cleaned up a bit with better comments, as I think it might be useful to know how (and why) I've changed certain aspects to work in AGK.

Now as a further note, the ObjectFile has been attached to the post and you'll have to manually set the path, because for some reason my AppGameKit Studio just doesn't like doing Relative Reads as it always claims the File doesn't Exist.
Now idea if that's an issue with how I'm trying to use it or what... just irritates the heck out of me though.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 26th Mar 2020 02:08
I'll get the next part up hopefully Monday... work has me doing an insane amount of extra hours that I wasn't expecting.
In the mean time, I did resolve the Triangle Rasterisation issue.



Add that to the DrawTriangle() Function after the Local Declarations., as it seems that AppGameKits' Integer > Float Rounding can be a bit "twitchy" ... so simply removing the Decimal without rounding resolves the issue.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 27th Mar 2020 22:21 Edited at: 27th Mar 2020 23:54
Nice I made a software renderer too back before I dived into shaders.
It defenately helped me in the process of understanding them.
I'm totaly nitpicking here, but those redundant calculations made me itchy somehow.
This:

To this:

There is more but the tidiness outweighs the performance I think.

Also the second part didn't work for me but I found your VertexCounter a bit slow so I just did this:

[Edit]
And you dont want to run the triangle filling if the vertices are on the same line:

[/Edit]
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 27th Mar 2020 23:40
The tutorial isn't mine... rather an AppGameKit Version of the C++ Code from the linked Tutorial Videos.
I'm not sure what I'll do afterwards.
Have a few ideas, but might keep with the "Retro" theme.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 27th Mar 2020 23:57 Edited at: 28th Mar 2020 00:00
I know, but you did a good and tidy job converting it.
I just having fun optimizing it here and there, don't mind me if you want ^^

But you should put everything into a package so it's more accesible for others if you want more feedback i guess.
Software 3D Renderer Demo with my changes

Attachments

Login to view attachments
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 1st Apr 2020 01:36


Alright so, this isn't strictly "Part 3" .... instead this is more a "I've run in to a bit of a road block"
That is to say that while this is working "Fine" with Low Triangle (Polygon) Counts., well it seems AppGameKit Arrays take a nose dive in performance the larger they are.

As a result, loading the "Teapot.obj" (which is only 6,300 ish Triangles) results in bringing things to single digit Frames Per Second...
Now I was doing some experiments... and the actual creation (i.e. resizing and sorting) is still just fine, and has very little impact on the framerate., at least on it's own.
As I actually took those away and just manually set the Array Size... same issue.

I'm going to experiment a bit more, but it might cause some issues going forward.
In any case I've posted the Refactored Code and added the Teapot.obj as an attachment.

Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 20th Apr 2020 20:21 Edited at: 20th Apr 2020 20:33
I do not help with splitting every 1000 pollygon in its own array?
To keep it simple?
I am used to hack agk to get wath i know

I have not seen you code but maybe splitting stuff in to there own arrays then to use sub sections in the same array?

edited…………......
Checked the code and that is some great work done there
could you put the teapot model here if i check your code ?

Login to post a reply

Server time is: 2024-03-29 11:45:25
Your offset time is: 2024-03-29 11:45:25