Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Light at objects

  1. #1
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Light at objects

    Sorry for this silly post, but lights (with AND without shader) are created for ALL objects, or not ?

    How can I set for which objects they work ?

    And how can I use more than 8 Lights ? Or only 8 for all/one object ?

    How could I give the lights to my shader ?

    Sorry but I couldn't figure this out...


    ^^


  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Light at objects

    Quote Originally Posted by DarkShadow44
    Sorry for this silly post, but lights (with AND without shader) are created for ALL objects, or not ?
    There is no silly questions!

    Quote Originally Posted by DarkShadow44
    How can I set for which objects they work ?
    For the FFP (without shaders) it can be achieved by using glEnable()/glDisable(). Each particular light-source can be enabled or disabled by glEnable(GL_LIGHTx)/glDisable(GL_LIGHTx). For example use
    Code :
    glEnable(GL_LIGHT1);
    //... DrawSomeObjectsWithLight1Effects();
    glDisable(GL_LIGHT1);
    //... DrawSomeObjectsWithoutLight1Effects();
    //... etc
    If you want to disable all light sources, than use
    Code :
    glDisable(GL_LIGTING);
    //... DrawSomeObjectsWithoutLight();

    Quote Originally Posted by DarkShadow44
    And how can I use more than 8 Lights ? Or only 8 for all/one object ?
    For the FFP only 8! But it is also expensive. Tell me, in what situation you would like to use more than 3 light sources? If there is such need, try to simulate those lights. It is common case to create a texture to simulate lighting effects. It is much cheaper than having lights. Nowadays hardware is strong enough to deal with enormous scenes with multiple lights, but my advice is not to waste the power.


    Quote Originally Posted by DarkShadow44
    How could I give the lights to my shader ?
    It depends on the version of the GLSL. If you are using GLSL up to the version 1.20, then you can get the parameters of the light-sources through build-in uniform variables gl_LightSource[]. The number of light sources is confined to the gl_MaxLights, which is the same value as in FFP, hence 8. In GLSL 1.30 and up, you are free to organize lighting as you like. There are limitations in the number of variables you can have, but you'll probably experience performance degradation before depletion of memory resources for the variables.

    Quote Originally Posted by DarkShadow44
    Sorry but I couldn't figure this out...
    Did I clarify anything, or make things even worse?

  3. #3
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Re: Light at objects

    First thanks for your answers, they helped very much ^^

    I want ot create one or two lights for a house, and draw this a few times (different houses and each a few times), so light would be nice.

    Could I limit lights for the radius of my house ?

    And how I set the lights with shaders if I would use more than 8 ? I mean, the shader is executed for every model...

    Another question, my lights just can make models(textured) more dark, not brighter, but why ?

    But now if the problem that my shader doesn't move my models
    Code :
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    Sorry that doesn't belong here...


    ^^


  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Light at objects

    Quote Originally Posted by DarkShadow44
    Could I limit lights for the radius of my house ?
    In FFP this can be done by setting attenuation parameters, but I suggest to relocate lights when moving to another house, keeping the total number of lights to just one or two.

    Quote Originally Posted by DarkShadow44
    And how I set the lights with shaders if I would use more than 8 ? I mean, the shader is executed for every model...
    In GLSL 1.3+ you don't have lights at all! Neither vertices, nor normals... Just attributes! And you can interpret them as you like. So, you can fill the buffer with thousands of coordinates and assume that those are lights' positions and do the lighting calculations.

    Quote Originally Posted by DarkShadow44
    Another question, my lights just can make models(textured) more dark, not brighter, but why ?
    You are probably "modulating" color of the objects with the textures, and the material is too dark, or the amount of light that shade the objects is not enough to make them bright.

    Quote Originally Posted by DarkShadow44
    But now if the problem that my shader doesn't move my models
    Code :
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    This part I didn't understand.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Re: Light at objects

    You mean if I move from one house to another to ""turn the light off" ? But what if there are more houses on the screen ?

    You mean, in the shader lights are like vectors ?

    If I set the light to maximum (1.0, 1.0, 1.0), then my model is as bright as if lightning is turned off


    If I use shaders instead of FFP, my model couldn't be translated (I mean moved by "glTranslatef"). All calls to "glTranslatef" and "glRotatef" change nothing...

    Could you possibly show your code of loading shaders ??
    Because my programm crashes with some shaders at "glBegin" (and my models are "frozen")


    ^^


  6. #6
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Light at objects

    Quote Originally Posted by DarkShadow44
    You mean if I move from one house to another to ""turn the light off" ? But what if there are more houses on the screen ?
    Set the lights and draw one house, than move lights to another position and draw another house etc.

    Quote Originally Posted by DarkShadow44
    You mean, in the shader lights are like vectors ?
    Put whatever you need for lighting into some uniforms and use the data to calculate lighting.

    Quote Originally Posted by DarkShadow44
    If I set the light to maximum (1.0, 1.0, 1.0), then my model is as bright as if lightning is turned off
    That's mean your lighting does not work at all. Post some code to take a look.

    Quote Originally Posted by DarkShadow44
    If I use shaders instead of FFP, my model couldn't be translated (I mean moved by "glTranslatef"). All calls to "glTranslatef" and "glRotatef" change nothing...
    Definitely I need to see the code.

    Quote Originally Posted by DarkShadow44
    Could you possibly show your code of loading shaders ??
    Because my programm crashes with some shaders at "glBegin" (and my models are "frozen")
    http://sites.google.com/site/opengltutorialsbyaks/

  7. #7
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Re: Light at objects

    Set the lights and draw one house, than move lights to another position and draw another house etc.
    That works ?

    I wanted to create a spot light: (that should be max. brightness)
    Code :
    	glEnable(GL_LIGHTING);
    	glEnable(GL_LIGHT0);
     
    GLfloat spot_direction[] = {0.0, 0.0, -5.0};
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,
    spot_direction);
    glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90);
    glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0);
     
    GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
     
    GLfloat light_ambient[] = {1, 1, 1, 1.0};
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
     
    GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

    Here is my vertex shader:
    Code :
    void main(void)
    {
     
     gl_TexCoord[0] = gl_MultiTexCoord0;
     gl_TexCoord[1] = gl_MultiTexCoord1;
      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }

    Here is my shader loading code:

    Sorry that it is so long but I have no clue what could be wrong

    Code :
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)        // Resize And Initialize The GL Window
    {
        if (height==0)                                        // Prevent A Divide By Zero By
        {
            height=1;                                        // Making Height Equal One
        }
     
        glViewport(0,0,width,height);                        // Reset The Current Viewport
     
        glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
        glLoadIdentity();                                    // Reset The Projection Matrix
     
        // Calculate The Aspect Ratio Of The Window
        gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
     
        glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
        glLoadIdentity();                                    // Reset The Modelview Matrix
     
    }
     
     
    GLhandleARB ProgramObject;
    GLhandleARB VertexShaderObject;
    GLhandleARB FragmentShaderObject;
     
     
    void CheckError(GLhandleARB glObject) ;
    GLhandleARB my_program;
     
    int LoadShaderv(const char* name);
    int LoadShaderf(const char* name);
     
    int ShaderVertex;
    int ShaderFragment;
     
    GLuint texture;
     
    int InitGL(GLvoid)                                        // All Setup For OpenGL Goes Here
    {
        glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
        glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                // Black Background
        glClearDepth(1.0f);                                    // Depth Buffer Setup
        glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
        glDepthFunc(GL_LEQUAL);                                // The Type Of Depth Testing To Do
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    // Really Nice Perspective Calculations
        glEnable(GL_TEXTURE_2D);
     
        GLenum err = glewInit();
    if (GLEW_OK != err)
    {
    /* Problem: glewInit failed, something is seriously wrong. */
    //fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }
    //fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
     
        // Create Shader And Program Objects
    my_program = glCreateProgramObjectARB();
     
    //    VertexShaderObject   = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    //FragmentShaderObject = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
     
     
        //LoadShader("geo_shdr.s",GL_GEOMETRY_SHADER_EXT);
     
        int ShaderVertex=LoadShaderv("vert_shdr.s");
    int ShaderFragment=LoadShaderf("frag_shdr.s");
     
    // Link The Program Object
    glLinkProgramARB(my_program);
    CheckError(my_program);
     
    // Use The Program Object Instead Of Fixed Function OpenGL
        if(use)
        {
            glUseProgramObjectARB(my_program);
        }
     
        //int uColor , uDepth;
        //uColor = glGetUniformLocationARB(s2,"tex1");
        //uDepth = glGetUniformLocationARB(s2,"tex2");
     
     
         //glUniform1i(uColor,1);
        // glUniform1i(uDepth,0);
     
        BMPClass bmp;
     
        BMPLoad("C:/!data/dat.bmp",bmp);
     
     
     
        glGenTextures(1, &texture);
     
            glBindTexture(GL_TEXTURE_2D, texture);
     
            //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (GLfloat) anisotropic);
     
        //    opj_dinfo_t* JPEG;
        //JPEG=opj_create_decompress(CODEC_JP2);
     
     
     
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
                //    glTexImage2D(GL_TEXTURE_2D, 0, 3, bmp.width, bmp.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bmp.bytes);
                    glTexImage2D(GL_TEXTURE_2D, 0, 3, bmp.width, bmp.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bmp.bytes);
        return TRUE;                                        // Initialization Went OK
    }
     
    char* data;
     
    void readShader(FILE*file)
    {
        fseek(file, 0, SEEK_END);
        int size=ftell(file);
            //size=filelength(file);
        data=(char*)malloc(size);
     
            fseek(file,-size, SEEK_CUR); //zum Anfang zurück
     
            fread(data,size,1,file);
            data[size]='\0';
    }
     
    void CheckError(GLhandleARB glObject)
    {
        int blen,slen ;
        char* InfoLog;
     
        glGetObjectParameterivARB(glObject, GL_OBJECT_INFO_LOG_LENGTH_ARB , &blen);
        if (blen > 1)
        {
             InfoLog=(char*)malloc( blen*sizeof(GLhandleARB));
             glGetInfoLogARB(glObject, blen, &slen, InfoLog);
             MessageBox(hWnd, InfoLog,NULL,NULL);
             free(InfoLog);
        }
    }
    int LoadShaderf(const char* name)
    {
     
     
    FILE *file=fopen(name,"rb");
     
    readShader(file);
        char* shader_data2=data;
     
    fclose(file);
     
    GLhandleARB shader;
     
    shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
     
     
     
    // Load Shader Sources
    glShaderSourceARB(shader, 1, (const GLcharARB**)&shader_data2, NULL);
     
    // Compile The Shaders
    glCompileShaderARB(shader);
    CheckError(shader);
     
    // Attach The Shader Objects To The Program Object
    glAttachObjectARB(my_program, shader);
     
     
    return shader;
    }
     
    int LoadShaderv(const char* name)
    {
     
     
    FILE *file=fopen(name,"rb");
     
    readShader(file);
        char* shader_data2=data;
     
    fclose(file);
     
    GLhandleARB shader;
     
    shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
     
     
     
    // Load Shader Sources
    glShaderSourceARB(shader, 1, (const GLcharARB**)&shader_data2, NULL);
     
    // Compile The Shaders
    glCompileShaderARB(shader);
    CheckError(shader);
     
    // Attach The Shader Objects To The Program Object
    glAttachObjectARB(my_program, shader);
     
     
    return shader;
    }
     
    float time=0;
     
    float right=0;
    float up=0;
     
     
     
    int DrawGLScene(GLvoid)                                    // Here's Where We Do All The Drawing
    {
     
     
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear Screen And Depth Buffer
        glLoadIdentity();                                    // Reset The Current Modelview Matrix
        glTranslatef(-1.5f,0.0f,-6.0f);                        // Move Left 1.5 Units And Into The Screen 6.0
        glTranslatef(right,0,0);
        glRotatef(up*10,0.0f,1.0f,0.0f);                        // Rotate The Triangle On The Y axis ( NEW )
     
        glTranslatef(right,0,0);
     
        glBindTexture(GL_TEXTURE_2D, texture);
     
        glBegin(GL_TRIANGLES);                                // Start Drawing A Triangle
     
            glTexCoord2f(1.0f,0.0f);
            glVertex3f( 0.0f, 1.0f, 0.0f);                    // Top Of Triangle (Front)
     
            glTexCoord2f(2.0f,1.0f);
            glVertex3f(-1.0f,-1.0f, 1.0f);                    // Left Of Triangle (Front)
     
            glTexCoord2f(3.0f,0.0f);
            glVertex3f( 1.0f,-1.0f, 0.0f);                    // Right Of Triangle (Front)
     
        glEnd();                                           
            time+=0.01;
        return TRUE;                                        // Keep Going
    }
     
     
     
    GLvoid KillGLWindow(GLvoid)                                // Properly Kill The Window
    {
        if (fullscreen)                                        // Are We In Fullscreen Mode?
        {
            ChangeDisplaySettings(NULL,0);                    // If So Switch Back To The Desktop
            ShowCursor(TRUE);                                // Show Mouse Pointer
        }
     
        if (hRC)                                            // Do We Have A Rendering Context?
        {
            if (!wglMakeCurrent(NULL,NULL))                    // Are We Able To Release The DC And RC Contexts?
            {
                MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            }
     
            if (!wglDeleteContext(hRC))                        // Are We Able To Delete The RC?
            {
                MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            }
            hRC=NULL;                                        // Set RC To NULL
        }
     
        if (hDC && !ReleaseDC(hWnd,hDC))                    // Are We Able To Release The DC
        {
            MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            hDC=NULL;                                        // Set DC To NULL
        }
     
        if (hWnd && !DestroyWindow(hWnd))                    // Are We Able To Destroy The Window?
        {
            MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            hWnd=NULL;                                        // Set hWnd To NULL
        }
     
        if (!UnregisterClass("OpenGL",hInstance))            // Are We Able To Unregister Class
        {
            MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            hInstance=NULL;                                    // Set hInstance To NULL
        }
    }
     
    /*    This Code Creates Our OpenGL Window.  Parameters Are:                    *
     *    title            - Title To Appear At The Top Of The Window                *
     *    width            - Width Of The GL Window Or Fullscreen Mode                *
     *    height            - Height Of The GL Window Or Fullscreen Mode            *
     *    bits            - Number Of Bits To Use For Color (8/16/24/32)            *
     *    fullscreenflag    - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)    */
     
    BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
    {
        GLuint        PixelFormat;            // Holds The Results After Searching For A Match
        WNDCLASS    wc;                        // Windows Class Structure
        DWORD        dwExStyle;                // Window Extended Style
        DWORD        dwStyle;                // Window Style
        RECT        WindowRect;                // Grabs Rectangle Upper Left / Lower Right Values
        WindowRect.left=(long)0;            // Set Left Value To 0
        WindowRect.right=(long)width;        // Set Right Value To Requested Width
        WindowRect.top=(long)0;                // Set Top Value To 0
        WindowRect.bottom=(long)height;        // Set Bottom Value To Requested Height
     
        fullscreen=fullscreenflag;            // Set The Global Fullscreen Flag
     
        hInstance            = GetModuleHandle(NULL);                // Grab An Instance For Our Window
        wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;    // Redraw On Size, And Own DC For Window.
        wc.lpfnWndProc        = (WNDPROC) WndProc;                    // WndProc Handles Messages
        wc.cbClsExtra        = 0;                                    // No Extra Window Data
        wc.cbWndExtra        = 0;                                    // No Extra Window Data
        wc.hInstance        = hInstance;                            // Set The Instance
        wc.hIcon            = LoadIcon(NULL, IDI_WINLOGO);            // Load The Default Icon
        wc.hCursor            = LoadCursor(NULL, IDC_ARROW);            // Load The Arrow Pointer
        wc.hbrBackground    = NULL;                                    // No Background Required For GL
        wc.lpszMenuName        = NULL;                                    // We Don't Want A Menu
        wc.lpszClassName    = "OpenGL";                                // Set The Class Name
     
        if (!RegisterClass(&wc))                                    // Attempt To Register The Window Class
        {
            MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                            // Return FALSE
        }
     
        if (fullscreen)                                                // Attempt Fullscreen Mode?
        {
            DEVMODE dmScreenSettings;                                // Device Mode
            memset(&dmScreenSettings,0,sizeof(dmScreenSettings));    // Makes Sure Memory's Cleared
            dmScreenSettings.dmSize=sizeof(dmScreenSettings);        // Size Of The Devmode Structure
            dmScreenSettings.dmPelsWidth    = width;                // Selected Screen Width
            dmScreenSettings.dmPelsHeight    = height;                // Selected Screen Height
            dmScreenSettings.dmBitsPerPel    = bits;                    // Selected Bits Per Pixel
            dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
     
            // Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
            if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
            {
                // If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
                if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
                {
                    fullscreen=FALSE;        // Windowed Mode Selected.  Fullscreen = FALSE
                }
                else
                {
                    // Pop Up A Message Box Letting User Know The Program Is Closing.
                    MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
                    return FALSE;                                    // Return FALSE
                }
            }
        }
     
        if (fullscreen)                                                // Are We Still In Fullscreen Mode?
        {
            dwExStyle=WS_EX_APPWINDOW;                                // Window Extended Style
            dwStyle=WS_POPUP;                                        // Windows Style
            ShowCursor(FALSE);                                        // Hide Mouse Pointer
        }
        else
        {
            dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;            // Window Extended Style
            dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows Style
        }
     
        AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);        // Adjust Window To True Requested Size
     
        // Create The Window
        if (!(hWnd=CreateWindowEx(    dwExStyle,                            // Extended Style For The Window
                                    "OpenGL",                            // Class Name
                                    title,                                // Window Title
                                    dwStyle |                            // Defined Window Style
                                    WS_CLIPSIBLINGS |                    // Required Window Style
                                    WS_CLIPCHILDREN,                    // Required Window Style
                                    0, 0,                                // Window Position
                                    WindowRect.right-WindowRect.left,    // Calculate Window Width
                                    WindowRect.bottom-WindowRect.top,    // Calculate Window Height
                                    NULL,                                // No Parent Window
                                    NULL,                                // No Menu
                                    hInstance,                            // Instance
                                    NULL)))                                // Dont Pass Anything To WM_CREATE
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        static    PIXELFORMATDESCRIPTOR pfd=                // pfd Tells Windows How We Want Things To Be
        {
            sizeof(PIXELFORMATDESCRIPTOR),                // Size Of This Pixel Format Descriptor
            1,                                            // Version Number
            PFD_DRAW_TO_WINDOW |                        // Format Must Support Window
            PFD_SUPPORT_OPENGL |                        // Format Must Support OpenGL
            PFD_DOUBLEBUFFER,                            // Must Support Double Buffering
            PFD_TYPE_RGBA,                                // Request An RGBA Format
            bits,                                        // Select Our Color Depth
            0, 0, 0, 0, 0, 0,                            // Color Bits Ignored
            0,                                            // No Alpha Buffer
            0,                                            // Shift Bit Ignored
            0,                                            // No Accumulation Buffer
            0, 0, 0, 0,                                    // Accumulation Bits Ignored
            16,                                            // 16Bit Z-Buffer (Depth Buffer)  
            0,                                            // No Stencil Buffer
            0,                                            // No Auxiliary Buffer
            PFD_MAIN_PLANE,                                // Main Drawing Layer
            0,                                            // Reserved
            0, 0, 0                                        // Layer Masks Ignored
        };
     
        if (!(hDC=GetDC(hWnd)))                            // Did We Get A Device Context?
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))    // Did Windows Find A Matching Pixel Format?
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        if(!SetPixelFormat(hDC,PixelFormat,&pfd))        // Are We Able To Set The Pixel Format?
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        if (!(hRC=wglCreateContext(hDC)))                // Are We Able To Get A Rendering Context?
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        if(!wglMakeCurrent(hDC,hRC))                    // Try To Activate The Rendering Context
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        ShowWindow(hWnd,SW_SHOW);                        // Show The Window
        SetForegroundWindow(hWnd);                        // Slightly Higher Priority
        SetFocus(hWnd);                                    // Sets Keyboard Focus To The Window
        ReSizeGLScene(width, height);                    // Set Up Our Perspective GL Screen
     
        if (!InitGL())                                    // Initialize Our Newly Created GL Window
        {
            KillGLWindow();                                // Reset The Display
            MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;                                // Return FALSE
        }
     
        return TRUE;                                    // Success
    }
     
    LRESULT CALLBACK WndProc(    HWND    hWnd,            // Handle For This Window
                                UINT    uMsg,            // Message For This Window
                                WPARAM    wParam,            // Additional Message Information
                                LPARAM    lParam)            // Additional Message Information
    {
        switch (uMsg)                                    // Check For Windows Messages
        {
            case WM_ACTIVATE:                            // Watch For Window Activate Message
            {
                // LoWord Can Be WA_INACTIVE, WA_ACTIVE, WA_CLICKACTIVE,
                // The High-Order Word Specifies The Minimized State Of The Window Being Activated Or Deactivated.
                // A NonZero Value Indicates The Window Is Minimized.
                if ((LOWORD(wParam) != WA_INACTIVE) && !((BOOL)HIWORD(wParam)))
                    active=TRUE;                        // Program Is Active
                else
                    active=FALSE;                        // Program Is No Longer Active
     
                return 0;                                // Return To The Message Loop
            }
     
            case WM_SYSCOMMAND:                            // Intercept System Commands
            {
                switch (wParam)                            // Check System Calls
                {
                    case SC_SCREENSAVE:                    // Screensaver Trying To Start?
                    case SC_MONITORPOWER:                // Monitor Trying To Enter Powersave?
                    return 0;                            // Prevent From Happening
                }
                break;                                    // Exit
            }
     
            case WM_CLOSE:                                // Did We Receive A Close Message?
            {
                PostQuitMessage(0);                        // Send A Quit Message
                return 0;                                // Jump Back
            }
     
            case WM_KEYDOWN:                            // Is A Key Being Held Down?
            {
                keys[wParam] = TRUE;                    // If So, Mark It As TRUE
                return 0;                                // Jump Back
            }
     
            case WM_KEYUP:                                // Has A Key Been Released?
            {
                keys[wParam] = FALSE;                    // If So, Mark It As FALSE
                return 0;                                // Jump Back
            }
     
            case WM_SIZE:                                // Resize The OpenGL Window
            {
                ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
                return 0;                                // Jump Back
            }
        }
     
        // Pass All Unhandled Messages To DefWindowProc
        return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
     
    int WINAPI WinMain(    HINSTANCE    hInstance,            // Instance
                        HINSTANCE    hPrevInstance,        // Previous Instance
                        LPSTR        lpCmdLine,            // Command Line Parameters
                        int            nCmdShow)            // Window Show State
    {
        MSG        msg;                                    // Windows Message Structure
        BOOL    done=FALSE;                                // Bool Variable To Exit Loop
     
        // Ask The User Which Screen Mode They Prefer
        //if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
        {
            fullscreen=FALSE;                            // Windowed Mode
        }
     
        // Create Our OpenGL Window
        if (!CreateGLWindow("NeHe's Solid Object Tutorial",640,480,16,fullscreen))
        {
            return 0;                                    // Quit If Window Was Not Created
        }
     
        while(!done)                                    // Loop That Runs While done=FALSE
        {
            if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))    // Is There A Message Waiting?
            {
                if (msg.message==WM_QUIT)                // Have We Received A Quit Message?
                {
                    done=TRUE;                            // If So done=TRUE
                }
                else                                    // If Not, Deal With Window Messages
                {
                    TranslateMessage(&msg);                // Translate The Message
                    DispatchMessage(&msg);                // Dispatch The Message
                }
            }
            else                                        // If There Are No Messages
            {
                // Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
                if ((active && !DrawGLScene()) || keys[VK_ESCAPE])    // Active?  Was There A Quit Received?
                {
                    done=TRUE;                            // ESC or DrawGLScene Signalled A Quit
                }
                else                                    // Not Time To Quit, Update Screen
                {
                    SwapBuffers(hDC);                    // Swap Buffers (Double Buffering)
                }
     
                if (keys[VK_F1])                        // Is F1 Being Pressed?
                {
                    keys[VK_F1]=FALSE;                    // If So Make Key FALSE
                    KillGLWindow();                        // Kill Our Current Window
                    fullscreen=!fullscreen;                // Toggle Fullscreen / Windowed Mode
                    // Recreate Our OpenGL Window
                    if (!CreateGLWindow("NeHe's Solid Object Tutorial",640,480,16,fullscreen))
                    {
                        return 0;                        // Quit If Window Was Not Created
                    }
                }
     
            }
        }
     
        // Shutdown
        KillGLWindow();                                    // Kill The Window
        return (msg.wParam);                            // Exit The Program
    }


    ^^


  8. #8
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    126

    Re: Light at objects

    Sorry for this long post, I solved it. nvemulate "destroyed" my shaders


    ^^


  9. #9
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Light at objects

    Why are you using nvemulate?
    What kind of hardware are you using?
    With the new drivers and nv8xxx cards you do not need to unlock any functionality. Everything works perfectly!

    Alert: Don't install 195.39. OpenCL cease to function.
    Maybe the problem is in the fact that I kept some dlls that are newer than the installation offered. Who knows...

  10. #10
    Member Contributor
    Join Date
    May 2009
    Posts
    57

    Re: Light at objects

    Sorry to just say this but there is a way to have more than 8 lights on the scene: Using a deferred renderer.
    This is more complicated but once you set it up it works ok.
    In my tests I have like 4000 lights on screen at a decent FPS (without shadows).

Page 1 of 3 123 LastLast

Similar Threads

  1. Light-emitting objects
    By Capgl in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-03-2012, 06:01 PM
  2. Transform light sources when transforming objects?
    By _misq in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 06-05-2011, 11:27 AM
  3. light for translucent objects
    By kazmalak in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-14-2005, 11:12 AM
  4. light objects
    By zen in forum OpenGL: General
    Replies: 3
    Last Post: 07-20-2004, 02:50 AM
  5. Light objects, material objects
    By vincoof in forum OpenGL: General
    Replies: 4
    Last Post: 05-11-2003, 11:27 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