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.
I'm sure others are thinking, like me, "Huh? PHP in a window, not a server-side script?" It took me a couple of moments to figure out how this works, so I figured this could be of some help to others struggling with it.
How to get this download to work in Windows:
1. Unzip the contents of the download to C:\php5
2. Open the C:\php5 directory in Windows Explorer
3. Drag and drop the opengl.php file onto the php-win.exe icon
or
2. Open a Command Prompt
3. C:
4. cd \php5
5. php-win.exe opengl.php
It seemed to me that the DLL paths are hard-coded, so that's why it needs to be in that particular directory.
How soon till we see a port of Unreal?
...Is truly a lost art.
Of course, we already knew this.
Opengl in php.. well, let's see, you could umm.. sell it to a PHB who doesn't know any better, or make bets with people at the local pub that it can be done and then whip it out to win the bet.
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
This actually isn't an "OpenGL implementation". It just calls OpenGL func in win32 environment.
cheap implementation. JBoss have a far superior product and this does not even come close to the technical excellence that is JBoss. I do not work for JBoss.
Maybe I'll just start using my kitchen sink as a bathtub just because I can.
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
You are way off. This is pure novelty and has nothing to do with "server side" or "web pages," don't be fooled by the presence of PHP. Also, "port of OpenGL" doesn't make much sense -- OpenGL cannot be ported, just implemented, which this does not do. It's just an OpenGL client.
"[A] high IQ is like a Jeep; you will still get stuck, just farther from help!" --Just d' FAQs, c.g.a
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.
...better pr0n
--
This sig doesn't do windows
Just from reading a few comments, I see people still believe PHP is only server-side. This is all client-side. No server is neccesary. This is just like php-gtk, and the old php_opengl implimentation.
Disconnect and self-destruct, one bullet at a time.
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?
The author welcomes feedback with practical uses for this technology.
Because he couldn't think of any.
*ducks*
welcome to the party, PHP.
Well, it's not a port or an implementation; it's a wrapper to a DLL. That's the fun of dynamically loaded libraries: you can call opengl, gtk, qt, COM, CORBA, $WHATEVER_YOU_WANT from $WHATEVER_LANGUAGE_YOU_WANT as long as you take the time and effort to write a wrapper label, which this guy did, and he wasn't the first.
All's true that is mistrusted
So why not have 5 of them?
Here's the slightly altered code. (right click, save)
- Cary
Soon php will be used for all kinds of innapropriate uses!!
For a moment I thought of someone writing a PHP script to dynamically generate Perl scripts for web output... just for no real reason
But then I thought.... Naaaaaa.
;)
P.S. Anything on NeHe about this yet? I did a text search of the front page but nada (I haven't been to the site in months).
Are you local? There's nothing for you here!
... and I doubt they would make it to the front page on Slashdot without someone actually downloading and running them to see what they are.
Hi, welcome to Slashdot. You must be new here.
m-
You catch enchiladas by picking them up behind the head and holding them underwater until they don't kick anymore -VeGas
from the they-said-it-couldn't-be-done dept.
No, that was the "from the they-said-it-shouldn't-be-done dept." It's down the hall to the right, and be sure to knock loudly before entering.
501 Not Implemented
On my 1.4ghz Pentium M/Radeon 9000 laptop i'm getting 230-240 fps on the fastest spirograph.
think about it, im surfing the web, and some stupid ad comes up and demands my processor and video card take time away from whatever I purchased them to do... arrgh... unless I want to disable all the latest plugins or something, and that's a hassle to my lazy moonpie pudged ass
This is a very cool thing heh.. but it isn't to be unexpected, as phpopengl was already made, but this new one looks great as well. But who knows what other things will come out... Look at all of these things that php can do here ,there are a bunch of interesting and very useful mods, and more come out all the time. Also, take a look at that link, it gives you a good idea of what php can do (although there is much more than what is on that page).
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
Alert and knowledgeable readers will note that this isn't an implementation of OpenGL, but a binding of the OpenGL API into the PHP language.
A PHP *implementation* of OpenGL would be very impressive, indeed! That would imply that all of the 3D math, texture mapping, shading, rasterization, etc was written in OpenGL. Unfortunately, such an implementation would probably be extremely slow and therefore fairly useless. And it would of course still require an dynamically linked C library for framebuffer access.
So -- this is a cute trick, to be sure, but nothing to write home about. The author of the software has already said as much in an earlier comment.
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. )
Oops! I meant to say: That would imply that all of the 3D math, texture mapping, shading, rasterization, etc was written in PHP. This is what happens when we post to Slashdot before having our afternoon triple espresso!
First I would like to point out that it is still making calls to OpenGL functions which were written in C (and asm most likely). Since PHP is a scripting language and in this case it is calling the OpenGL functions most of the work is being done in the OpenGL calls. Therefore it should run pretty well because most of the delay will be resulting from the C function calls. Scripting languages and all interpreter languages should do well even for simple scenes. They do slow down when you have a lot of logic going on however, such as updating a world model graph.
Reserved Word.
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
This process is still young, but the eventual direction this will take is 3d apps over PHP and the web.
No, for the simple fact that this project is not headed in that direction. It does not provide for 3D apps over the web.
It's bound to go that way.
No, because in order for it to go that way, a terrible amount of work would need to be done, and the end result wouldn't provide anything that doesn't already exist.
I think it's extremely viable for a plugin to be designed that will use this, and many will adopt it for websites as a result. Why the hell wouldn't they?
Because PHP is not very well suited to the task, and better solutions exist. This hack is on the order of building a toilet out of LEGO's. Possible, but neither viable nor a harbringer of things to come.
It's not a totally bad idea, just one that scares me somewhat, if it's used maliciously.
I don't know that you know what the idea is here.
There are systemic misuses and outright exploits. I am sure that any new system has both.
There is nothing new about this "system". It's just another computer program.
Blatant plug: OpenGL and SDL bindings for Common Lisp: CL-SDL. And yes, I'm one of the authors. Most Common Lisps are compiled to native code; the performance is fairly good with the added benefit of having a high-level language to program with. There are also bindings to Haskell and OCaml AFAIK.
TimoT
It's mean to suggest something like that... Someone now WILL feel they NEED to write OpenGL bindings for BrainF*ck and Bash just because you suggested it and it's perverted enough.