MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/shaders/shaders_basic_pbr.cpp:79–286  ·  view source on GitHub ↗

---------------------------------------------------------------------------------- Main Entry Point ----------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

77// Main Entry Point
78//----------------------------------------------------------------------------------
79int main()
80{
81 // Initialization
82 //--------------------------------------------------------------------------------------
83 const int screenWidth = 800;
84 const int screenHeight = 450;
85
86 SetConfigFlags(FLAG_MSAA_4X_HINT);
87 InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic pbr");
88
89 // Define the camera to look into our 3d world
90 raylib::Camera camera;
91 camera.position = Vector3{ 2.0f, 2.0f, 6.0f }; // Camera position
92 camera.target = Vector3{ 0.0f, 0.5f, 0.0f }; // Camera looking at point
93 camera.up = Vector3{ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
94 camera.fovy = 45.0f; // Camera field-of-view Y
95 camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
96
97 // Load PBR shader and setup all required locations
98 raylib::Shader shader (TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
99 TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
100 shader.locs[SHADER_LOC_MAP_ALBEDO] = GetShaderLocation(shader, "albedoMap");
101 // WARNING: Metalness, roughness, and ambient occlusion are all packed into a MRA texture
102 // They are passed as to the SHADER_LOC_MAP_METALNESS location for convenience,
103 // shader already takes care of it accordingly
104 shader.locs[SHADER_LOC_MAP_METALNESS] = GetShaderLocation(shader, "mraMap");
105 shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
106 // WARNING: Similar to the MRA map, the emissive map packs different information
107 // into a single texture: it stores height and emission data
108 // It is binded to SHADER_LOC_MAP_EMISSION location an properly processed on shader
109 shader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(shader, "emissiveMap");
110 shader.locs[SHADER_LOC_COLOR_DIFFUSE] = GetShaderLocation(shader, "albedoColor");
111
112 // Setup additional required shader locations, including lights data
113 shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
114 int lightCountLoc = GetShaderLocation(shader, "numOfLights");
115 int maxLightCount = MAX_LIGHTS;
116 shader.SetValue(lightCountLoc, &maxLightCount, SHADER_UNIFORM_INT);
117
118 // Setup ambient color and intensity parameters
119 float ambientIntensity = 0.02f;
120 raylib::Color ambientColor = Color{ 26, 32, 135, 255 };
121 raylib::Vector3 ambientColorNormalized = Vector3{ ambientColor.r/255.0f, ambientColor.g/255.0f, ambientColor.b/255.0f };
122 shader.SetValue(shader.GetLocation("ambientColor"), &ambientColorNormalized, SHADER_UNIFORM_VEC3);
123 shader.SetValue(shader.GetLocation("ambient"), &ambientIntensity, SHADER_UNIFORM_FLOAT);
124
125 // Get location for shader parameters that can be modified in real time
126 int emissiveIntensityLoc = shader.GetLocation("emissivePower");
127 int emissiveColorLoc = shader.GetLocation("emissiveColor");
128 int textureTilingLoc = shader.GetLocation("tiling");
129
130 // Load old car model using PBR maps and shader
131 // WARNING: We know this model consists of a single model.meshes[0] and
132 // that model.materials[0] is by default assigned to that mesh
133 // There could be more complex models consisting of multiple meshes and
134 // multiple materials defined for those meshes... but always 1 mesh = 1 material
135 raylib::Model car ("resources/models/old_car_new.glb");
136

Callers

nothing calls this directly

Calls 10

InitWindowFunction · 0.85
LoadTextureFunction · 0.85
IsKeyPressedFunction · 0.85
UpdateLightFunction · 0.85
DrawSphereWiresFunction · 0.85
GetLocationMethod · 0.80
CreateLightFunction · 0.70
DrawTextFunction · 0.50
UpdateMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected