Skip to content

Commit e062e38

Browse files
committed
REVIEWED: examples: Several minor issues
1 parent dcc9e96 commit e062e38

File tree

4 files changed

+63
-85
lines changed

4 files changed

+63
-85
lines changed

examples/models/models_loading_vox.c

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(void)
6767
models[i] = LoadModel(voxFileNames[i]);
6868
double t1 = GetTime()*1000.0;
6969

70-
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
70+
TraceLog(LOG_INFO, TextFormat("[%s] Model file loaded in %.3f ms", voxFileNames[i], t1 - t0));
7171

7272
// Compute model translation matrix to center model on draw position (0, 0 , 0)
7373
BoundingBox bb = GetModelBoundingBox(models[i]);
@@ -80,6 +80,8 @@ int main(void)
8080
}
8181

8282
int currentModel = 0;
83+
Vector3 modelpos = { 0 };
84+
Vector3 camerarot = { 0 };
8385

8486
// Load voxel shader
8587
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
@@ -98,11 +100,7 @@ int main(void)
98100
// Assign out lighting shader to model
99101
for (int i = 0; i < MAX_VOX_FILES; i++)
100102
{
101-
Model m = models[i];
102-
for (int j = 0; j < m.materialCount; j++)
103-
{
104-
m.materials[j].shader = shader;
105-
}
103+
for (int j = 0; j < models[i].materialCount; j++) models[i].materials[j].shader = shader;
106104
}
107105

108106
// Create lights
@@ -112,12 +110,8 @@ int main(void)
112110
lights[2] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, 20 }, Vector3Zero(), GRAY, shader);
113111
lights[3] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, -20 }, Vector3Zero(), GRAY, shader);
114112

115-
116113
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
117-
118114
//--------------------------------------------------------------------------------------
119-
Vector3 modelpos = { 0 };
120-
Vector3 camerarot = { 0 };
121115

122116
// Main game loop
123117
while (!WindowShouldClose()) // Detect window close button or ESC key
@@ -137,15 +131,11 @@ int main(void)
137131
}
138132

