Creating a quadrilateral using interleaved vertices in three.js

Why does three.js keep complaining about 'tex' not being a 'WebGLTexture' when I try to draw a quad? Any insights on this issue would be greatly appreciated. Thank you.

// z= depth, tex is texture
function drawQuad(z, tex)
{
  var verts = [      
    -1.0,  1.0, z, 0.0, 1.0,
    -1.0, -1.0, z, 0.0, 0.0,
    1.0,  1.0, z, 1.0, 1.0,
    1.0, -1.0, z, 1.0, 0.0,      
  ];    

  const gl = renderer.getContext();  

  gl.disable(gl.DEPTH_TEST);

  gl.useProgram(quadShader);

  var vb = gl.createBuffer();
  gl.bindBuffer(gl.ARRAY_BUFFER, vb);
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verts), gl.STATIC_DRAW);    

  gl.bindBuffer(gl.ARRAY_BUFFER, vb);

  gl.enableVertexAttribArray(0);  
  gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 20, 0);

  gl.enableVertexAttribArray(1);  
  gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 20, 12);  

  gl.uniform1i(gl.getUniformLocation(quadShader, 'su_tex'), 0)
  gl.activeTexture(gl.TEXTURE0 + 0);     
  gl.bindTexture(gl.TEXTURE_2D, tex);   

  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4) 
  
  gl.enable(gl.DEPTH_TEST);
}

The 'tex' variable is loaded in the following manner:

wallTex = loader.load("https://r105.threejsfundamentals.org/threejs/resources/images/wall.jpg");
drawQuad(1.0, wallTex);

Answer №1

Alright, I've cracked the code.

For those still scratching their heads (especially C++ OpenGL programmers), here's a helpful tidbit:

  1. The WebGlTexture is essentially the ID you generate with glGenTextures(1, &texturId), specifically used for rendering purposes.

  2. On the flip side, the THREE.js.Texture serves as a container for textures, housing descriptive information and image data sourced from the web or elsewhere. It comes with a hidden property known as __webglTexture that remains null until the THREE.js.Texture is put to use for rendering. Once employed, it dynamically creates a WebGLTexture (likely through an internal call to glGenTextures(1, &textureId)), assigning the ID of this WebGlTexture to its __webglTexture. From there, it becomes fair game for rendering operations.

Personally, I believe THREE.js.Texture may warrant a name change to something like THREE.js.TextureRes - less room for confusion, if you ask me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Detecting the Escape key when the browser's search bar is open - a step-by-step guide

