# Xah's Edu Corner: Introduction to 3D Graphics Programing

Discussion in 'Perl Misc' started by Xah Lee, Dec 23, 2006.

1. ### Xah LeeGuest

Of Interest:

Introduction to 3D Graphics Programing
http://xahlee.org/3d/index.html

Currently, this introduction introduces you to the graphics format of
Mathematica, and two Java Applet utilities that allows you to view them
with live rotation in a web browser. Also, it includes a introductory
tutorial to POV-Ray.

Once you understand any one of these pages, you can use your favorite
programing language to start doing 3D Graphics Programing.

In the coming months, i will also introduce the .obj format that are
used by many geometric modeling programs. And, a tutorial on how to use
Python (or Perl, lisp) to do 3D Graphics programing, by setting up
functions that spits out any of 3D-Geometry Formats (such as
Mathematica Graphics or POV-Ray or .inc).

These are the imminent plans for the coming weeks. Other potential
subjects are introduction or tutorials on various utilities or
programing lang libraries that does conversion between different 3D
graphics formats, dedicated tutorial on how to generate mathematical
surfaces, more elaborate study on POV-Ray's abilities and sample cases,
etc.

The focus of these pages, will be 3D-Graphics programing with the goal
of Algorithmic Mathematical Art.
(see
http://xahlee.org/Periodic_dosage_dir/t1/20040113_cmaci_larcu.html )

In particular, we focus on creating geometric objects and their
arrangement that are esthetic in a mathematical way. (for example,
regular tilings in 3D, nested structures in 3D, symmetric structures in
3D, elaborate 3D maze tunnels, beehive sculpting, regular polyhedrons
and their decorations, projection and slices of higher dimensional
symmetries, 3D-manifolds ... etc.) This mathematical esthetic is
opposed to, for example, rendering techniques or technologies (e.g.
fogs, sceneries, fast algorithms...etc) that are quite common in
computer graphics literatures.

Xah

âˆ‘ http://xahlee.org/

Xah Lee, Dec 23, 2006

2. ### Boris BorcicGuest

Xah Lee wrote:
> Of Interest:

to which of comp.lang.perl.misc, comp.lang.python, comp.lang.lisp,
comp.lang.java.programmer, comp.lang.functional ?

Boris Borcic, Dec 23, 2006

3. ### Jon HarropGuest

Xah Lee wrote:
> Introduction to 3D Graphics Programing
> http://xahlee.org/3d/index.html

You will probably find it more rewarding to use a more modern graphics
system, such as OpenGL or DirectX, with a suitable programming language
rather than Mathematica's. I would recommend any of OCaml, F#, Haskell,
Lisp, Scheme, Python or Ruby for graphics, you can do much more
sophisticated, animated, real time visualisations than you can with
Mathematica's primitives.

There are lots of great web pages out there. I've written some 2D and 3D
graphics examples in OCaml:

http://www.ffconsultancy.com/products/ocaml_for_scientists/visualisation
http://www.ffconsultancy.com/free/ray_tracer
http://www.ffconsultancy.com/free/fractal
http://www.ffconsultancy.com/free/maze

and more recently F#:

http://www.ffconsultancy.com/dotnet/fsharp

I was very impressed with the tutorial videos on VPython at ShowMeDo:

http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries

For an introduction to OpenGL, look no further than the NeHe tutorials at
GameDev:

http://nehe.gamedev.net

One of our future products at FF Consultancy is a suite of extensions for
the F# interactive mode that allows you to visualise 2D and 3D graphics in
real time with simplicity rivalling Mathematica but the sophistication and
performance of DirectX, whilst also having the power of the F# programming
language and .NET to analyse your data.

--
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet

Jon Harrop, Dec 23, 2006
4. ### Jürgen ExnerGuest

Boris Borcic wrote:
> Xah Lee wrote:
>> Of Interest:

>
> to which of comp.lang.perl.misc, comp.lang.python, comp.lang.lisp,
> comp.lang.java.programmer, comp.lang.functional ?

You must be new. Otherwise you would be familiar with this troll already.

jue

Jürgen Exner, Dec 23, 2006
5. ### Xah LeeGuest

Dear Jon Harrop,

I don't know OpenGL, but i think it is a low-level crap, and have done
the industry huge irreparable damage the same way unix has.

This wikipedia excerpt from
http://en.wikipedia.org/wiki/QuickDraw_3D
summarize my sentiment:

Â«Most 3D toolkits concentrate on the lowest levels of the 3D rendering
pipeline...

For instance, the OpenGL system consists primarily of a system for
describing geometry in various ways...

Higher-level concepts of the 3D world are generally not included in
low-level libraries...

To add to the problems, OpenGL was not truly low-level..
Â»

Note this:

Â«
TODAY THERE REMAINS NO STANDARD HIGH-LEVEL API FOR 3D GRAPHICS. Several
attempts have been made, including OpenGL++ and the SGI/Microsoft
Fahrenheit graphics API, but none of these have made it to production.
Â»

----------

As a practical example of its low-level problem, i looked at your basic
OpenGL tutorial, the minimal program
(http://www.ffconsultancy.com/products/ocaml_for_scientists/visualisation/):

let () =
let argv' = Glut.init Sys.argv in
ignore (Glut.createWindow ~title:"OpenGL Demo");
GlClear.color (0.1, 0.3, 0.1);
Glut.displayFunc ~cbfun () -> GlClear.clear [ `color ]; Gl.flush
());
Glut.mainLoop ()

Immediately, a extremely intelligent alien who understand advanced
programing and geometry in 3D and higher dimensions, but who is not
familiar with OpenGL per se, would be facing 6 lines, almost all of it
are irrelevant to geometry or the mathematics of programing,
but are extraneous concepts created by the system itself . (the
exceptions are the â€œcolorâ€, and â€œclearâ€)

This is in contrast to the Mathematica system or its graphics. For
example:
http://xahlee.org/3d/mma.html e.g.

Graphics3D[{
Cuboid[{0, 0, 0}],
Point[{1.5, 1.5,0}],
Polygon[{{2, 2, 1}, {2, 1, 1}, {1, 2, 1}}]
}]

Even if you don't know nothing about Mathematica or never coded a
single line of 3d graphics application, the lines above are all very
meaningful, as they are inalienable concepts of geometry, not something
extraneous as most imperative languages or systems or unix forces upon
its users.

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

Note that the above sentiment about OpenGL, is just my sentiment on the
overall situation of graphics programing. (and in general the low-level
garbage situation applies to almost all imperative languages and vast
majority of protocols in the industry.) I don't particular know OpenGL
as a low-level graphic system is a good one or not. (but it is probably
correct to assume that Microsoft's Direct3D is far more better designed
system at the same level)

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

Regarding VisualPython... i saw a demo in 2002 by a professor
friend. I think it is good. Though, why is its licensing not GPL or
otherwise Open Source? That's kinda odd since Pyhton is.

----

What i'm looking for, is a system that allows one to easily to graphics
programing. By graphics programing, i mean 3d geometric shapes
manipulation, as opposed to rendering or implementing CAD systems or
how to write photoshop filters or the science of realistic rendering
etc as most people are thinking of when hearing the term computer
graphics programing.

So far as i know, Mathematica is the platform that allows one to do
graphics programing. But, i think Flash probably is another platform
that does it. And i think VisualPython is also.

I'm interested in other platforms that allows one to do this.

Xah

âˆ‘ http://xahlee.org/

Jon Harrop wrote:
> Xah Lee wrote:
> > Introduction to 3D Graphics Programing
> > http://xahlee.org/3d/index.html

>
> You will probably find it more rewarding to use a more modern graphics
> system, such as OpenGL or DirectX, with a suitable programming language
> rather than Mathematica's. I would recommend any of OCaml, F#, Haskell,
> Lisp, Scheme, Python or Ruby for graphics, you can do much more
> sophisticated, animated, real time visualisations than you can with
> Mathematica's primitives.
>
> There are lots of great web pages out there. I've written some 2D and 3D
> graphics examples in OCaml:
>
> http://www.ffconsultancy.com/products/ocaml_for_scientists/visualisation
> http://www.ffconsultancy.com/free/ray_tracer
> http://www.ffconsultancy.com/free/fractal
> http://www.ffconsultancy.com/free/maze
>
> and more recently F#:
>
> http://www.ffconsultancy.com/dotnet/fsharp
>
> I was very impressed with the tutorial videos on VPython at ShowMeDo:
>
> http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries
>
> For an introduction to OpenGL, look no further than the NeHe tutorials at
> GameDev:
>
> http://nehe.gamedev.net
>
> One of our future products at FF Consultancy is a suite of extensions for
> the F# interactive mode that allows you to visualise 2D and 3D graphics in
> real time with simplicity rivalling Mathematica but the sophistication and
> performance of DirectX, whilst also having the power of the F# programming
> language and .NET to analyse your data.
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy
> Objective CAML for Scientists
> http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet

Xah Lee, Dec 27, 2006
6. ### RaffGuest

Xah Lee wrote:
> Dear Jon Harrop,
>
> Thanks for the informative reply.
>
> I don't know OpenGL, but i think it is a low-level crap, and have done
> the industry huge irreparable damage the same way unix has.

OpenGL is low level, that's right, but it is not crap. OpenGL is
hardware independent, and is a true multiplatform standard. The
difference between OpenGL and higher level libraries, like OpenInventor,
it is similar to the difference between a low-level programming language
like C and a higher level object-oriented language, IMHO.

> I don't particular know OpenGL
> as a low-level graphic system is a good one or not. (but it is probably
> correct to assume that Microsoft's Direct3D is far more better designed
> system at the same level)
>

Direct3D it is lower level than OpenGL, and usually needs more
instructions than OpenGL to do the same things.

Raff, Dec 27, 2006
7. ### Ravi TejaGuest

Xah Lee wrote:

> Regarding VisualPython... i saw a demo in 2002 by a professor
> friend. I think it is good. Though, why is its licensing not GPL or
> otherwise Open Source? That's kinda odd since Pyhton is.

You are confusing VPython with Activestate's Visual Python IDE plugin
for Visual Studio.
>From VPython's home page in very bold font - "VPython is free and

open-source"
http://www.vpython.org/

Ravi Teja, Dec 27, 2006
8. ### Keith KellerGuest

["Followup-To:" header set, but it's best not to followup at all.]

On 2006-12-27, Raff <> wrote:
> Xah Lee wrote:

>> I don't know OpenGL, but i think it is a low-level crap, and have done

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> the industry huge irreparable damage the same way unix has.

>
> OpenGL is low level, that's right, but it is not crap.

Whether it is or not, Xah doesn't know and doesn't care, as he is
a troll (and anyone who would say "I don't know X but it's crap" is
definitely either clueless or trolling). Please don't pay attention
to his rants.

--keith

--
-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

Keith Keller, Dec 27, 2006
9. ### Xah LeeGuest

Thanks for correction.

This is superb! I'll be looking into vpython!

Xah

Ravi Teja wrote:
> Xah Lee wrote:
>
> > Regarding VisualPython... i saw a demo in 2002 by a professor
> > friend. I think it is good. Though, why is its licensing not GPL or
> > otherwise Open Source? That's kinda odd since Pyhton is.

>
> You are confusing VPython with Activestate's Visual Python IDE plugin
> for Visual Studio.
> >From VPython's home page in very bold font - "VPython is free and

> open-source"
> http://www.vpython.org/

Xah Lee, Dec 27, 2006
10. ### Guest

Xah Lee wrote:
>
> I read it wrong before.
> Thanks for correction.
>
> This is superb! I'll be looking into vpython!
>
> Xah

Of course it does what it does by resort to OpenGL and C++, so is part
of the problem

I am looking forward to your tutorial efforts, and hoping those efforts
can be accessed without exposure to too much polemics. Though if that

BTW, VPython is most of the way through a 4.xxx release which provides
some nice additional functionality to the 3.xx series core - like
transparency and texturing. Problem being the the lead developer has
graduated and moved on, and the NSF funding that had supported the
effort has run out.

And the core folks around the project are either science educators or
Python folks - there is little C++ expertise currently involved with
the project.

The project is looking for help.

Anyone willing to jump in should perhaps reply here or at:

Art

, Jan 8, 2007
11. ### hgGuest

Xah Lee wrote:

> I don't know OpenGL, but i think it is a low-level crap, and have done
> the industry huge irreparable damage the same way unix has.

So you _are_ psychic ! is the end of the world be in 2007 ?

hg, Jan 9, 2007
12. ### John ErsatznomGuest

wrote:
> And the core folks around the project are either science educators or
> Python folks - there is little C++ expertise currently involved with
> the project.
>
> The project is looking for help.
>
> Anyone willing to jump in should perhaps reply here or at:

I see lots of mentions of C++ and Python, but not Java, so suggesting
that anyone reply "here" (i.e. comp.lang.java.programmer) seems
questionable to me.

And what the hell is wrong with my goddam newsserver? Again it
complained that a header was missing (which either should have been
the message was a duplicate (it was a duplicate only if the previous try

I'm thinking of ditching aioe. Anyone know of any other public, free
newsservers that permit posting as well as reading? A whole lot of Web
research has failed to turn up any besides aioe. Mind you, I found a lot
of high quality free ones that permit reading only (some with binaries!
not that I need 'em) and at least one that calls itself "free" and says
it permits posting but actually charges an "account setup fee" -- where
are truth in advertising laws when you need them? "Free" doesn't mean
"No monthly payments" or "No recurring payments", it means FREE, as in
NO PAYMENTS AT ALL, MORONS ...

John Ersatznom, Jan 10, 2007
13. ### Xah LeeGuest

Xah Lee wrote in 2006-12-22:
> Of Interest:
>
> Introduction to 3D Graphics Programing
> http://xahlee.org/3d/index.html

Folks, i have expanded my tutorial to several pages in the past nearly
two months, and thank you very much for those who have given
encouragement.

I had plans to write pages that actually contained Python or Perl and
elisp code to demonstrate the mingled use of common languages with
POV-RAY and other tools for doing algorithmic mathematical art...

However, i'm posting now for one in-credible discovery that amazed me,
and believe it is a revolutionary both with respect to technology, as
well as its social impact.

Following is my brief introduction. The web version is at:
Introduction to Second Life
http://xahlee.org/sl/sl.html

-------

Introduction to Second Life

Xah Lee, 2007-01-09

above: A screenshot of a location in Second Life.

This place is called â€œThe Futureâ€, it is a place built by Henry
Segerman â†— built.

Second Life is a online virtual world with 2 million accounts as of
2006-12, and reportedly 10 thousand users logged in at any moment.
Basically, you operate a software that is a 3D world much like 3D
games, but everything in the â€œgameâ€ is built by users, and you can
interact with other users, including buying and selling virtual land
with real money. What people do inside Second Life is entirely up to
them (as in real life). And, as it happens, what people do mostly in
Second Life are pretty much what people do in real life. The major
activities are: sex, shopping, socializing, dancing.

My mathematician friend Henry Segerman introduced me to 2nd life. (also
because it appeared in Time Mag in 2006-12.) Henry has a 2nd life page
that contains many math objects made in Second Life:
http://www.stanford.edu/~segerman/2ndlife.html.

Part of my interest in Second Life is to build geometric models. (See
Introduction to 3D Graphics Programing) I have for the past couple
years sought for a software platform/system where i can build 3D
objects, with abilities to do interactive adjustment (such as moving a
slide to change a surface's parameter), dynamic rotation (viewing from
different angles), animations (such as morphing that shows geometric
processes), and most of all, walk-thru in it as if it is a building.

As far as my experiences goes, no software platform for 3D graphics are
close to the ideal of what i need to do. They lack one feature or the
other, or otherwise requires the programer to be a specialist with
years of dedication in learning the tool. For example, Mathematicaâ†—
has great collection of math functions but no dynamic graphics.
POV-RAYâ†— and 3D-modelers like AutoCADâ†— can do great in building 3D
objects but they are not designed for interactivity, animations, or
walk-thru. Java the programming languageâ†— allows one to write applets
that does rotation and interactive manipulation but programing in Java
is extremely unnecessarily complex and yet it is still not possible to
do walk-thrus. The one class of platform that does all these, is 3D
game engines. But alas, they take a dedicated game programing
specialist to be able to use it. Second Life changed all this.

(Note: Just for completness, my requirement for a 3D-graphics
programing software system is this: â€¢ easy to use for average
programers or scientists. â€¢ Easy to build geometry models, such as
basic shapes like spheres and blocks, as well as surfaces or meshes of
triangles. â€¢ designed for interactivity. That is, the programer can
easily build buttons and sliders that changes parameters and have the
object reflect these changes visually right away. â€¢ the user can
easily change viewing angles or rotate the object. â€¢ The programer
can easily do animations. For example, morph a sphere into a cube, or a
bunch of spheres flying in space as a swarm of flies. â€¢ The ability
to do walk-thru (or fly-thru). For example, if i build a fancy 3D-maze
or architecture, i should be able to â€” say â€” become a ant, and walk
inside the object, so as to view the object from inside and as well as
getting the real experience of perceiving such a building. (Before my
discover of Second Life, the platform that i was considering nearly
ideal and preparing to learn, are VPythonâ†— and Macromedia Flashâ†— (i
do still plan to learn these technologies) ))

Second Life is not just the answer to my mathematical fantasies, but
because of its Real-World nature, being run and build by real people,
and with scarily real money market of the virtual dollars it uses, is
nothing but a technological revolution with great social impact. It is
essentially the virtual-3D-world-wide-web dream of VRMLâ†— envisioned
around 1995.

Anshe Chungâ†— is famouly known for being the first to become a (real
world) millionaire by selling entirely virtual items and virtual
services inside Second Life.

For a encyclopedic introduction, see: Second Lifeâ†—

Here are some articles about Second Life. (note that there are a lot
linked at the bottom of the Wikipedia article.)

* Time Mag: â€œMy So-Called Second Lifeâ€, By Joel Stein,
20061216.â†—
* businessWeek online: INSIDE INNOVATION â€” IN SIDE. Second Life
Lessons. By Reena Jana and Aili McConnon. 2006-11-27.â†—

Recently i heard of Entropia Universeâ†—. I haven't taken a closer look
but i think it is a competitor to Second Life.

Note that Second Life may not be and is probably not the first virtual
world. And, when virtual world like Second Life becomes household
activity as the internet is today, it will probably not be known as
Second Life or run by one single company, but diverse companies with
servers all over the world, where there is a unified virtual world all
the world's people can be in. (This situation may be likened to the
internet circa 1995. Or, perhaps also similar when telephone was in its
pioneering days.)

----

Xah

âˆ‘ http://xahlee.org/

Xah Lee, Jan 22, 2007