http://www.perlmonks.org?node_id=698866

iSina has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am writing a protein folding program. I was only planning to distribute it as a calculator machine but I decided to add graphics to it. Most of the graphics part is done except one problem that I cant get over with. It is the lighting... At first I had written a more complex lighting scheme but as I found out that I couldnt get light to be displayed, I simplified it more and more until it was practically not there... So to see my problem with the issue, I have exactly translated a C light tutorial to perl and the light is still not displayed on my screen. I am wondering what is the problem? Is it how I input my arguements to opengl functions? Atleast can someone with POGL module take this code and run it, maybe it is a problem with my graphics card. I will be really really grateful if you can help me. Here is the code (if you can get this to work, I will try to apply the same correction to my program):
use OpenGL qw(:all); use strict; our $Light_Position = pack("f4", 0.0, 0.0, 0.0, 5.0 ); our $Specular_Material = pack("f4",1.0, 1.0, 1.0, 1.0); our $Shiny_Material = (50.0 ); our $newQuad = gluNewQuadric (); our $window; sub init { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glMaterialfv_s(GL_FRONT, GL_SPECULAR, $Specular_Material); glMaterialfv_s(GL_FRONT, GL_SHININESS, $Shiny_Material); glLightfv_s(GL_LIGHT1, GL_POSITION, $Light_Position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT1); } sub ReSizeGLScene { my ($w, $h) = @_; glViewport (0, 0, $w, $h); glMatrixMode (GL_PROJECTION); glLoadIdentity(); if ($w <= $h) { glOrtho (-1.5, 1.5, -1.5*$h / $w, 1.5*$h/$w, -10.0, 10.0); } else { glOrtho (-1.5*$w/$h,1.5*$w/$h, -1.5, 1.5, -10.0, 10.0); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } sub DrawGLScene { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gluSphere($newQuad,1, 18, 18); glFlush (); } glutInit(); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow("Window"); init(); glutDisplayFunc(\&DrawGLScene); glutReshapeFunc(\&ReSizeGLScene); glutMainLoop; return 0;

Replies are listed 'Best First'.
Re: Daunting Problem With Perl Opengl Lighting
by grep (Monsignor) on Jul 20, 2008 at 00:42 UTC
    I wish I knew what I am supposed to see, could you post a description or a demo screenshot from the tutorial?

    What I do see is a black box (500px) with a light gray circle in in the center about 300px across. I hope that is what I'm supposed to see, but I have no way of telling (without teaching myself OpenGL, which I really don't have time for right now).

    grep
    One dead unjugged rabbit fish later...
      Well that is good if you are not seeing any light on that circle (which is supposed to be a sphere). You are only supposed to see some a sphere with some shading and light. If you are not then the problem should be with the code and I hope I can fix it. Can you try changing the place of the light by changing the array and see if it creates any difference? I assume it wont though... our @Light_Position = ( 1.0, 1.0, 1.0, 1.0 );
        After changing @Light_Position I saw no change in the image.
        grep
        One dead unjugged rabbit fish later...
Re: Win32 - gl/glu.h problem
by BrowserUk (Patriarch) on Jul 20, 2008 at 07:41 UTC
      Has anyone attempting to build OpenGL on win32 solved the GL/glu.h problem?

      Coincidentally, I've been messing with POGL over the last week or so. I find that the latest subversion source builds straight out of the box using Visual Studio - and I've managed to patch it so that it builds with MinGW, too.

      For the svn source:
      svn checkout svn://graphcomp.org/cpan/OpenGL OpenGL
      or, if you don't have subversion, I could perhaps email you that source. (I think I've still got your address.)

      Note that the svn source ships with the freeglut dll, headers and import lib, and that running 'perl Makefile.PL' will install said dll into your perl/site/bin (unless it's already there).

      Cheers,
      Rob

        I'm trying to build the CPAN module by following the readme. Having followed the directions there, I get the following error:

        c:\Perl\packages\OpenGL-0.56\glu_util.h(4) : fatal error C1083: Cannot open include file: 'GL/glu.h': No such file or directory

        Unsurprising, as this file doesn't come with the CPAN module, or in glutdlls37beta.zip, or in GL.zip, which the readme suggests are all that is needed.

        So then I pulled the full source distribution from here, and even that doesn't contain a GL/glu.h.

        A quick google shows this to be a well known problem, but I failed to find a solution. I did locate a 'GL/glu.h' but it wasn't sufficiently up to date.

        As for the ppms, ever since PPM went graphical, it mysteriously breaks as soon as you look at it. It works a few times after a freah install and then just stops working.

        I've spent hours hacking my way through the maze of twisty packages that are the ActiveState::* and ActivePerl::* module spaces trying to work out what has broken, and even succeeded in fixing it briefly once, but it they seem to delight in making everything as obscure as possible. Anyone who believes that OO is the salvation of maintenance should try working out what is going on in there (or EU::MM), to realise that OO dogma leads to OO spagetti. And OO spagetti is just like procedural spagetti except that is costs 5 times as much to manufacture and is 10 times as hard to unravel.

        I've also reinstalled more times since 5.8.6/AS811 than in all the preceding builds put together. Seems to me that "they" are attempting to counter the Strawberry moves to take away their Win32 perl monopoly, but instead of making things easier to use, they've gone the protectionist route...which never worked.

        Bah humbug!


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.