पिक्सेल सरणी के साथ बनावट बनाना बिल्कुल संभव है! मैं एक ही पिक्सेल, ठोस रंग बनावट बनाने के लिए हर समय अपने कोड में निम्नलिखित का उपयोग करता हूं।
function createSolidTexture(gl, r, g, b, a) {
var data = new Uint8Array([r, g, b, a]);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
return texture;
}
संपादित करें: अनुमान लगाना इस थोड़ा आगे, क्या आप जानना चाहते हैं के सबसे gl.texImage2d
कॉल में है। कच्चे आरजीबी (ए) डेटा से बनावट बनाने के लिए आपको बिना हस्ताक्षरित बाइट मानों की एक सरणी की आवश्यकता होती है, आपको वेबजीएल को निर्दिष्ट करना होगा कि डेटा क्या दर्शाता है (आरजीबी या आरजीबीए), और आपको बनावट के आयामों को जानने की आवश्यकता है। एक अधिक सामान्यीकृत कार्य इस तरह दिखेगा:
function textureFromPixelArray(gl, dataArray, type, width, height) {
var dataTypedArray = new Uint8Array(dataArray); // Don't need to do this if the data is already in a typed array
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, type, width, height, 0, type, gl.UNSIGNED_BYTE, dataTypedArray);
// Other texture setup here, like filter modes and mipmap generation
return texture;
}
// RGB Texture:
// For a 16x16 texture the array must have at least 768 values in it (16x16x3)
var rgbTex = textureFromPixelArray(gl, [r,g,b,r,g,b...], gl.RGB, 16, 16);
// RGBA Texture:
// For a 16x16 texture the array must have at least 1024 values in it (16x16x4)
var rgbaTex = textureFromPixelArray(gl, [r,g,b,a,r,g,b,a...], gl.RGBA, 16, 16);
क्षमा करें शायद यह स्पष्ट नहीं था कि मेरा क्या मतलब था। मैंने क्यू – alex
अपडेट किया है यदि आपका डेटा ऐरेबफर में है तो आप वेबजीएल से एक फ़ंक्शन का उपयोग कर सकते हैं (जिसे मुझे अभी याद नहीं है) – Chiguireitor
@Chiguireitor क्या आप शायद मुझे एक सरणी बफर बनाने के तरीके पर एक उदाहरण दे सकते हैं? – alex