This section explains how to set colors for 3D objects.
To change the color of a model, use the setModelColor(...) function.
- Function Format -
Arguments:
To change the color of a polygon, use the setPolygonColor(...) function.
- Function Format -
Arguments:
The RGBA format represents a color using the three primary colors -- Red, Green, and Blue -- plus an Alpha component. The Alpha component controls the transparency of the color: 0 means fully transparent, and the maximum valu (255) means fully opaque.
Color blending between red, green, and blue components is based on additive color mixing, which works by combining light. This is different from subtractive color mixing, such as mixing paint.
Examples of common RGBA color combinations:
Let's create a sphere model and set its color to blue. Try running the following code:
import graphics3d.Graphics3DFramework;
import Graphics3D;
// プログラムの最初に呼び出される関数
void onStart ( int rendererID ) {
// 画面サイズや背景色の設定(省略可能)
setWindowSize( 800, 600 );
setBackgroundColor( 0, 0, 0, 255 );
// 球モデルを生成して配置
int sphere = newSphereModel( 1.0, 1.0, 1.0, 10, 7 );
mountModel( sphere, rendererID );
// 球モデルを青色に設定
setModelColor( sphere, 0, 0, 255, 255 );
}
Sample.vcssl
When you run this program, a blue sphere will appear on a black background.