简体   繁体   English

WebGL texParami设置导致纹理渲染为黑色

[英]WebGL texParami setting causing Textures to render to black

So this question is related to a previous post made at https://gamedev.stackexchange.com/questions/38829/webgl-texture-appears-as-black 因此,该问题与先前在https://gamedev.stackexchange.com/questions/38829/webgl-texture-appears-as-black上发布的帖子有关

I was having problems rendering a texture http://www.html5canvastutorials.com/cookbook/ch9/1369_09_06/crate.jpg , which is an even power of 2 (despite the changes recommended in the previous post) 我在渲染纹理http://www.html5canvastutorials.com/cookbook/ch9/1369_09_06/crate.jpg时遇到问题,这是2的偶数幂(尽管在上一篇文章中建议进行更改)

I put a fork on JSFiddle , and after playing around with several images, it seems some textures render and some do not. 我在JSFiddle上放了一个叉子,玩了几张图像之后,似乎有些纹理可以渲染,而有些则不可以。 Specifically this is detailed in the code 具体在代码中有详细说明

image.src = 'https://lh4.googleusercontent.com/-Y2gO2Ex8Q10/T588LBJKq7I/AAAAAAAAgzc/XKpph-vQWiw/s686/_DSC4127+-+Version+2.jpg';   
// The original texture runs fine

image.src = 'http://webglfundamentals.org/webgl/resources/f-texture.png'
// As does this texure from WebGLFundamentals

image.src = 'http://www.html5canvastutorials.com/cookbook/ch9/1369_09_06/crate.jpg';
// But the crate texture does not want to show

image.src = 'https://dev.opera.com/articles/raw-webgl-part-2-simple-shader/figure3.png'
// Neither does this Red-Green-Yellow gradient

What am I missing in the JSFiddle code terms of being able to render the texture correctly? 我在JSFiddle代码中缺少能够正确渲染纹理的内容吗?

I know its NOT an issue with the image and it must be a setting somewhere since its working correctly at the page located at http://www.html5canvastutorials.com/cookbook/ch9/1369_09_06/ 我知道它与图片无关,它必须是某个设置,因为它在http://www.html5canvastutorials.com/cookbook/ch9/1369_09_06/

Any help would be greatly appreciated!! 任何帮助将不胜感激!!

Thanks. 谢谢。

You have a problem with Cross-Origin Resource Sharing . 跨域资源共享存在问题。

In dev-tools console output you can see: 在dev-tools控制台输出中,您可以看到:

Image from origin 'http://www.html5canvastutorials.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.

For security reasongs, you are only allowed to load images from your own domain or from those who specifically allow it, by setting the Access-Control-Allow-Origin header. 出于安全原因,只允许通过设置Access-Control-Allow-Origin标头从您自己的域或专门允许它的域中加载图像。

Only images on lh4.googleusercontent.com and dev.opera.com return with the header Access-Control-Allow-Origin: * and are the only ones that work. 只有lh4.googleusercontent.comdev.opera.com上的图像以标题Access-Control-Allow-Origin: *并且是唯一起作用的图像。

You will need to host the images on your own server, or if you need to load from and arbitrary URL you will need an image proxy on your server. 您将需要在自己的服务器上托管图像,或者如果需要从任意URL加载图像,则服务器上将需要图像代理。

If you are just playing with WebGL, you can use crossorigin.me and use your image as: 如果您只是在玩WebGL,则可以使用crossorigin.me并将图像用作:

http://crossorigin.me/http://www.html5canvastutorials.com/cookbook/ch9/1369_09_06/crate.jpg

You can read more about CORS here and here . 您可以在此处此处阅读有关CORS的更多信息。

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

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