Slashdot Mirror


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.

18 of 286 comments (clear)

  1. Running This by andyrut · · Score: 4, Informative

    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.

    1. Re:Running This by Fletch · · Score: 2, Informative
      It seemed to me that the DLL paths are hard-coded, so that's why it needs to be in that particular directory.
      The PHP binary is looking for the php_ffi.dll extension in it's default extension_dir (C:\php5\ext). Instead of unzipping it there you could simply run it as:
      php.exe -d extension_dir=. opengl.php
  2. Correct me if I'm wrong, but... by Anonymous Coward · · Score: 5, Informative

    This actually isn't an "OpenGL implementation". It just calls OpenGL func in win32 environment.

    1. Re:Correct me if I'm wrong, but... by hey · · Score: 2, Informative

      Yeah, for example it uses glEnable() from Windows.

  3. Re:Practical use by shamilton · · Score: 4, Informative

    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
  4. This is NOT Server-side by cbrocious · · Score: 5, Informative

    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.
  5. Re:vsync by volvoguy · · Score: 2, Informative

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

  6. Re:Using the right tool for the job by damiam · · Score: 2, Informative

    GTK can embed an OpenGL display, so yes, you can use 3D in GTK apps. That wasn't, however, the parent's point. The point was that PHP was designed for server-side scripting and is therefore not the right tool for any GUI job.

    --
    It's hard to be religious when certain people are never incinerated by bolts of lightning.
  7. Re:Perfect application by timothyf · · Score: 2, Informative

    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 with PHP. That will run in your browser.

  8. Who's getting the most FPS? by asherman · · Score: 2, Informative

    On my 1.4ghz Pentium M/Radeon 9000 laptop i'm getting 230-240 fps on the fastest spirograph.

  9. Re:Perfect application by MagPulse · · Score: 3, Informative

    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.

  10. awesome by vmircea · · Score: 4, Informative

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

  11. Re:PHP OpenGL on SourceForge by iridiumz0r · · Score: 5, Informative

    I'm the author of this thing. I read slashdot quite regularly and I'm very suprised this found it's way here. In my opinion it is not slashdot worthy. It relies on lots of experimental stuff, and is just generally not up to production standard. It was my mess-around one afternoon when I should have been studying. I entered it into the competition because I wanted to do something different. I chose intentionally not to use PHP-GTK for various reasons. I wanted to start out from scratch and see if I can do everything myself. It was not my intention to do this all 'properly' as such.

  12. This is no big deal by Anonymous Coward · · Score: 1, Informative
    OpenGL is just a library. You can link it in to anything which allows libraries to be linked in. That includes C programs, Java programs (JNI), C++ programs. But it doesn't stop there... PHP has a modules/extension mechanism; it can link in DSO files. But so can Apache and a host of other things. In fact, maybe I'll write an Apache/OpenGL module so that people can make stuff appear on my screen by doing web stuff... that would be really easy to do if you've written some Apache modules before, and I've done plenty of that, but I'm not really sure what I would do with this.

    ----------
    mobile porn

  13. Not an implementation, but a binding by Xeger · · Score: 4, Informative

    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.

  14. Correction by Xeger · · Score: 2, Informative

    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!

  15. Re:Yet another OpenGL binding by TimoT · · Score: 2, Informative

    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

  16. Re:Using the right tool for the job by 1110110001 · · Score: 2, Informative

    Set error_reporting to E_ALL and you see when PHP has to decide something you haven't defined. When you set your stderr to /dev/null you won't see errors in most unix tools and they do "something else". PHP has a recommended configuration. Use it!

    b4n