Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: open gl lighting

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    8

    open gl lighting

    Click image for larger version. 

Name:	maze.jpg 
Views:	70 
Size:	20.8 KB 
ID:	903


    Hi guys

    i'm completely baffled, i'm trying to set lighting on the ground of the maze but every location i set, whether it be different, the light always ends up in the same location every time.


    This is my floorvertex code:
    Code cpp:
     
    #pragma once
     
     
    #include "GXBase.h"
     
     
    typedef struct {
        float u;    // texture u
        float v;    // texture v
        float nx;    // normal x
        float ny;    // normal y
        float nz;    // normal z
        float x;    // position x
        float y;    // position y
        float z;    // position z
    } 
    FloorVertex;
     
     
    static const FloorVertex Floor_Data[108] = {
     
     
    //room 1
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, -32.5f /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, -17.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, -17.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, -17.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, -32.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, -32.5f    /* 1 */
        },
     
     
     
     
    //room 1c
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -2.5f, 0.0f, -17.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -2.5f, 0.0f, -7.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 2.5f, 0.0f, -7.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 2.5f, 0.0f, -7.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 2.5f, 0.0f, -17.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -2.5f, 0.0f, -17.5f    /* 1 */
        },
     
     
    //room 2
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -32.5f, 0.0f, -7.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, -7.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, 7.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, 7.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -32.5f, 0.0f, 7.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -32.5f, 0.0f, -7.5f    /* 1 */
        },
     
     
    //room 2c
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, -2.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, -2.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, 2.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, 2.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, 2.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, -2.5f    /* 1 */
        },
     
     
     
     
    //room 3
     
        {
     
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 32.5f, 0.0f, 7.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, 7.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, -7.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, -7.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 32.5f, 0.0f, -7.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 32.5f, 0.0f, 7.5f    /* 1 */
        },
     
     
     
     
    //room 3c
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, 2.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, 2.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, -2.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, -2.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, -2.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, 2.5f    /* 1 */
        },
     
     
     
     
    //room 4
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, 32.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, 17.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, 17.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, 17.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -7.5f, 0.0f, 32.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 7.5f, 0.0f, 32.5f    /* 1 */
        },
     
     
     
     
    //room 4c
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 2.5f, 0.0f, 17.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 2.5f, 0.0f, 7.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -2.5f, 0.0f, 7.5f    /* 1 */
        },
     
     
     
     
     
     
        {
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -2.5f, 0.0f, 7.5f    /* 0 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -2.5f, 0.0f, 17.5f    /* 1 */
        },
     
     
        {
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 2.5f, 0.0f, 17.5f    /* 1 */
        },
     
     
     
     
    //room 5
     
     
            {
                0.0f, 1.0f, 0.0f, 1.0f,
                    0.0f, 7.5f, 0.0f, 7.5f   /* 2 */
            },
     
     
            {
                0.0f, 0.0f, 0.0f, 1.0f, 
                    0.0f, -7.5f, 0.0f, 7.5f   /* 0 */
            },
     
     
            {
                1.0f, 0.0f, 0.0f, 1.0f, 
                    0.0f, -7.5f, 0.0f, -7.5f   /* 1  */
            },
     
     
            {
                1.0f, 0.0f, 0.0f, 1.0f, 
                    0.0f, -7.5f, 0.0f, -7.5f   /* 1  */
            },
     
     
            {
                1.0f, 1.0f, 0.0f, 1.0f,
                    0.0f, 7.5f, 0.0f, -7.5f   /* 3 */
            },
     
     
            {
                0.0f, 1.0f, 0.0f, 1.0f,
                    0.0f, 7.5f, 0.0f, 7.5f   /* 2 */
            },
     
     
     
     
     
     
    };[/QUOTE]
     
    and this is my main code:
     
    [QUOTE]
    #include "GXBaseCube.h"
    #include "../../Common/GameFactory.h"
    #include "GXBase.h"
    #include "MazeVertices.h"
    #include "GroundVertices.h"
    #include "FloorVertices.h"
    #include "RoofVertices.h"
    #include <cmath>
     
     
    using namespace gxbase;
     
     
    GXBaseCube::GXBaseCube(void)
    {
        _texture0 = GameFactory::LoadTexture("08356Hill.bmp");
        _texture1 = GameFactory::LoadTexture("08356Ground.bmp");
        _texture2 = GameFactory::LoadTexture("08356Sky.bmp");
        _texture3 = GameFactory::LoadTexture("Cool64x64.bmp");
        _texture4 = GameFactory::LoadTexture("08356Floor.bmp");
        _texture5 = GameFactory::LoadTexture("08356Maze.bmp");
    }
     
     
    GXBaseCube::~GXBaseCube(void)
    {
    }
     
     
    void GXBaseCube::Draw(void)
    {
        glPushMatrix();
            glTranslatef(_x, _y, _z);
     
     
            glBindTexture(GL_TEXTURE_2D, _texture0);
     
     
            static float angle = 0.0f;
            angle += 0.0f;
            glRotatef(angle, 1.0f, 0.5f, 0.2f);
     
     
     
     
     
     
     
     
     
            // Enable lighting
            glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
     
     
     
     
     
     
     
    //GLfloat lightpos[] = {  40.000000f, -40.000000f, -40.000000f, -40.000000f, 40.000000f, 40.000000f };
    GLfloat lightpos[] =
        {
     
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 32.5f, 0.0f, 7.5f,    /* 0 */
     
     
     
     
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, 7.5f,    /* 1 */
     
     
     
     
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, -7.5f,    /* 1 */
     
     
     
     
     
     
     
     
            0.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 17.5f, 0.0f, -7.5f,    /* 0 */
     
     
     
     
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 32.5f, 0.0f, -7.5f,    /* 1 */
     
     
     
     
            1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 32.5f, 0.0f, 7.5f    /* 1 */
     
     
     
        };
    //GLfloat lightpos[] =
        //{
        //1.0f, 0.0f, 0.0f, 1.0f,
        //    0.0f, -17.5f, 0.0f, -7.5f    /* 1 */
        //};
    ////GLfloat lightpos[] =
    //    {
            /*1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, -17.5f, 0.0f, 7.5f*/    /* 1 */
    //    };
     
     
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
    glDisable(GL_LIGHTING);
     
     
     
     
            //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
     
     
     
            glEnableClientState(GL_VERTEX_ARRAY);
            glVertexPointer(3, GL_FLOAT, sizeof(CubeVertex), &Cube_Data[0].x);
     
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(GL_FLOAT, sizeof(CubeVertex), &Cube_Data[0].nx);
     
     
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(2, GL_FLOAT, sizeof(CubeVertex), &Cube_Data[0].u);
     
     
     
     
     
     
     
     
     
            glDrawArrays(GL_TRIANGLES, 0, 36);//glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
        //glPopMatrix();
     
     
     
     
        //glPushMatrix();
            glTranslatef(_x, _y, _z);
     
     
            glBindTexture(GL_TEXTURE_2D, _texture1);
     
     
            angle += 0.0f;
            glRotatef(angle, 1.0f, 0.5f, 0.2f);
     
     
     
     
            glEnableClientState(GL_VERTEX_ARRAY);
            glVertexPointer(3, GL_FLOAT, sizeof(GroundVertex), &Ground_Data[0].x);
     
     
     
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(GL_FLOAT, sizeof(GroundVertex), &Ground_Data[0].nx);
     
     
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(2, GL_FLOAT, sizeof(GroundVertex), &Ground_Data[0].u);
     
     
            glDrawArrays(GL_TRIANGLES, 0, 36);
        //glPopMatrix();
     
     
            glTranslatef(_x, _y, _z);
     
     
            glBindTexture(GL_TEXTURE_2D, _texture4);
     
     
     
     
            //static float angle = 0.0f;
            angle += 0.0f;
            glRotatef(angle, 1.0f, 0.5f, 0.2f);
     
     
     
            glEnableClientState(GL_VERTEX_ARRAY);
            glVertexPointer(3, GL_FLOAT, sizeof(FloorVertex), &Floor_Data[0].x);
     
     
     
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(GL_FLOAT, sizeof(FloorVertex), &Floor_Data[0].nx);
     
     
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(2, GL_FLOAT, sizeof(FloorVertex), &Floor_Data[0].u);
     
     
               glColor3f(1.0f,1.0f,1.0f);
            glDrawArrays(GL_TRIANGLES, 0, 108);
     
     
     
     
        //glPushMatrix();
            glTranslatef(_x, _y, _z);
     
     
            glBindTexture(GL_TEXTURE_2D, _texture2);
     
     
            angle += 0.0f;
            glRotatef(angle, 1.0f, 0.5f, 0.2f);
     
     
            glEnableClientState(GL_VERTEX_ARRAY);
            glVertexPointer(3, GL_FLOAT, sizeof(RoofVertex), &Roof_Data[0].x);
     
     
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(GL_FLOAT, sizeof(RoofVertex), &Roof_Data[0].nx);
     
     
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(2, GL_FLOAT, sizeof(RoofVertex), &Roof_Data[0].u);
     
     
            glDrawArrays(GL_TRIANGLES, 0, 36);
     
     
                    glTranslatef(_x, _y, _z);
     
     
            glBindTexture(GL_TEXTURE_2D, _texture5);
     
     
            angle += 0.0f;
            glRotatef(angle, 1.0f, 0.5f, 0.2f);
     
     
            glEnableClientState(GL_VERTEX_ARRAY);
            glVertexPointer(3, GL_FLOAT, sizeof(MazeVertex), &Maze_Data[0].x);
     
     
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(GL_FLOAT, sizeof(MazeVertex), &Maze_Data[0].nx);
     
     
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(2, GL_FLOAT, sizeof(MazeVertex), &Maze_Data[0].u);
     
     
            glDrawArrays(GL_TRIANGLES, 0, 244);
     
     
     
     
     
     
     
     
        glPopMatrix();
    }
     
     
    void GXBaseCube::Update(void)
    {
    }

    I will appreciate any help guys!!

    Thank you.
    Last edited by Dark Photon; 11-14-2012 at 05:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •