简体   繁体   English

在OpenGL场景中创建聚光灯

[英]Creating spotlight in OpenGL scene

I'm studying OpenGL and trying to create a spot light at my application. 我正在研究OpenGL并试图在我的应用程序中创建聚光灯。 The code that I'm using for my #vertex-shader is shown below: 我用于#vertex-shader的代码如下所示:

    #: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: 我想创建这个聚光灯非常简单,但是由于我是OpenGL新手,所以直到现在我都不知道该如何做,甚至阅读以下资料:

http://www.glprogramming.com/red/chapter05.html#name3 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. 然后,由于某种原因,我无法理解您尝试在着色器中调用已弃用的旧样式固定功能OpenGL状态设置程序函数。 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. 我建议您先阅读一个不错的OpenGL教程,并从头开始研究它,而不必跳过任何事情。 I suggest http://arcsynthesis.org/gltut 我建议http://arcsynthesis.org/gltut

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM