Game Development Reference
In-Depth Information
else{
gl.uniform1i(shaderProgram.hasTexture,0);
gl.disableVertexAttribArray(shaderProgram.
textureCoordAttribute);
}
...
}
}
We have also modified our drawScene function to change the color of our picked
object. While iterating over our array of stageObjects , if any object's isPicked
attribute is true , we set our own diffuse color ( gl.uniform3f(shaderProgram.
materialDiffuseColor, 0, 255, 0); ). We do not use the diffuse color loaded
from the JSON file. We apply a texture only if the isPicked property is false .
Earlier, we only checked if the materialFile variable was associated with it, but
now we also check for the isPicked property.
The jigLib.JSegment class was created only for ray
casting and not picking. In many physics engines, you will
see that in the picking code, the ray takes only the direction
and not the length of the ray (infinite ray). Hence, when you
test the picking, you will have to steer the camera close to the
object using arrow keys to pick it.
Offscreen rendering using framebuffers
WebGL games sometimes require the rendering of images without displaying them
to the user or screen. For example, a game may want to draw the offline image
and then cache it to save the reprocessing time. Offscreen rendering is also used
to generate shadows of objects. Another example; our game might want to render
an image and use it as a texture in a filter pass. For best performance, offscreen
memories are managed by WebGL. When WebGL manages offscreen buffers, it
allows us to avoid copying the pixel data back to our application.
WebGL has framebuffer objects. The framebuffers allow our game to capture a game
scene in the GPU memory for further processing.
A framebuffer object ( FBO ) is a drawable object. It is a window-agnostic object that
is defined in the WebGL standard. After we draw to a framebuffer object, we can
read the pixel data to our game or use it as source data for other WebGL commands.
 
Search WWH ::




Custom Search