3D Gallery with Great Artwork Imagine Logo with Three Colors Beach Cabin 3D Android Tablet with Different Screens Studio Apartment Red Figured Greek Vase on Blue Background Silver and Gold Flashlight Lake on Fire

Framebuffer Beginner's Guide Source Code

WebGL Framebuffer with Texture Color Attachment

Framebuffer Example Background Colors Change Framebuffer Beginner's Guide Initialize the Framebuffer Render One Frame Texture for Interactive Square

JavaScript

/**
* Framebuffer with just one
* texture color attachment.
* 
* @param s: String path to image file.
*/
var GLFbTexColor = function(s){ 

// Show an error message
// soon as possible.
if (typeof Float32Array === 'undefined'){
 new GLControl(0,null,null,null);
 return;
}


var shapes = new Square(); 
  
var aIm = new Array();

var e =  new GLEntity(
 s,
 0
);

e.nOffset = Number(
 shapes.aOffset[0]
);

e.nCount = Number(
 shapes.aCount[0]
);

aIm.push(
 e
);
 
 // Default viewport dimensions:
this.nDim = Number(512);

var controller = new GLControl
(
 shapes.aVertices,
 shapes.aIndices,  
 aIm,
 this
);
  
if(controller == null){
 return;
}
 
};

GLFbTexColor.prototype = {

Initialize the Framebuffer

 
init:function(controller) {

var gl = controller.gl;

var glDemo = controller.glDemo; 

var glUtils = controller.glUtils = new GLUtils();

glUtils.getFramebuffer(
 controller,
 512
);

glUtils.getTexColor(
 controller
);

glUtils.getFramebufferStatus(
 controller
);
 
var responsive = new GLResponsive(
 ontroller,
 null
);

if (responsive == null){

 init.eDebug.innerHTML = "GLResponsive == null";

}  
},
  

Render One Frame

 
/**
Render one animation frame.
**/
render: function(controller){

var gl = controller.gl;

var glDemo = controller.glDemo;

var glUtils = controller.glUtils;

var e0 = controller.aEntities[0];

var nDimCanvas = controller.cv.width;

// Viewport dimensions
// equal render texture
// dimensions, before
// render to texture.
gl.viewport(
 0,
 0,
 glDemo.nDim,
 glDemo.nDim
);
 
gl.bindFramebuffer(
gl.FRAMEBUFFER, 
  glUtils.fb
);
 
gl.clearColor(
 Math.random(),
 Math.random(),
 Math.random(),   
 1
); 
 
gl.clear(
 gl.COLOR_BUFFER_BIT 
 | 
 gl.DEPTH_BUFFER_BIT
);
 

// Activate the 
// first texture. 
gl.uniform1i
(
 0.uSampler, 
 e0.idx
); 

gl.activeTexture
(
 gl.TEXTURE0 + e0.idx
);
 
// Draws the scene
// mapping the first
// texture to scene mesh
// elements. Renders to the
// framebuffer texture.
e0.matrix[14] = -8;

glUtils.renderInteractiveXY(
 controller,
 e0
);
 
// Viewport dimensions
// equal canvas dimensions
// before render to
// the canvas.
gl.viewport(
 0,
 0,
 nDimCanvas,
 nDimCanvas
);
 
// Draw the rendered
// texture to a square.
gl.bindFramebuffer(
 gl.FRAMEBUFFER, 
 null
);
 
gl.uniform1i
(
 e0.uSampler, 
 3
); 
 

gl.clearColor(
 1,
 0,
 1,
 1
);

gl.clear(
 gl.COLOR_BUFFER_BIT 
 | 
 gl.DEPTH_BUFFER_BIT
);

e0.matrix[14] = -2;

glUtils.renderQuad(
 controller,
 e0
);

},

};

Texture for Interactive Square

Texture with Four Colors
Tags
learn to code,Web GL, 3D Programming, 3D Development, 3D Media, 3D Web, 3 D Websites, 3D Development, 3D Web Design, 3D Web Development, Web Development, free tutorials, online learning, learn coding, html5, html 5, Web GL, 3D rendering software, GLSL, 3D Graphics Engine, 3D rendering software, create 3D website, 3D Media, JavaScript, html tutorial, how to code, programming websites, learn computer programming, learn to code for free, learning coding, stem, 3D images, webgl simple example, webgl basics, learning webgl, learn webgl

Ads >
Create 3D Games: Learn WebGL Book 2 Simple Shaders: Learn WebGL Book 4
3D Programming for Beginners: Learn WebGL Book 1

for Web graphics!

Copyright © 2022 Amy Butler. All Rights Reserved.