我试图访问我的jar文件中的目录.我想浏览目录中的每个文件.我试过,例如,使用以下内容:
URL imagesDirectoryURL=getClass().getClassLoader().getResource("Images");
if(imagesFolderURL!=null)
{
File imagesDirectory= new File(imagesDirectoryURL.getFile());
}
Run Code Online (Sandbox Code Playgroud)
如果我测试这个小程序,它运行良好.但是,一旦我把内容放入罐子里,它就不会因为几个原因了.如果我使用此代码,则URL始终指向jar外部,因此我必须将Images目录放在那里.但是,如果我使用new File(imagesDirectoryURL.toURI());它,它在jar内部不起作用,因为我得到了错误URI not hierarchical.我确定该目录存在于jar中.我怎么能得到Imagesjar里面的内容?
如果我的vec4为NULL,我正在尝试检查着色器(GLSL)内部.我需要这个有几个原因,主要是为了让特定的显卡兼容,因为它们中的一些在gl_FragColor中传递了前一种颜色,而有些则没有(提供需要覆盖的空vec4).好吧,在一台相当新的Mac上,有人遇到了这个错误:
java.lang.RuntimeException: Error creating shader: ERROR: 0:107: '==' does not operate on 'vec4' and 'int'
ERROR: 0:208: '!=' does not operate on 'mat3' and 'int'
Run Code Online (Sandbox Code Playgroud)
这是我在片段着色器中的代码:
void main()
{
if(gl_FragColor == 0) gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); //Line 107
vec4 newColor = vec4(0.0, 0.0, 0.0, 0.0);
[...]
if(inverseViewMatrix != 0) //Line 208
{
[do stuff with it; though I can replace this NULL check with a boolean]
}
[...]
gl_FragColor.rgb = mix(gl_FragColor.rgb, newColor.rgb, newColor.a);
gl_FragColor.a += newColor.a;
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我在开始时对gl_FragColor进行了0/NULL检查,因为有些图形卡会在那里传递有价值的信息,但有些则没有.现在,在那个特殊的mac上,它没有用.我做了一些研究,但找不到有关如何在GLSL中进行正确的NULL检查的任何信息.有没有,或者我真的需要在这里制作单独的着色器吗?