
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Z-Buffer or Depth-Buffer method in C++
The z-buffer also known as depth-buffer is a method that is used for hidden surface detection.
Hidden surface detection
For any picture that has objects and surfaces that are transparent. In this case, objects that are behind other objects are hidden. For proper visual of the image, we need to remove these hidden surfaces is required. The identification is called hidden surface problem.
In z-buffer, we will compare surfaces in the z-axis as depths.
Algorithm
Step 1: initialize the depth of all pixel max. d(i,j) = infinity Step 2: Initialize color for all pixels. c(i,j) = background-color Step 3: for each pixel in polygon projection do, Step 3.1: find z i.e. depth of projection’s (i,j) pixel. Step 3.2: if z < d(i,j) do Step 3.2.1 : d(i,j) = z and c(i,j) = color of polygon.
Using this method pixel by pixel, we will find the depth of each pixel of the plane. The smallest surface determines the color of the buffer. Generally, all z values are close to the range[0,1].
z=0, back clipping plane and z= 1, front clipping plane.
Some important point of a z-buffer
No initial sorting of polygons(planes) is required to apply the z-buffer method.
Z-buffer provides fast results even if the number of planes is large.
Object comparison is not required in the z-buffer method.
Non-polygonal hidden objects can also be detected using this method.
No extra data-structure for storing and resolving is required.
Hardware implementation is possible to speed up the process and is actively used in solve graphic workstations.
The method is applicable only when the objects under consideration are opaque i.e. transparent objects might give an error.
Drawing of the hidden surface might be a time-consuming process.
- Related Articles
- A-Buffer Method in C/C++?
- Buffer Type in C#
- Buffer BlockCopy in C#
- Buffer GetByte Example in C#
- Buffer SetByte Example in C#
- Clearing input buffer in C/C++
- Database Buffer in DBMS
- What does buffer flush means in C++ ?
- How do I clear the cin buffer in C++?
- What do you mean by buffer in C language?
- Difference between Buffer and Cache
- Difference between Cache and Buffer
- What is a buffer attribute in JSP?
- How to use string buffer in android?
- Convert buffer to readable string in JavaScript?
