Course evaluation By now you should have received an invitation to provide a course evaluation. If you have not received an invitation, or have technical difficulty accessing the link, I encourage you to contactOverview Today we mostly focused on texture mapping, but first we finished the work on sliders. Where we had left things off in our previous lecture, the sliders neglected to update properly when the user switched to a different object.Restoring sliders We made sure that the slider values for the selected object are kept up to date even when the user selects a different object. We did this by adding the following code at the end of the animate function:Texture mappingif (selectedObject) { rotateXSlider.value = 50 * selectedObject.rotate[0] + 50; rotateYSlider.value = 50 * selectedObject.rotate[1] + 50; rotateZSlider.value = 50 * selectedObject.rotate[2] + 50; scaleXSlider.value = 25 * selectedObject.scale[0]; scaleYSlider.value = 25 * selectedObject.scale[1]; scaleZSlider.value = 25 * selectedObject.scale[2]; } For the remainder of the class we focused on texture mapping. This involved a number of steps:● Creating a GUI for the user We added code that paralleled the code for creating shapes. This provided a set of buttons, one for each choice of texture, to describe what texture to use when creating a new object.● Placing a source image in our folder I provided just● Starting a localhost Web server We browsers do not normally allow you to access local files on your computer, for security reasons. Therefore in order to do development on your own computer that involves loading texture images, you need to make the browser think it is talking to a Web server.● adding behavior to canvas1.onRelease()
to handle texture when objects are
created or clicked on, respectivelyIn the places in ,,canvas1.onRelease();; where we create a new object or modify the color of ane existing object, we added code to also attach the currently specified texture to the object.● Understanding how Mipmapping works I described how Mipmapping works. In the coming days I will put more detail about that into these course notes.● Loading a texture image file in lib10.js We added the following code to the place in the library where a triangle mesh shape is actually rendered:● Handling texture in the fragment shader// INDICATE TO THE FRAGMENT SHADER THAT WE WILL BE TEXTURING THIS OBJECT setUniform('1f', 'uTexture', this.textureSrc ? 1 : 0); if (this.textureSrc) if (! this.texture) { // INITIALIZATION: ASYNCHRONOUSLY LOAD THE IMAGE FILE AND BUILD THE TEXTURE. let image = new Image(); image.onload = function() { gl.bindTexture (gl.TEXTURE_2D, this.obj.texture = gl.createTexture()); gl.texImage2D (gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this); gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST); gl.generateMipmap(gl.TEXTURE_2D); gl.bindTexture(gl.TEXTURE_2D, null); }; image.obj = this; image.src = this.textureSrc; } else { // ONCE THE TEXTURE HAS BEEN INITIALIZED: TELL THE FRAGMENT SHADER TO USE IT. gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, this.texture); setUniform('1i', 'uSampler', 0); } In order for all of this to work, we needed to declare the following uniform variables in the fragment shader:Downloadable codeuniform float uTexture; // DO WE SHOW THE TEXTURE? uniform sampler2D uSampler; // SAMPLE THE TEXTURE USING vUV.Then in The code for all of this is in hw10.zip.Homework: Final project proposal By the end of this coming weekend, please put up onto your website your proposal for a final project. You can do anything reasonable for this project. Think of the "expected amount of work" as around the same as two weekly assignments. |