One feature on my website is an editor window that can be closed using the Escape key. The functionality is implemented in JavaScript: $(document).keyup( function(e) { // Closing editor window with ESCAPE KEY if(e.which == 27) { // Clic ...

Sending a JSON object as a map through AJAX to an MVC controller

I am looking to send a map (dictionary) to the MVC controller along with a string parameter. var reportName= 'ReportName'; var FilterValues = new Map([ [0, "value1"], [1, "value2"], [2, "value3"], ]); var model = { reportName: reportName, ...

Help needed with PHP, MYSQL, and AJAX! Trying to figure out how to update a form dynamically without triggering a page refresh. Can anyone

Hey there! I'm fairly new to the world of dynamically updating databases without needing a page refresh. My goal is to build something similar to The end result I'm aiming for includes: Dynamically generating fields (Done) Loading existing dat ...

Tips for addressing the issue - error TS2451: Unable to redefine block-specific variable 'total'

I am currently working on setting up the Jest testing framework and running a basic test (using an example from jestjs.io). Here is the content of the sum.ts file: function sum(a: any, b: any):any { return a + b; } module.exports = sum; And here is the ...

Tips for streamlining distinct states and generalized state in UI Router

I've set up the following configuration in my JS app under the $stateProvider section using angular ui-router: .state('login', { url: '/login', templateUrl: 'app/login/login.tmpl.html', controller: &apo ...

Compatibility of image maps with browsers and the usage of imagemapster

Currently, I am utilizing ImageMapster to make adjustments to an image map while hovering. However, I am facing challenges with both the image map itself and the ImageMapster plugin. The issues I am encountering are: 1) Despite specifying a height and wid ...

Texture of poor quality - 256 x 256 dimensions loaded using RGBELoader

I'm facing an issue where RGBELoader() is generating 256x256 textures regardless of the source resolution being 4k. I attempted to use the pmremGenerator, but it doesn't seem to make a difference. new RGBELoader() .setPath( ' ...

Steps for triggering a click event on a div with a button role within a class containing multiple elements

Can anyone help me figure out how to auto-click every button in Instagram's "hide story from" settings using console? I tried the following code: for (let i = 0; i < 300; i++) { document.getElementsByClassName('wbloks_1')[i] ...

Creating Unique Designs with Multiple Shapes and Elements using Clipping Masks

I have a design piece to create that I initially built using three separate square div containers with independent background images. However, this method feels rigid to me as it requires chopping up and restaging a new image each time it needs to be chang ...

Looking for help understanding a basic piece of code

$('#ID').on('click', function() { if(!CommonUtil.compareDateById('startDt','endDt',false, false, true)) { return false; } var cnt = 0; if(!CommonUtil.isNullOrEmptyById('startD ...

Learning the ropes: Building a model with nodejs using tensorflow.js

I am interested in creating an image classifier, but I lack knowledge of python. Since I am familiar with javascript, I have been considering using Tensorflow.js. Can models be trained with Tensorflow.js, and if so, what are the steps involved in the proce ...

Expanding the dropdown menu depending on the selection of the radio button

I am looking to implement a feature where the drop-down option is displayed or hidden based on the selection of a radio button in AngularJS. If the "Overall Company" radio button is selected, then the drop-down element should not be shown. If the "Demogra ...

JavaScript - Utilizing an image file in relation to a URL pathway

Is there a way to reference an image URL using a relative path in a JavaScript file similar to CSS files? To test this, I created two divs and displayed a gif in the background using CSS in one and using JavaScript in the other: -My file directory struct ...

How can I resolve the issue of the mouse x/y glitch while drawing on an HTML canvas using JavaScript/jQuery?

I've been searching all over for a solution to this issue, but I just can't seem to find out what's causing the problem... This is my first attempt at working on something like this in my spare time. I hope to apply what I learn to create a ...

Adjust the vertical size of the slider in Jssor

Hi there! I'm currently working on a slider that I want to have a dynamic width (100% of the container) and a static height of 550px on PCs, while being responsive on mobile devices. Below is my code snippet: <div class="col-md-6 right-col" id="sl ...

`How can I use lodash to filter an array based on any matching value?`

I have a collection of objects and I need to search for instances where certain properties match specific values. Here is an example array: let arr = [ { a: 'foo', b: 'bar' }, { a: 'bar', ...

Contrasting the process of generating DOM elements by using createElement, setting properties, etc., versus constructing a string of elements and then appending them

I am curious about the distinction between these two methods for creating HTML elements. I cannot seem to find any difference. I simply want to understand if there are any variations based on performance or any other factors. The first technique involves ...

404 Response Generated by Express Routes

Exploring the MEAN stack has been a great way for me to expand my knowledge of node and express. Currently, I am working on creating a simple link between two static pages within the app. My routes are set up as follows: //Home route var index = require( ...

summing 3 numbers to a total of 100 percent

I am currently trying to calculate the percentages of different statuses based on 3 count values. Let's assume I have 3 statuses: 1) Passed 2) Failed 3) Skipped When dealing with only two cases, I was able to use a combination of the Floor and Ceil ...

Having difficulty replicating the same effect across all five canvas elements

After following the code provided by j08691 here for canvas, everything worked flawlessly. However, I encountered an error in JavaScript when trying to implement it on multiple canvas elements. As a beginner in JavaScript, I would greatly appreciate any as ...