Setting Colors for 3D Objects

This section explains how to set colors for 3D objects.

- Table of Contents -

Setting the Color of a Model

To change the color of a model, use the setModelColor(...) function.

- Function Format -

void setModelColor (
  int modelID,
  int red, int green, int blue, int alpha
)

Arguments:

Setting the Color of a Polygon

To change the color of a polygon, use the setPolygonColor(...) function.

- Function Format -

void setPolygonColor (
  int polygonID,
  int red, int green, int blue, int alpha
)

Arguments:

What is the RGBA Format?

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.

Additive Color Mixing
Additive Color Mixing
RGBA color blending uses additive mixing like light, not subtractive mixing like paint.

Examples of common RGBA color combinations:

Example Program

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.

Execution Result
Execution Result
A blue sphere will appear on a black background.