سؤال

I'm studying OpenGL and trying to create a spot light at my application. The code that I'm using for my #vertex-shader is shown below:

    #:vertex-shader #{
        #version 150 core
            in vec3 in_pos;
            in vec2 in_tc;
            out vec2 tc;

            glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 20.0f);
            GLfloat spot_direction[] = { -1.0, -1.0, 0.0 };
            glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);

            glEnable(GL_LIGHT0);


            void main() {

                vec4 pos= vec4(vec3(1.0)*in_pos - vec3(1.0), 1.0);
                pos.z=0.0;
                gl_Position =   pos;
                tc = in_tc;
            }
}

The thing is, every time I'm trying to run the code an Error that says:

Type: other, Source: api, ID: 131169, Severity: low
Message: Framebuffer detailed info: The driver allocated storage for renderbuffer 1.
 len = 157, written = 0
failed to compile vertex shader of deferred: directional
info log for shader deferred: directional
vertex info log for shader deferred: directional:
ERROR: Unbound variable: when

Specifications:

Renderer: GeForce GTX 580/PCIe/SSE2
Version: 3.3.0 NVIDIA 319.17
GLSL: 3.30 NVIDIA via Cg compiler
Status: Using GLEW 1.9.0
1024 x 768
OS: Linux debian

I guess to create this spotlight is pretty much simple, but since I'm really new to OpenGL I don't have a clue how to do it until now, even reading sources like:

http://www.glprogramming.com/red/chapter05.html#name3

Read also in some place that light spots can get really hard to understand, but I cant avoid this step right now since I'm following my lecture schedule. Could anybody help me?

هل كانت مفيدة؟

المحلول

You completely, totally misunderstood what shaders do. First of all you're declaring function calls in the global scope, which is disallowed anyway. And then, for some reason I cannot fathom you try to call deprecated, old style, fixed function OpenGL state setter functions in the shader. This is not how it works.

I suggest you head to a decent OpenGL tutorial, and work through it from the beginning without skipping things. I suggest http://arcsynthesis.org/gltut

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top