[ 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.


Author of This Article

Fumihiro Matsui
[ Founder of RINEARN, Doctor of Science (Physics), Applied Info Tech Engineer ]
Develops VCSSL, RINEARN Graph 3D and more. Also writes guides and articles.

Translation Cooperator

ChatGPT AIs
[ GPT-3.5, 4, 5, 5.1 ]
We greatly appreciate the cooperation of ChatGPT AIs in translating this article.


Sponsored Link



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

Exevalatorv2.4Released—MCPSupportAdded,NowUsableasanAICalculationTool
2025-11-15 - We'vereleasedExevalatorv2.4,ourexpression-evaluationlibrary.Startingwiththisversion,itsupportsMCP,makingitusableasacalculationtoolforAIassistants.

Exevalatorv2.3Released—NowUsablefromPython
2025-11-04 - We'vereleasedExevalatorv2.3.Startingwiththisversion,youcannowuseitfromPython!WithgrowingdemandaroundAItooldevelopmentinmind,wesharethedetailshere.

ExevalatorUpdated—EasyJapaneseLocalizationforErrorMessages
2025-10-31 - Exevalator2.2.2isout.YoucannowlocalizeerrormessagestoJapanesewithasimplecopy-and-paste,andwe'veincludedseveralbugfixesandminorparseradjustments.

InsideRINPnOnline:ArchitectureOverview
2025-10-22 - AninsidelookatthearchitectureoftherecentlylaunchedonlineversionoftheRINPnscientificcalculator.It'sopensource,soyoucanfreelymodifyandreuseittobuildyourownwebcalculator(maybe!).

MeetRINPnOnline:UsetheScientificCalculatorAnywhere,Instantly
2025-10-21 - RINPn,thefreescientificcalculator,nowhasanonlineversionyoucanuseinstantlyinyourbrowser—onbothPCandsmartphones.Readtheannouncementfordetails.

TheVCSSLSupportAIisHere!—RequiresaChatGPTPlusAccountforPracticalPerformance
2025-08-19 - AnewAIassistantfortheVCSSLprogramminglanguageisheretoansweryourquestionsandhelpwithcoding.ThisarticleexplainshowtouseitandshowcasesplentyofrealQ&Aandgeneratedcodeexamples.

EnglishDocumentationforOurSoftwareandVCSSLIsNowNearlyComplete
2025-06-30 - We'rehappytoannouncethatthelarge-scaleexpansionofourEnglishdocumentationwiththesupportofAI—aprojectthatbegantwoyearsago—hasnowreacheditsinitialtargetmilestone.

VCSSL3.4.52Released:EnhancedIntegrationwithExternalProgramsandMore
2025-05-25 - Thisupdateintroducesenhancementstotheexternalprogramintegrationfeatures(e.g.,forrunningC-languageexecutables).Severalotherimprovementsandfixesarealsoincluded.Detailsinside.