Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
PHP Programming Graphics Software

OpenGL in PHP 286

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.
This discussion has been archived. No new comments can be posted.

OpenGL in PHP

Comments Filter:
  • by mdrejhon ( 203654 ) * on Tuesday June 08, 2004 @05:21PM (#9371307) Homepage
    Very impressive -- A while back I heard about PHPOpenGL [sourceforge.net].

    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.
  • Running This (Score:5, Informative)

    by andyrut ( 300890 ) on Tuesday June 08, 2004 @05:21PM (#9371310) Homepage Journal
    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.
  • by AtariMike ( 516594 ) on Tuesday June 08, 2004 @05:22PM (#9371326)
    How soon till we see a port of Unreal?
  • by Cardinal ( 311 ) on Tuesday June 08, 2004 @05:23PM (#9371337)
    ...Is truly a lost art.

    Of course, we already knew this. [php.net]
    • When you have a hammer, everything looks like a nail!
    • 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? :)
      • Python is fast has a superb set of built in functionality and very flexible, and has great OO support.
        Ruby is fast has a superb set of built in functionality and very flexible, and great OO support.
        Smalltalk is fast has a superb set of built in functionality and very flexible, and great OO support.
        Common Lisp is fast has a superb set of built in functionality and very flexible, and great OO support.

        Nothing about PHP makes it more suited for this job. Also, PHP is a language that was made specifical

    • by killjoe ( 766577 ) on Tuesday June 08, 2004 @05:49PM (#9371581)
      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?
      • by Saeed al-Sahaf ( 665390 ) on Tuesday June 08, 2004 @05:52PM (#9371611) Homepage
        So why not php?

        Because you don't have to be a "guru" a la Perl to right functional programs with it. Same reason people here hate VB.

        • I don't hate VB because non-coders can use it, I hate VB because it forces me to think like a non-coder in order to use it.

        • by runderwo ( 609077 ) <{gro.niw.liam} {ta} {owrednur}> on Tuesday June 08, 2004 @08:47PM (#9373138)
          Nice troll. The problem is more like that with PHP you can "right" programs that work with a minimum of effort. That sounds great, but the issue shows up when that code is handed to someone else. Debugging someone else's code in a language that enforces structured programming pragmas as little as possible is a nightmare. I know this because I do it on a regular basis.

          PHP is like MySQL, and it appeals to the same group of people. It works, most of the time. When it's not sure what to do, it does _something_ rather than annoy the programmer, which might even be the wrong thing. When it does something that might be the wrong thing, it does it silently whenever possible so there is no "squeaking" on the outside. The result is that PHP programs work most of the time, like MySQL. That sounds great, but they also have a tendency to fail in unexpected murky ways.

          BTW, there is no need to be a "guru" to write Perl programs. An understanding of the syntax, as well as basic structured programming/OO principles is all that is necessary to create fast, reusable, and reliable Perl code. The problem is that frequently people lack the latter, so they jump on a language like PHP which lets them get away with not having to know such things. Such people view PHP as superior and Perl programmers as pretentious language snobs because they can do in 5 minutes in PHP what would have taken them an hour to learn how to do in Perl. That in no way invalidates the viewpoint of the Perl snob. PHP is a half-ass hack of a language that happens to be preferred by the majority of half-ass hacks of programmers out there.

          Note, this is not a flame at PHP developers. I know some really good ones. I'm flaming people who suggest that PHP is a better language because it doesn't make you learn anything about software design principles. That's precisely the reason I avoid other people's PHP code whenever possible and don't recommend its use in a business environment where software infrastructure quality counts towards the bottom line.

          • "Debugging someone else's code in a language that enforces structured programming pragmas as little as possible is a nightmare. I know this because I do it on a regular basis."

            Same here, and I totally agree with you. If something goes wrong, I want to know about it, not have the program / database decide for me what it should do with it. I think your problem was you mentioned something bad about MySQL in a PHP story. The LAMP zealots are amongst the worst. MySQL will accept date types like 2004-15-60!
      • VB.Net, C#, or any other .Net framework language are certainly NOT scripting languages!
      • When one thinks OpenGL they think real time graphics. 59fps sounds impressive until you look at what it's doing in 59fps. Unless he's got his vsync locked that demo should be going several hundred FPS even on a lowly GeForce 2 MX and a barely over 1Ghz processor.

        When cross platform is more important than "wow" factor and speed PHP might be appropriate. Otherwise you need to stick to compiled languages. If it can only push a few basic primitives with simple vertex based coloring at 59fps that doesn't le
      • by pizza_milkshake ( 580452 ) on Tuesday June 08, 2004 @06:32PM (#9371991)
        It's a turing complete language

        so is Brainfuck [muppetlabs.com], but i wouldn't consider it the right tool at any time.

      • i would say that it's absolutely brain-dead scoping rules alone make it not the right tool for just about any meaningful task. and unless you're refering only to php5, calling php object oriented is like calling an old ten-speed with an electric motor strapped onto it a motorcycle.
      • So why not php? What makes php a poor choice as opposed to say perl, python, ruby, vb.net or any other scripted language?

        What makes any scripting language a good choice for 3D graphics?

    • I don't think so. Does gtk easily do 3D? It looks to me that the demo uses 3D.
    • "Using the right tool for the job ... Is truly a lost art."

      What? He is creating a tool.
  • by vxvxvxvx ( 745287 ) on Tuesday June 08, 2004 @05:23PM (#9371340)
    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.
  • vsync (Score:5, Interesting)

    by shamilton ( 619422 ) on Tuesday June 08, 2004 @05:26PM (#9371366)
    59 fps? Sounds like vertical sync at 60 hz. Anybody have any real performance figures?
    • Re:vsync (Score:3, Interesting)

      by atrus ( 73476 )
      Many video cards, when operating in OpenGL, VSync by default, so I agree with you here.
    • Re:vsync (Score:2, Informative)

      by volvoguy ( 760793 )
      If the FPS given in the titlebar of the demo app are accurate, it's doing 160FPS on my modest machine (P4 2.8Ghz, 1Gb RAM, ATI Radeon 7500).

  • by Anonymous Coward on Tuesday June 08, 2004 @05:26PM (#9371372)
    This actually isn't an "OpenGL implementation". It just calls OpenGL func in win32 environment.
  • by Anonymous Coward on Tuesday June 08, 2004 @05:27PM (#9371377)
    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.
  • Hrm.. (Score:5, Funny)

    by Anonymous Coward on Tuesday June 08, 2004 @05:28PM (#9371390)
    Maybe I'll just start using my kitchen sink as a bathtub just because I can.
    • Maybe I'll just start using my kitchen sink as a bathtub just because I can.

      Wait till you have kids.
    • Re:Hrm.. (Score:3, Funny)

      by mrjb ( 547783 )
      Actually my dad tried this once [using the sink as bathtub] before I was born, according to legend, because the tiny house they bought had no shower-- used the sink as tub and got stuck. If he moved one way he'd turn up the burning hot peel-your-skin-off temperature water, moving the other way he'd turn up the so-cold-it-would-freeze-his-you-know-what-off water. My mom, instead of helping out, ran off to get the photo camera. None of the pictures she took got any good, they were all shaken cause of her laug
  • Actually faster FPS (Score:3, Interesting)

    by Wallslide ( 544078 ) on Tuesday June 08, 2004 @05:28PM (#9371396)
    I have a 3ghz P4, Radeon 9700 Pro, and 1gb of RAM, and I get about 180FPS constant
  • by mhesseltine ( 541806 ) on Tuesday June 08, 2004 @05:29PM (#9371400) Homepage Journal

    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 [slashdot.org] and make it a remote application?

  • Perfect application (Score:5, Interesting)

    by Capt'n Hector ( 650760 ) on Tuesday June 08, 2004 @05:32PM (#9371425)
    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.
    • You'll probably want to keep looking. As others have mentioned, this only calls Win32 OpenGL API (using some bundled DLLs?), and requires that PHP be run from the command line. While the code may be more portable for being written in PHP (although, as I said, it relies on external libraries written for Win32), it won't run in your browser.

      However, you might take a look at Shockwave Flash Remoting [amfphp.org] with PHP. That will run in your browser.

    • That's not how it works, you don't run a remote 3d interface, you write opengl apps using the php language. It appears to be just a language binding, it has nothing to do with servers or websites. All you get here is the the constructs the php language give you (dynamic typing, etc) with a way to create a local opengl app. Don't think flash, think more like XUL or Visual Basic (both of which require a runtime), it could be delivered and run over the web but not without a lot of work and already having th
    • RTFA. This has nothing to do with the web. This is just a wrapper around a .dll that allows PHP programs to access the video card and use OpenGL on the local machine. It's Windows-only and the API probably sucks.

      Python and Perl also have (much more mature) OpenGL support. I doubt they would fit your needs either (OpenGL is for real-time local graphics, not networked visualization), but they'd almost certainly be better than this hack.

    • by MagPulse ( 316 ) on Tuesday June 08, 2004 @06:05PM (#9371732)
      You probably want a Java3D applet, which can use OpenGL or Direct3D. You can access your database from it using JDBC or just grab a flat file from a URL, and then visualize it however you want.
    • Uh no. This is a client side application, OpenGL bindings for PHP. You can't use it with a web server so that it renders some polygons into client's browser window. Sheesh.
  • by Anonymous Coward on Tuesday June 08, 2004 @05:33PM (#9371440)
    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.
  • by tickticker ( 549972 ) <tickticker@ g m a i l .com> on Tuesday June 08, 2004 @05:38PM (#9371483) Journal
    ...better pr0n

    --
    This sig doesn't do windows
  • by cbrocious ( 764766 ) on Tuesday June 08, 2004 @05:39PM (#9371489) Homepage
    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.
  • 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.
  • Feedback (Score:2, Funny)

    by Anonymous Coward
    The author welcomes feedback with practical uses for this technology.

    Because he couldn't think of any.

    *ducks*
  • And I say, (Score:4, Funny)

    by consumer ( 9588 ) on Tuesday June 08, 2004 @05:45PM (#9371547)
    welcome to the party [cpan.org], PHP.
  • So why not have 5 of them? [patriot.net]

    Here's the slightly altered code [patriot.net]. (right click, save)

    - Cary
  • by theantix ( 466036 ) on Tuesday June 08, 2004 @06:02PM (#9371704) Journal
    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.
  • On my 1.4ghz Pentium M/Radeon 9000 laptop i'm getting 230-240 fps on the fastest spirograph.
  • by Moonpie Madness ( 764217 ) on Tuesday June 08, 2004 @06:05PM (#9371728)
    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
    • You sound a little confused there sonny..

      This is a _php extention_, so the only way you would see php generated 3d images in your browser would be if they were rendered on the website's server, then converted to gif/jpg, and send to your browser as image.. Thus taking no cpu power from your computer

  • awesome (Score:4, Informative)

    by vmircea ( 730382 ) <vmircea@tj h s s t . edu> on Tuesday June 08, 2004 @06:06PM (#9371747) Homepage
    This is a very cool thing heh.. but it isn't to be unexpected, as phpopengl [sourceforge.net] 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 [php.net] ,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).
  • Interesting... (Score:4, Interesting)

    by cr0sh ( 43134 ) on Tuesday June 08, 2004 @06:33PM (#9372004) Homepage
    Let me first say I know this is client-side and not server-side.

    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)...

    • Re:Interesting... (Score:3, Interesting)

      by Tokerat ( 150341 )

      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)...

      My thoughts exactly. PHP already does this with the imaging funcitons, only in 2D. I ass

  • 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.
    • Correction (Score:3, Informative)

      by Xeger ( 20906 )
      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!
  • Avoiding DLL Hell (Score:4, Interesting)

    by tji ( 74570 ) on Tuesday June 08, 2004 @07:07PM (#9372328)
    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:

    ---
    if ( is_file( "SimpleWndProc.dll" ) ? filesize( "SimpleWndProc.dll" ) != 2560 : 1 )
    {
    $dll = "eNrtVU9IFGEUf7NpTbZue1hCYqlvQT3JslsG0clt/aho1XHND OnguDutY+uMzh80"
    . "KDrYQTPJS1TUoWMEdSpYrEOEsQl66yD9gT1ILCHhIcqDML35Z la3IgO7mQ9+733v"
    . "fe9733vffN+blu4p2AEAFQjLAsiBQ03wd3qD8B2c9sHT3fOhH JeYD53pk3UyqKkZ"
    . "TRwgKVFRVIP0SkQzFSIrpLmtgwyoaSlcXV1V68YYevv9/ZFnd 8fKcQwxe2tirBHl"
    . "80fXmUzKqT577k+5CBQgwWEluZm11AvgC+3hKr3gcQu0ye+Cu Jo99qxPlyQ7AFfx"
    [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. )
  • 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
  • Awesome! (Score:3, Interesting)

    by Klowner ( 145731 ) on Tuesday June 08, 2004 @08:50PM (#9373163) Homepage
    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.
  • by BigZaphod ( 12942 ) on Wednesday June 09, 2004 @12:55AM (#9374458) Homepage
    My JiggleScript [jigglescript.com] 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.

As of next Thursday, UNIX will be flushed in favor of TOPS-10. Please update your programs.

Working...