OpenGL in PHP
Neophytus writes "Submitted as an entry into the .geek PHP5 tournament a proof of concept openGL implementation in PHP has been released by Peter 'iridium' Waller. The demonstration (download) shows four items being rendered in realtime by PHP at a not unreasonable 59FPS. The author welcomes feedback with practical uses for this technology."
Update: 06/09 01:10 GMT by T : iridiumz0r, author of this entry, adds a link to this informative page responding to a number of comments in the discussion below.
Very impressive -- A while back I heard about PHPOpenGL.
But he didn't even use this at all! Pretty self contained, even to the gzipped uuencoded DLL file embedded in this PHP script whose sole purpose is to create the window that this PHP demo needs for the 3D graphics.
59 fps? Sounds like vertical sync at 60 hz. Anybody have any real performance figures?
"[A] high IQ is like a Jeep; you will still get stuck, just farther from help!" --Just d' FAQs, c.g.a
I have a 3ghz P4, Radeon 9700 Pro, and 1gb of RAM, and I get about 180FPS constant
While my subject is half-joking, it would be cool to be able to have a running traffic chart generated by a PHP script that you could use to monitor a particular server.
Maybe tie this in with the 3D portscanning/IDS system mentioned a few days ago and make it a remote application?
Overrated / Underrated : Moderation
When I ran it on my laptop, I was getting an average of 120 FPS. And while I respect the effort and appreciate the use of OpenGL, I cant see this killing Flash in the near future (or in any other parallel reality). Server-side scripts should stay just that, IMHO.
I've joined a group at LBNL (berkeley lab) that could use this. They have a database of molecular data, and they need a way to visualize it using a web interface.
Quid festinatio swallonis est aetherfuga inonusti?
Africus aut Europaeus?
You'd be surpised what get's prototyped in PHP e.g. http://sourceforge.net/projects/phpsdl/ - "PHP SDL module is a wrapper/binding of Simple DirectMedia Layer for PHP. The goal of this project is to allow rapid prototyping of multimedia applications using PHP."
Usually doesn't get beyond the prototype though.
Here's a couple of ideas:
- GPS terrain mapping: stream a live map in real time with low bandwidth
- Shrek Chat Live!: Have hires avatars render while you speak. Kinda like that Microsoft chat but with good chat buddies.
- Quantum Encryption: Have a whole 3d movie but just use three texture map hidden in the movie are your keys.
You say things that offend me and I can deal with it. Can you?
php is fast has a superb set of built in functionality and very flexible, and with php5 has pretty good OO support.
:)
Sure you're not just prejudiced?
I am curious, why don't you consider php to be the right tool? It's a turing complete language, it's object oriented, it supports inheritance (and mixin type multiple inheritance), it has exception handling, assertions, a large library and a large community.
So why not php? What makes php a poor choice as opposed to say perl, python, ruby, vb.net or any other scripted language?
evil is as evil does
I suppose if we did some code hacking we could get it to render the OpenGL scene and take a screenshot then save the screenshot as a file. From then on everyone could be sent that screenshot off the page. Sites with Half-Life and Quake2 maps wouldn't have to manually take the screenshots. PHP would be able to do it all for them (if they got a good camera location anyway :P)
Have you metaroderated recently?
Some would say that any use is inappropriate for PHP. Not me, but it's certainly one of the less interesting open source languages about.
;)
For instance, Ruby's web application support has been rapidly gaining ground for quite a while now; fancy state-keeping systems last seen on LISP; a powerful server framework now integrated with the standard library; an innovative object-relational mapping library which makes interfacing with SQL databases childsplay; an interesting new web application framework which is causing quite a stir; an amazingly easy to set up Wiki server; a nifty template library gaining fancy bytecode based acceleration and native-C compilation. Every one of these projects alone is probably more interesting to the average developer than yet-another-OpenGL-module for an interpreted language... isn't it?
Maybe this is why this is News for Nerds, not News for Geeks
I confess: I've been migrating away from bash and Perl script development, toward using PHP CGI scripts, for a while. It's just too convenient to not use as a CLI scripting language.
I have recently been playing around with Python, PyGame and OpenGL (I love the NeHe tutorial conversions done for PyGame) - I have been pretty pleased with the speed (OpenGL does all the heavy lifting - with a proper culling algorithm and scene graph implementation, speed could go up more with more complex scenes), especially on the machine I am using, which is low-end by many people's definition (P-3/450 w/GeForce 2 - definitely not a gaming machine, but works well enough for me).
Now, I don't know much about OpenGL yet, but is it possible to render to a file instead of the graphics buffer? If it were, then this thing could (in theory) go server-side (provided the server has the proper APIs and DLL, of course) - then render to a file for display by a web server.
Such a system could be useful for online data visualization services or other similar systems (mapping, network visualization, etc)...
Reason is the Path to God - Anon
I love his method for avoiding DLL problems.. the dll file is incoded in the program's source code, and is written out at run time:
D OnguDutY+uMzh80"Z la3IgO7mQ9+733v"H JeYD53pk3UyqKkZ"d 8fKcQwxe2tirBHl"u Jo99qxPlyQ7AFfx"
---
if ( is_file( "SimpleWndProc.dll" ) ? filesize( "SimpleWndProc.dll" ) != 2560 : 1 )
{
$dll = "eNrtVU9IFGEUf7NpTbZue1hCYqlvQT3JslsG0clt/aho1XHN
. "KDrYQTPJS1TUoWMEdSpYrEOEsQl66yD9gT1ILCHhIcqDML35
. "fe9733vffN+blu4p2AEAFQjLAsiBQ03wd3qD8B2c9sHT3fOh
. "TRwgKVFRVIP0SkQzFSIrpLmtgwyoaSlcXV1V68YYevv9/ZFn
. "80fXmUzKqT577k+5CBQgwWEluZm11AvgC+3hKr3gcQu0ye+C
[snip]
. "kdWIJ8pHfdFAdH90uzf+D/QDFVAQCA==";
$dllout = fopen( "SimpleWndProc.dll", "wb" );
if ( !$dllout )
die( "Unable to extract SimpleWndProc.dll" );
fwrite( $dllout, gzuncompress( base64_decode( $dll ) ) );
fclose( $dllout );
---
( He said in the comments that it required a DLL file to work for various reasons, and I guess he wanted to have everything contained in one file... But, it's still pretty funny. )
I'm a C coder, and I don't like VB.
... ) { ... }
But personally, I don't think that it forces you to think like a non-coder. It just has a very crippled, rigid, and non-expressive syntax that gets in your way.
If you took VB.NET and gave it a C-like syntax, it'd start to look a lot like Java, which is a pretty good language, and certainly better than nothing. The clumsiness of VB syntax, however, is what ruins the language IMHO.
Think about it:
Dim x as Integer
int x;
If...Then..End If
if(
Function iSomeFunctionName( x as Integer ) as Integer
iSomeFunctionName = x
End Function
int fn( int x ) { return x; }
These are all examples of equivalent statements. VB's just happen to be more clumsy, less flexible, and more bullshit-heavy. You can still do interesting things in VB. It's just annoying.
If there's one thing VB is good at, it makes it really easy to create GUI applications, and fast. And now that VB is VB.net, VB can use C# objects, and vice versa. So, honestly? I wouldn't mind coding the core of an application in C# (or better yet, Java), and then using VB.net to create a flimsy/cheap UI connecting the pieces and making it look presentable. In fact, if done right, that could turn out to be a better way to design an application.
Every tool has a place. Don't let the number of bad VB "programmers" fool you. Believe it or not, it's possible to create a "good" VB app.
This seems like a crazy idea, but it could seriously be useful. Making an online library of a huge pile of 3D models for example? That could greatly help game development projects.. Rather than opening model after model trying to remember which one is which, you could dump them all into a repository and have a handy-dandy php/opengl script generate little thumbnails for them all.. Awesome.
Not to troll, but IMO PHP is a rapidly advancing language and a force to be reconcilied with.
My JiggleScript project is a similar idea only using JavaScript as a base. I haven't released in awhile, but I've been working on it the past week or so and am nearing a point where I will be making another release--now with sound via OpenAL! :-)
I get many hundreds of frames per second with my system on pretty moderate hardware (such as my 1Ghz G4 Powerbook). There is one script (not on the site, but a friend wrote it) that has about 200 boxes being rendered at a time (so about 2400 polygons) and my Powerbook still touches the 200fps range.
Give it a shot. I'd love to get some people playing with and testing JiggleScript.
Hexy - a strategy game for iPhone/iPod Touch