139133
UpdateCameraPro(&camera,
140-
(Vector3) {
141-
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
142-
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
143-
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
144-
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
145-
0.0f // Move up-down
146-
},
147-
camerarot,
148-
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
134+
(Vector3){ (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f, // Move forward-backward
135+
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f, // Move right-left
136+
0.0f }, // Move up-down
137+
camerarot, // Camera rotation
138+
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
149139

150140
// Cycle between models on mouse click
151141
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1) % MAX_VOX_FILES;
@@ -156,36 +146,34 @@ int main(void)
156146

157147
// Update light values (actually, only enable/disable them)
158148
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
159-
160149
//----------------------------------------------------------------------------------
150+
161151
// Draw
162152
//----------------------------------------------------------------------------------
163153
BeginDrawing();
164154

165-
ClearBackground(RAYWHITE);
166-
167-
// Draw 3D model
168-
BeginMode3D(camera);
169-
170-
DrawModel(models[currentModel], modelpos, 1.0f, WHITE);
171-
DrawGrid(10, 1.0);
172-
173-
// Draw spheres to show where the lights are
174-
for (int i = 0; i < MAX_LIGHTS; i++)
175-
{
176-
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lights[i].color);
177-
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lights[i].color, 0.3f));
178-
}
179-
180-
EndMode3D();
181-
182-
// Display info
183-
DrawRectangle(10, 400, 340, 60, Fade(SKYBLUE, 0.5f));
184-
DrawRectangleLines(10, 400, 340, 60, Fade(DARKBLUE, 0.5f));
185-
DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
186-
DrawText("MOUSE MIDDLE BUTTON to ZOOM OR ROTATE CAMERA", 40, 420, 10, BLUE);
187-
DrawText("UP-DOWN-LEFT-RIGHT KEYS to MOVE CAMERA", 40, 430, 10, BLUE);
188-
DrawText(TextFormat("File: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
155+
ClearBackground(RAYWHITE);
156+
157+
// Draw 3D model
158+
BeginMode3D(camera);
159+
DrawModel(models[currentModel], modelpos, 1.0f, WHITE);
160+
DrawGrid(10, 1.0);
161+
162+
// Draw spheres to show where the lights are
163+
for (int i = 0; i < MAX_LIGHTS; i++)
164+
{
165+
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lights[i].color);
166+
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lights[i].color, 0.3f));
167+
}
168+
EndMode3D();
169+
170+
// Display info
171+
DrawRectangle(10, 40, 340, 70, Fade(SKYBLUE, 0.5f));
172+
DrawRectangleLines(10, 40, 340, 70, Fade(DARKBLUE, 0.5f));
173+
DrawText("- MOUSE LEFT BUTTON: CYCLE VOX MODELS", 20, 50, 10, BLUE);
174+
DrawText("- MOUSE MIDDLE BUTTON: ZOOM OR ROTATE CAMERA", 20, 70, 10, BLUE);
175+
DrawText("- UP-DOWN-LEFT-RIGHT KEYS: MOVE CAMERA", 20, 90, 10, BLUE);
176+
DrawText(TextFormat("Model file: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
189177

190178
EndDrawing();
191179
//----------------------------------------------------------------------------------
@@ -201,5 +189,3 @@ int main(void)
201189

202190
return 0;
203191
}
204-
205-

examples/models/models_point_rendering.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int main(void)
5757
Mesh mesh = GenMeshPoints(numPoints);
5858
Model model = LoadModelFromMesh(mesh);
5959

60-
//SetTargetFPS(60);
60+
SetTargetFPS(60);
6161
//--------------------------------------------------------------------------------------
6262

6363
// Main game loop
@@ -92,15 +92,12 @@ int main(void)
9292
// Draw
9393
//----------------------------------------------------------------------------------
9494
BeginDrawing();
95+
9596
ClearBackground(BLACK);
9697

9798
BeginMode3D(camera);
98-
9999
// The new method only uploads the points once to the GPU
100-
if (useDrawModelPoints)
101-
{
102-
DrawModelPoints(model, position, 1.0f, WHITE);
103-
}
100+
if (useDrawModelPoints) DrawModelPoints(model, position, 1.0f, WHITE);
104101
else
105102
{
106103
// The old method must continually draw the "points" (lines)
@@ -124,17 +121,16 @@ int main(void)
124121

125122
// Draw a unit sphere for reference
126123
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
127-
128124
EndMode3D();
129125

130126
// Draw UI text
131-
DrawText(TextFormat("Point Count: %d", numPoints), 20, screenHeight - 50, 40, WHITE);
132-
DrawText("Up - increase points", 20, 70, 20, WHITE);
133-
DrawText("Down - decrease points", 20, 100, 20, WHITE);
134-
DrawText("Space - drawing function", 20, 130, 20, WHITE);
127+
DrawText(TextFormat("Point Count: %d", numPoints), 10, screenHeight - 50, 40, WHITE);
128+
DrawText("UP - Increase points", 10, 40, 20, WHITE);
129+
DrawText("DOWN - Decrease points", 10, 70, 20, WHITE);
130+
DrawText("SPACE - Drawing function", 10, 100, 20, WHITE);
135131

136-
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 20, 160, 20, GREEN);
137-
else DrawText("Using: DrawPoint3D()", 20, 160, 20, RED);
132+
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 10, 130, 20, GREEN);
133+
else DrawText("Using: DrawPoint3D()", 10, 130, 20, RED);
138134

139135
DrawFPS(10, 10);
140136

examples/shaders/shaders_lightmap_rendering.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define GLSL_VERSION 100
3434
#endif
3535

36-
#define MAP_SIZE 10
36+
#define MAP_SIZE 16
3737

3838
//------------------------------------------------------------------------------------
3939
// Program main entry point
@@ -88,8 +88,6 @@ int main(void)
8888

8989
RenderTexture lightmap = LoadRenderTexture(MAP_SIZE, MAP_SIZE);
9090

