Results 1 to 4 of 4

Thread: (Lighting) behaviour different at each execution

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    3

    (Lighting) behaviour different at each execution

    Hi

    I feel I've been quite successful last few days, getting my OpenGL application up and running, with textures and lights and colors and all, thanks to a great deal of very helpful documentation on the interweb. But I can find no mention on google, these forums, the FAQ or common problems lists, or elsewhere, of the particular issue I'm running into now.

    My application (I won't post code at this stage, but it follows typical form from OpenGL examples, and I don't _think_ it's relevant to the issue) uses SDL to open a window with an OpenGL context. Then it does the usual basic stuff, rendering a surface with a bunch of vertices with normals, and a single light set up above it, to produce nice lit terrain. All works fine.

    Sometimes. This is the issue - on some executions, it does what is expected. On some executions, the light is in the wrong place. On some, the light is entirely absent (or perhaps under the surface so I can't see its effects).

    So the question is - how can the behaviour of my application be different on different instantiations? I am very willing to believe that this is an SDL-specific issue; I've searched for it under that assumption and also turned up nothing, so I figured I would eliminate it as an OpenGL issue first.

    I've taken every care I can to ensure that it is not a threading issue (though it certainly sounds like one). I make sure that my OpenGL context is open and fully created (going so far as to pause for a second) before I make any calls to OpenGL from my own code. The only thread that is calling GL functions is my applications's main thread (the only other thread is whatever SDL is running in the background, and that is only servicing keyboard events).

    It may be helpful to note that everything seems to work exactly correctly _except_ the lighting, and that is quite entirely variable. I can't make it go one way or the other by starting the application from a prompt (which slows it down a bit through the use of stdout) or by double-click, or through the IDE. I just can't get any hints out of it at all as to the cause .

    Thus, I'm hoping only that someone has ever heard of such a thing. I have googled until I'm blue in the face, and seen no mention of it. In case it's a known bug in my card or drivers, my platform is Windows 7, GeForce 8600GT, OpenGL supplied by MS SDK.

    Thanks, in advance
    hangdog

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    3

    Re: (Lighting) behaviour different at each execution

    PS. Of course, if this is not an SDL issue, an obvious possibility is that I'm using OpenGL incorrectly, for instance issuing my initialise or in-loop commands in the wrong order. If that seems likely, I can of course post code.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    3

    Re: (Lighting) behaviour different at each execution

    (SOLVED)

    Meantime, I've been bashing through my code again and again. Finally spotted the problem. In case anyone else makes the same dumb mistake as me:

    I was using glLightfv to set the light position, and I was not providing four elements but only three (thinking three was enough, and having read the docs with my eyes closed, apparently). Presumably, the remaining element was being initialised to something random, hence the unpredictable behaviour.

    If I've learned something about OpenGL it's that I must remember that the interface is C not C++, so things that compile may be far from things that will run correctly. So, I promise to always read the API specification carefully, particularly when passing pointers to data.

    Thanks

  4. #4
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: (Lighting) behaviour different at each execution

    This would have been a UMR (uninitialized memory read) setting the light vector w component to some unknown value.

    A UMRs like this can go undetected in C and C++, since you're just sending a pointer to an array of implied dimension.

Similar Threads

  1. SIMD execution
    By zje in forum OpenCL
    Replies: 2
    Last Post: 04-06-2012, 11:22 PM
  2. Replies: 3
    Last Post: 03-24-2012, 06:35 AM
  3. The execution in GPU is not the same that CPU
    By luizdrumond in forum OpenCL
    Replies: 3
    Last Post: 09-02-2011, 04:00 PM
  4. Weird behaviour with lighting and display lists...
    By ahkcasfm in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 05-05-2009, 11:14 PM
  5. Execution causes two Windows to pop up
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-28-2002, 11:31 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
  •  
Proudly hosted by Digital Ocean