首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Math.random()未声明的标识符

Math.random()未声明的标识符
EN

Stack Overflow用户
提问于 2014-09-16 14:31:00
回答 1查看 708关注 0票数 0

我试图在我的片段着色器中生成随机颜色,但我遇到了编译器错误。下面是我的代码:

代码语言:javascript
复制
    <!--here is where the color is set-->
    <script id="fragment-shader" type="x-shader/x-fragment">

    precision mediump float;

    void
    main()
    {
        float red = Math.random();
        float green = 0.5;
        float blue = 0.7;
        gl_FragColor = vec4( red, green, blue, 1.0 );
    }
    </script><!--here is where the color is set-->

下面是我得到的错误:

代码语言:javascript
复制
    Fragment shader failed to compile.  The error log is:<pre>ERROR: 0:8: 'Math' : undeclared identifier 
    ERROR: 0:8: '' : methods are not supported 
    ERROR: 0:8: 'random' : no matching overloaded function found 
    </pre>

我对HMTL、WebGL和Javascript都是新手,我不知道是什么破坏了它,也不知道为什么。为什么我无法使用Math.random?

EN

回答 1

Stack Overflow用户

发布于 2014-09-16 22:24:26

Math是一个JavaScript对象,着色器是用GLSL编写的。

要在GLSL中生成随机数,请参阅@asimes的评论。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25862006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档