91-
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR);
92-
9391
Material material = LoadMaterialDefault();
9492
material.shader = shader;
9593
material.maps[MATERIAL_MAP_ALBEDO].texture = texture;
@@ -103,29 +101,33 @@ int main(void)
103101
DrawTexturePro(
104102
light,
105103
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
106-
(Rectangle){ 0, 0, 20, 20 },
107-
(Vector2){ 10.0, 10.0 },
104+
(Rectangle){ 0, 0, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE },
105+
(Vector2){ (float)MAP_SIZE, (float)MAP_SIZE },
108106
0.0,
109107
RED
110108
);
111109
DrawTexturePro(
112110
light,
113111
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
114-
(Rectangle){ 8, 4, 20, 20 },
115-
(Vector2){ 10.0, 10.0 },
112+
(Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE/2.0f, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE },
113+
(Vector2){ (float)MAP_SIZE, (float)MAP_SIZE },
116114
0.0,
117115
BLUE
118116
);
119117
DrawTexturePro(
120118
light,
121119
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
122-
(Rectangle){ 8, 8, 10, 10 },
123-
(Vector2){ 5.0, 5.0 },
120+
(Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE*0.8f, (float)MAP_SIZE, (float)MAP_SIZE },
121+
(Vector2){ (float)MAP_SIZE/2.0f, (float)MAP_SIZE/2.0f },
124122
0.0,
125123
GREEN
126124
);
127125
BeginBlendMode(BLEND_ALPHA);
128126
EndTextureMode();
127+
128+
// NOTE: To enable trilinear filtering we need mipmaps available for texture
129+
GenTextureMipmaps(&lightmap.texture);
130+
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR);
129131

130132
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
131133
//--------------------------------------------------------------------------------------
@@ -141,24 +143,20 @@ int main(void)
141143
// Draw
142144
//----------------------------------------------------------------------------------
143145
BeginDrawing();
146+
144147
ClearBackground(RAYWHITE);
145148

146149
BeginMode3D(camera);
147150
DrawMesh(mesh, material, MatrixIdentity());
148151
EndMode3D();
149152

150-
DrawFPS(10, 10);
151-
152-
DrawTexturePro(
153-
lightmap.texture,
154-
(Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE },
153+
DrawTexturePro(lightmap.texture, (Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE },
155154
(Rectangle){ (float)GetRenderWidth() - MAP_SIZE*8 - 10, 10, (float)MAP_SIZE*8, (float)MAP_SIZE*8 },
156-
(Vector2){ 0.0, 0.0 },
157-
0.0,
158-
WHITE);
155+
(Vector2){ 0.0, 0.0 }, 0.0, WHITE);
159156

160-
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
161-
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
157+
DrawText(TextFormat("LIGHTMAP: %ix%i pixels", MAP_SIZE, MAP_SIZE), GetRenderWidth() - 130, 20 + MAP_SIZE*8, 10, GREEN);
158+
159+
DrawFPS(10, 10);
162160

163161
EndDrawing();
164162
//----------------------------------------------------------------------------------

examples/textures/textures_tiled_drawing.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main(void)
4040

4141
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
4242
Texture texPattern = LoadTexture("resources/patterns.png");
43-
SetTextureFilter(texPattern, TEXTURE_FILTER_TRILINEAR); // Makes the texture smoother when upscaled
43+
SetTextureFilter(texPattern, TEXTURE_FILTER_BILINEAR); // Makes the texture smoother when upscaled
4444

4545
// Coordinates for all patterns inside the texture
4646
const Rectangle recPattern[] = {
@@ -110,19 +110,17 @@ int main(void)
110110
}
111111
}
112112

113-
// Handle keys
114-
115-
// Change scale
113+
// Handle keys: change scale
116114
if (IsKeyPressed(KEY_UP)) scale += 0.25f;
117115
if (IsKeyPressed(KEY_DOWN)) scale -= 0.25f;
118116
if (scale > 10.0f) scale = 10.0f;
119117
else if ( scale <= 0.0f) scale = 0.25f;
120118

121-
// Change rotation
119+
// Handle keys: change rotation
122120
if (IsKeyPressed(KEY_LEFT)) rotation -= 25.0f;
123121
if (IsKeyPressed(KEY_RIGHT)) rotation += 25.0f;
124122

125-
// Reset
123+
// Handle keys: reset
126124
if (IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; }
127125
//----------------------------------------------------------------------------------
128126

@@ -165,7 +163,7 @@ int main(void)
165163

166164
// De-Initialization
167165
//--------------------------------------------------------------------------------------
168-
UnloadTexture(texPattern); // Unload texture
166+
UnloadTexture(texPattern); // Unload texture
169167

170168
CloseWindow(); // Close window and OpenGL context
171169
//--------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)