mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-06 06:13:10 +00:00
REVIEWED: examples: Several minor issues
This commit is contained in:
parent
dcc9e96148
commit
e062e3835e
@ -67,7 +67,7 @@ int main(void)
|
|||||||
models[i] = LoadModel(voxFileNames[i]);
|
models[i] = LoadModel(voxFileNames[i]);
|
||||||
double t1 = GetTime()*1000.0;
|
double t1 = GetTime()*1000.0;
|
||||||
|
|
||||||
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
TraceLog(LOG_INFO, TextFormat("[%s] Model file loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
||||||
|
|
||||||
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
||||||
BoundingBox bb = GetModelBoundingBox(models[i]);
|
BoundingBox bb = GetModelBoundingBox(models[i]);
|
||||||
@ -80,6 +80,8 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
Vector3 modelpos = { 0 };
|
||||||
|
Vector3 camerarot = { 0 };
|
||||||
|
|
||||||
// Load voxel shader
|
// Load voxel shader
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
||||||
@ -98,11 +100,7 @@ int main(void)
|
|||||||
// Assign out lighting shader to model
|
// Assign out lighting shader to model
|
||||||
for (int i = 0; i < MAX_VOX_FILES; i++)
|
for (int i = 0; i < MAX_VOX_FILES; i++)
|
||||||
{
|
{
|
||||||
Model m = models[i];
|
for (int j = 0; j < models[i].materialCount; j++) models[i].materials[j].shader = shader;
|
||||||
for (int j = 0; j < m.materialCount; j++)
|
|
||||||
{
|
|
||||||
m.materials[j].shader = shader;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create lights
|
// Create lights
|
||||||
@ -112,12 +110,8 @@ int main(void)
|
|||||||
lights[2] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, 20 }, Vector3Zero(), GRAY, shader);
|
lights[2] = CreateLight(LIGHT_POINT, (Vector3) { -20, 20, 20 }, Vector3Zero(), GRAY, shader);
|
||||||
lights[3] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, -20 }, Vector3Zero(), GRAY, shader);
|
lights[3] = CreateLight(LIGHT_POINT, (Vector3) { 20, -20, -20 }, Vector3Zero(), GRAY, shader);
|
||||||
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
Vector3 modelpos = { 0 };
|
|
||||||
Vector3 camerarot = { 0 };
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
@ -137,14 +131,10 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateCameraPro(&camera,
|
UpdateCameraPro(&camera,
|
||||||
(Vector3) {
|
(Vector3){ (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f, // Move forward-backward
|
||||||
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f, // Move right-left
|
||||||
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
0.0f }, // Move up-down
|
||||||
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
camerarot, // Camera rotation
|
||||||
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
|
||||||
0.0f // Move up-down
|
|
||||||
},
|
|
||||||
camerarot,
|
|
||||||
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
|
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
|
||||||
|
|
||||||
// Cycle between models on mouse click
|
// Cycle between models on mouse click
|
||||||
@ -156,8 +146,8 @@ int main(void)
|
|||||||
|
|
||||||
// Update light values (actually, only enable/disable them)
|
// Update light values (actually, only enable/disable them)
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
|
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
@ -166,7 +156,6 @@ int main(void)
|
|||||||
|
|
||||||
// Draw 3D model
|
// Draw 3D model
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
DrawModel(models[currentModel], modelpos, 1.0f, WHITE);
|
DrawModel(models[currentModel], modelpos, 1.0f, WHITE);
|
||||||
DrawGrid(10, 1.0);
|
DrawGrid(10, 1.0);
|
||||||
|
|
||||||
@ -176,16 +165,15 @@ int main(void)
|
|||||||
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lights[i].color);
|
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lights[i].color);
|
||||||
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lights[i].color, 0.3f));
|
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lights[i].color, 0.3f));
|
||||||
}
|
}
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
// Display info
|
// Display info
|
||||||
DrawRectangle(10, 400, 340, 60, Fade(SKYBLUE, 0.5f));
|
DrawRectangle(10, 40, 340, 70, Fade(SKYBLUE, 0.5f));
|
||||||
DrawRectangleLines(10, 400, 340, 60, Fade(DARKBLUE, 0.5f));
|
DrawRectangleLines(10, 40, 340, 70, Fade(DARKBLUE, 0.5f));
|
||||||
DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
|
DrawText("- MOUSE LEFT BUTTON: CYCLE VOX MODELS", 20, 50, 10, BLUE);
|
||||||
DrawText("MOUSE MIDDLE BUTTON to ZOOM OR ROTATE CAMERA", 40, 420, 10, BLUE);
|
DrawText("- MOUSE MIDDLE BUTTON: ZOOM OR ROTATE CAMERA", 20, 70, 10, BLUE);
|
||||||
DrawText("UP-DOWN-LEFT-RIGHT KEYS to MOVE CAMERA", 40, 430, 10, BLUE);
|
DrawText("- UP-DOWN-LEFT-RIGHT KEYS: MOVE CAMERA", 20, 90, 10, BLUE);
|
||||||
DrawText(TextFormat("File: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
|
DrawText(TextFormat("Model file: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -201,5 +189,3 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ int main(void)
|
|||||||
Mesh mesh = GenMeshPoints(numPoints);
|
Mesh mesh = GenMeshPoints(numPoints);
|
||||||
Model model = LoadModelFromMesh(mesh);
|
Model model = LoadModelFromMesh(mesh);
|
||||||
|
|
||||||
//SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
@ -92,15 +92,12 @@ int main(void)
|
|||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
// The new method only uploads the points once to the GPU
|
// The new method only uploads the points once to the GPU
|
||||||
if (useDrawModelPoints)
|
if (useDrawModelPoints) DrawModelPoints(model, position, 1.0f, WHITE);
|
||||||
{
|
|
||||||
DrawModelPoints(model, position, 1.0f, WHITE);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The old method must continually draw the "points" (lines)
|
// The old method must continually draw the "points" (lines)
|
||||||
@ -124,17 +121,16 @@ int main(void)
|
|||||||
|
|
||||||
// Draw a unit sphere for reference
|
// Draw a unit sphere for reference
|
||||||
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
|
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
// Draw UI text
|
// Draw UI text
|
||||||
DrawText(TextFormat("Point Count: %d", numPoints), 20, screenHeight - 50, 40, WHITE);
|
DrawText(TextFormat("Point Count: %d", numPoints), 10, screenHeight - 50, 40, WHITE);
|
||||||
DrawText("Up - increase points", 20, 70, 20, WHITE);
|
DrawText("UP - Increase points", 10, 40, 20, WHITE);
|
||||||
DrawText("Down - decrease points", 20, 100, 20, WHITE);
|
DrawText("DOWN - Decrease points", 10, 70, 20, WHITE);
|
||||||
DrawText("Space - drawing function", 20, 130, 20, WHITE);
|
DrawText("SPACE - Drawing function", 10, 100, 20, WHITE);
|
||||||
|
|
||||||
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 20, 160, 20, GREEN);
|
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 10, 130, 20, GREEN);
|
||||||
else DrawText("Using: DrawPoint3D()", 20, 160, 20, RED);
|
else DrawText("Using: DrawPoint3D()", 10, 130, 20, RED);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
#define GLSL_VERSION 100
|
#define GLSL_VERSION 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAP_SIZE 10
|
#define MAP_SIZE 16
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
@ -88,8 +88,6 @@ int main(void)
|
|||||||
|
|
||||||
RenderTexture lightmap = LoadRenderTexture(MAP_SIZE, MAP_SIZE);
|
RenderTexture lightmap = LoadRenderTexture(MAP_SIZE, MAP_SIZE);
|
||||||
|
|
||||||
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR);
|
|
||||||
|
|
||||||
Material material = LoadMaterialDefault();
|
Material material = LoadMaterialDefault();
|
||||||
material.shader = shader;
|
material.shader = shader;
|
||||||
material.maps[MATERIAL_MAP_ALBEDO].texture = texture;
|
material.maps[MATERIAL_MAP_ALBEDO].texture = texture;
|
||||||
@ -103,30 +101,34 @@ int main(void)
|
|||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
light,
|
light,
|
||||||
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
|
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
|
||||||
(Rectangle){ 0, 0, 20, 20 },
|
(Rectangle){ 0, 0, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE },
|
||||||
(Vector2){ 10.0, 10.0 },
|
(Vector2){ (float)MAP_SIZE, (float)MAP_SIZE },
|
||||||
0.0,
|
0.0,
|
||||||
RED
|
RED
|
||||||
);
|
);
|
||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
light,
|
light,
|
||||||
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
|
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
|
||||||
(Rectangle){ 8, 4, 20, 20 },
|
(Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE/2.0f, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE },
|
||||||
(Vector2){ 10.0, 10.0 },
|
(Vector2){ (float)MAP_SIZE, (float)MAP_SIZE },
|
||||||
0.0,
|
0.0,
|
||||||
BLUE
|
BLUE
|
||||||
);
|
);
|
||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
light,
|
light,
|
||||||
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
|
(Rectangle){ 0, 0, (float)light.width, (float)light.height },
|
||||||
(Rectangle){ 8, 8, 10, 10 },
|
(Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE*0.8f, (float)MAP_SIZE, (float)MAP_SIZE },
|
||||||
(Vector2){ 5.0, 5.0 },
|
(Vector2){ (float)MAP_SIZE/2.0f, (float)MAP_SIZE/2.0f },
|
||||||
0.0,
|
0.0,
|
||||||
GREEN
|
GREEN
|
||||||
);
|
);
|
||||||
BeginBlendMode(BLEND_ALPHA);
|
BeginBlendMode(BLEND_ALPHA);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
|
// NOTE: To enable trilinear filtering we need mipmaps available for texture
|
||||||
|
GenTextureMipmaps(&lightmap.texture);
|
||||||
|
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR);
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -141,24 +143,20 @@ int main(void)
|
|||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
DrawMesh(mesh, material, MatrixIdentity());
|
DrawMesh(mesh, material, MatrixIdentity());
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawTexturePro(lightmap.texture, (Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE },
|
||||||
|
|
||||||
DrawTexturePro(
|
|
||||||
lightmap.texture,
|
|
||||||
(Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE },
|
|
||||||
(Rectangle){ (float)GetRenderWidth() - MAP_SIZE*8 - 10, 10, (float)MAP_SIZE*8, (float)MAP_SIZE*8 },
|
(Rectangle){ (float)GetRenderWidth() - MAP_SIZE*8 - 10, 10, (float)MAP_SIZE*8, (float)MAP_SIZE*8 },
|
||||||
(Vector2){ 0.0, 0.0 },
|
(Vector2){ 0.0, 0.0 }, 0.0, WHITE);
|
||||||
0.0,
|
|
||||||
WHITE);
|
|
||||||
|
|
||||||
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
|
DrawText(TextFormat("LIGHTMAP: %ix%i pixels", MAP_SIZE, MAP_SIZE), GetRenderWidth() - 130, 20 + MAP_SIZE*8, 10, GREEN);
|
||||||
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
|
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -40,7 +40,7 @@ int main(void)
|
|||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
Texture texPattern = LoadTexture("resources/patterns.png");
|
Texture texPattern = LoadTexture("resources/patterns.png");
|
||||||
SetTextureFilter(texPattern, TEXTURE_FILTER_TRILINEAR); // Makes the texture smoother when upscaled
|
SetTextureFilter(texPattern, TEXTURE_FILTER_BILINEAR); // Makes the texture smoother when upscaled
|
||||||
|
|
||||||
// Coordinates for all patterns inside the texture
|
// Coordinates for all patterns inside the texture
|
||||||
const Rectangle recPattern[] = {
|
const Rectangle recPattern[] = {
|
||||||
@ -110,19 +110,17 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle keys
|
// Handle keys: change scale
|
||||||
|
|
||||||
// Change scale
|
|
||||||
if (IsKeyPressed(KEY_UP)) scale += 0.25f;
|
if (IsKeyPressed(KEY_UP)) scale += 0.25f;
|
||||||
if (IsKeyPressed(KEY_DOWN)) scale -= 0.25f;
|
if (IsKeyPressed(KEY_DOWN)) scale -= 0.25f;
|
||||||
if (scale > 10.0f) scale = 10.0f;
|
if (scale > 10.0f) scale = 10.0f;
|
||||||
else if ( scale <= 0.0f) scale = 0.25f;
|
else if ( scale <= 0.0f) scale = 0.25f;
|
||||||
|
|
||||||
// Change rotation
|
// Handle keys: change rotation
|
||||||
if (IsKeyPressed(KEY_LEFT)) rotation -= 25.0f;
|
if (IsKeyPressed(KEY_LEFT)) rotation -= 25.0f;
|
||||||
if (IsKeyPressed(KEY_RIGHT)) rotation += 25.0f;
|
if (IsKeyPressed(KEY_RIGHT)) rotation += 25.0f;
|
||||||
|
|
||||||
// Reset
|
// Handle keys: reset
|
||||||
if (IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; }
|
if (IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; }
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user