PDA

View Full Version : OpenGL in a WebBrowser



zak
04-08-2009, 09:03
Hi
i have found a page in wich the author provide a source code to build an activeX ocx/dll to display an opengl graphics in the internet explorer.
download the source from here:
http://www.sulaco.co.za/opengl_project_OpenGL_ActiveX.htm
it is written in the old delphi 7 (year 2002)
1) i was not able to run the online version, but the offline version are working okay: just copy the prebuilt ActiveGLProject.ocx to windows\system32 (in windows xp) then register the control:
regsvr32.exe ActiveGLProject.ocx
then run the supplied page ActiveGL.htm in the internet explorer, agree when the security warning appears. you will see a rotating figure.

2) of course we can't compare displaying opengl in this way with the recent addition in thinbasic ie: merging opengl with the canvas as in the marvelous example supplied by Petr here:
http://community.thinbasic.com/index.php?PHPSESSID=4c4c607df4d9334cc37253948ce3ecbd&topic=2423.msg18277#msg18277
the later is extrememly stable and without flickering and can be managed by keys/mouse...if we want .
but for the fun only, we can play with the supplied source code above even if we do not know Delphi language, : the target is to display a rotating pyramid in the webbrowser using the code by Petr in his recent response to martin.
1- open the file ActiveGLImpl1.pas in notepad the replace all the code between glBegin(.....); and glEnd; with the pyramid code:
or whatever you want.
2 - use an old version of Delphi 7 enterprise, install it temporary for the testing purposes only, and click file -> open project, then open the ActiveGLProject.dpr you will see in this file a line {$E ocx}, but if you want a dll change it to {$E dll} then save it.
3 - click in the menu Project -> Compile ActiveGLProject then Build ActiveGLProject. and you will see in the source code folder either an ActiveGLProject.ocx or ActiveGLProject.dll upon your choice.
4 - copy the ActiveGLProject.dll to the windows\system32 folder then register it, every time you want to test another ocx/dll you must unregister it like this :
regsvr32.exe -u ActiveGLProject.dll
then copy the new one and register it again.
i do not know the delphi language, this is just like walking during a sleep.
attached the thinbasic program (the same one by Petr: just it is opening the ActiveGL.htm instead of google.com , together with the slightly modified delphi source and the activex dll, register it before running the thinbasic program.
it is interesting to note that there is no security warning when running the activex ocx/dll from the webbrowser control. there are many many ideas and suggestions concerning displaying opengl in the webbrowser. one of them is to be able to supply the htm code within the thinbasic code instead of running the htm page. second is to make a generic activex dll which will accept the opengl code from the thinbasic code something like the oxygen approach or another possible approaches.
i forgot to say that in the thinbasic code :
WebBrowser_Navigate2(cbhndl, %ID_WEB1, "ActiveGL.htm")
i can't run the ActiveGL.htm file until i specify it's complete path, so to copy the file into c:\ then the code is:
WebBrowser_Navigate2(cbhndl, %ID_WEB1, "c:\ActiveGL.htm")
the second is working.
i do not know if this is a BUG or not, since it may be the webbrowser control designed to display http://www.... and not the local htm files.
here is what you should see:
http://img35.imageshack.us/img35/9669/pyramid2n.jpg

For other Delphi Fun codes ;maths,physics,puzzles...look here:
http://www.delphiforfun.org/programs/index.htm
free source code with executables, written by old version of Delphi

Michael Hartlef
04-08-2009, 09:28
Good find zak.

Delphi will allways be my first love when it comes to programming. I followed and used extensively till delphi 6. My ide INDEED was written in it. The language is so powerfull but at the same time easy.

Thanks for the info.
Michael

zak
04-08-2009, 09:32
hi mike
but it seems there is no delphi company now, and the program is replaced by a very big .net dependent language.
this is very bad , the good old stuff are always disappeared.

Petr Schreiber
04-08-2009, 09:38
Hi Zak,

thanks for interesting sample!
There is one thing - I do not recommend to copy anything to Windows directory, as it is not necessary.

The quick test steps to try your DLL can be simplified to:

Download and unrar your RAR :)
use "regsvr32.exe ActiveGLProject.dll" in the directory where you registered
Instead of


WebBrowser_Navigate2(cbhndl, %ID_WEB1, "c:\ActiveGL.htm") use simply
WebBrowser_Navigate2(cbhndl, %ID_WEB1, app_sourcepath+"ActiveGL.htm")

Run the script



Big thanks for example code on ActiveX plugin, as PowerBASIC 9 (language I use to create TBGL) supports creating COM servers now... hmm ;)

On the other side I think lot of people are still hesitating to install any ActiveX components, and in work/school it is usually even blocked.

But it is very inspiring for sure!


Petr

zak
04-08-2009, 13:53
another addition to the subject:
the WebGL from a japanese site:
http://sourceforge.jp/projects/webgl/releases/
or from here:
http://rapidshare.com/files/263591400/WebGL..20051210.BETA.rar
wich run the usual java script, the declaration addition are in the header file, but seems limited, and it may possible to add to it, together with the other file gl.js
the opengl code in the sample.htm file,
i can't run the sample.htm from ie, but i can using firefox.
the result as in the picture: a rotating lines:
http://img30.imageshack.us/img30/4369/webgl.jpg

Michael Hartlef
04-08-2009, 18:46
hi mike
but it seems there is no delphi company now, and the program is replaced by a very big .net dependent language.
this is very bad , the good old stuff are always disappeared.



Not quite right. After Codegear took it over , now Embarcadero is responsible. There is still a native Win version:

http://www.embarcadero.com/products/delphi/