Setting Colors for 3D Objects
This section explains how to set colors for 3D objects.
Setting the Color of a Model
To change the color of a model, use the setModelColor(...) function.
- Function Format -
int modelID,
int red, int green, int blue, int alpha
)
Arguments:
- modelID: Specifies the ID of the model to configure.
- red, green, blue, alpha: Specify the color components of the model. Each component should be in the range from 0 to 255. The format used is RGBA (explained below).
Setting the Color of a Polygon
To change the color of a polygon, use the setPolygonColor(...) function.
- Function Format -
int polygonID,
int red, int green, int blue, int alpha
)
Arguments:
- polygonID: Specifies the ID of the polygon to configure.
- red, green, blue, alpha: Specify the color components of the polygon. Each component should be in the range from 0 to 255. The format used is RGBA (explained below).
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.

Examples of common RGBA color combinations:
- (Red, Green, Blue) = (255, 255, 255) results in white, not black.
- (Red, Green, Blue) = (255, 255, 0) results in yellow.
- (Red, Green, Blue) = (0, 255, 255) results in cyan (a bright blue-green).
- (Red, Green, Blue) = (255, 0, 255) results in magenta (a purplish pink)
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.

- 3D Computer Graphics
- Setting Up the Foundation
- Mouse Control and Animation
- Using the Framework
- Creating and Placing Light Sources (and Adjusting Their Properties)
- Creating and Placing Models / Standard Models
- Creating and Placing Polygons, and Various Types of Polygons
- Moving 3D Objects
- Rotating 3D Objects
- Scaling 3D Objects
- Flipping 3D Objects
- Setting Colors for 3D Objects
- Configuring the Shape of 3D Objects
- Fill Settings for 3D Objects
- Material Settings for 3D Objects
- Understanding Coordinate Systems: Concepts, Creation, and Placement
- Moving Coordinate Systems
- Walking Coordinate Systems
- Controlling the Origin Position of a Coordinate System
- Rotating Coordinate Systems
- Spinning a Coordinate System
- Euler Angle-Based Attitude Control of Coordinate Systems
- Camera Work
- Creating, Placing, and Performing Basic Operations on Vectors
- Coordinate Transformations
- Screen Projection
- Collision Detection