[ Prev | Index | Next ]
Japanese English

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 -

void setModelColor (
  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 -

void setPolygonColor (
  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.

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:

  • (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.

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



Sponsored Link



Japanese English
Index
[ Prev | Index | Next ]
News From RINEARN
* VCSSL is developed by RINEARN.

English Documentation for Our Software and VCSSL Is Now Nearly Complete
2025-06-30 - We're happy to announce that the large-scale expansion of our English documentation with the support of AI — a project that began two years ago — has now reached its initial target milestone.

VCSSL 3.4.52 Released: Enhanced Integration with External Programs and More
2025-05-25 - This update introduces enhancements to the external program integration features (e.g., for running C-language executables). Several other improvements and fixes are also included. Details inside.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!