Results 1 to 2 of 2

Thread: Lighting + Normals Question

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    2

    Lighting + Normals Question

    Hi everyone,
    I'm experiencing an issue with OpenGL ES 2.0 on the iPhone. I'm working on a game where I'd like to get a nice "glow" from the sun in the middle. I've got the "look" of it down, but I think I've botched the normals. Essentially, all I want is a flat triangle strip, with a light source in the middle. But, I'm getting a strange result (see video here). I've played around with the normals, setting all to zero, all to one, etc. but it doesn't seem to work.

    Apologies if I'm not being super-clear here, I'm relatively new to OpenGL. I hope the image, video and source code below will better reveal my problem.

    Video of the issue can be seen here

    The image below displays what I am attempting to achieve here...

    Any help would be greatly appreciated!!

    Code :
    static const Vertex3D vertices[]= {
            {-480, 320,-1},              
            {-480, 0 ,-1},
            {960, 320, -1},
            {960, 0, -1},
        };
     
        static const Color3D colors[] = {
            {1.0, 0.77647, 0, 0.3},
            {1.0, 0.77647, 0, 0.3},
            {1.0, 0.77647, 0, 0.3},
            {1.0, 0.77647, 0, 0.3},
        };
     
        static const GLubyte icosahedronFaces[] = {
            0, 1, 2,
            2, 1, 3
        };
     
    // I'm not sure what to do here for a flat normal...
        static const Vector3D normals[] = {
            {0.000000, 0.000000, 1.000000},
            {0.000000, 1.000000, 1.000000},
            {0.000000, 0.000000, 1.000000},
            {0.000000, 1.000000, 1.000000},
        };
     
        glPushMatrix();
        glClear(GL_DEPTH_BUFFER_BIT);
     
        /********** LIGHTING */
        // Define the diffuse component of the first light
        const GLfloat light0Diffuse[] = {1, 1, 1, 1.0};
        // Define the position of the first light
        const GLfloat light0Position[] = {lightPosition_.x, lightPosition_.y, 1.0, 1.0};
     
        glEnable(GL_DEPTH_TEST);
        glEnableClientState(GL_NORMAL_ARRAY);
        glEnable( GL_COLOR_MATERIAL );
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glDisable(GL_TEXTURE_2D);
     
        glShadeModel(GL_SMOOTH);
     
     
        glBlendFunc (GL_SRC_ALPHA, GL_DST_ALPHA);
        glVertexPointer(3, GL_FLOAT, 0, vertices);
        glColorPointer(4, GL_FLOAT, 0, colors);
        glNormalPointer(GL_FLOAT, 0, normals);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, icosahedronFaces);
        glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
     
     
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Diffuse);
        glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
     
        glEnable(GL_TEXTURE_2D);
        glDisable(GL_LIGHT0);
        glDisable(GL_LIGHTING);
        glDisable( GL_COLOR_MATERIAL );
        glDisableClientState(GL_NORMAL_ARRAY);
        glDisable(GL_DEPTH_TEST);
        glPopMatrix();

    -G.

  2. #2
    Senior Member Regular Contributor imported_tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: Lighting + Normals Question

    To achieve a basic sun glow effect, you can draw additive blended textured quad without any lighting. As lighting can be disabled, you will not need any normals at all. So you should not be setting nor sending any normals.

    The code looks like it is for ES 1, not ES 2.

Similar Threads

  1. Lighting without Normals
    By Salbris in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-28-2010, 11:17 AM
  2. Normals and lighting
    By iris_raj in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-17-2003, 10:28 PM
  3. Lighting/Normals help
    By chennes in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-24-2003, 08:07 AM
  4. lighting and normals
    By Warrior in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 03-27-2001, 10:05 AM
  5. lighting and normals
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-26-2000, 03:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean