Skip to content

Commit e86cbfa

Browse files
committed
Change main.cpp to be more interactive
1 parent 188e4bf commit e86cbfa

File tree

2 files changed

+48
-61
lines changed

2 files changed

+48
-61
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
./cmake-build-debug/
1+
cmake-build-debug/
2+
.idea/
3+
include/
4+
lib/

src/main.cpp

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,46 @@
1-
/*******************************************************************************************
2-
*
3-
* raylib [core] example - Basic window
4-
*
5-
* Welcome to raylib!
6-
*
7-
* To test examples, just press F6 and execute raylib_compile_execute script
8-
* Note that compiled executable is placed in the same folder as .c file
9-
*
10-
* You can find all basic examples on C:\raylib\raylib\examples folder or
11-
* raylib official webpage: www.raylib.com
12-
*
13-
* Enjoy using raylib. :)
14-
*
15-
* This example has been created using raylib 1.0 (www.raylib.com)
16-
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
17-
*
18-
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
19-
*
20-
********************************************************************************************/
21-
221
#include "raylib.h"
23-
24-
int main()
25-
{
26-
// Initialization
27-
//--------------------------------------------------------------------------------------
28-
int screenWidth = 800;
29-
int screenHeight = 450;
30-
31-
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
32-
33-
SetTargetFPS(60);
34-
//--------------------------------------------------------------------------------------
35-
36-
// Main game loop
37-
while (!WindowShouldClose()) // Detect window close button or ESC key
38-
{
39-
// Update
40-
//----------------------------------------------------------------------------------
41-
// TODO: Update your variables here
42-
//----------------------------------------------------------------------------------
43-
44-
// Draw
45-
//----------------------------------------------------------------------------------
46-
BeginDrawing();
47-
48-
ClearBackground(RAYWHITE);
49-
50-
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
51-
52-
EndDrawing();
53-
//----------------------------------------------------------------------------------
54-
}
55-
56-
// De-Initialization
57-
//--------------------------------------------------------------------------------------
58-
CloseWindow(); // Close window and OpenGL context
59-
//--------------------------------------------------------------------------------------
60-
61-
return 0;
2+
#include "rlgl.h"
3+
#define RAYGUI_IMPLEMENTATION
4+
#include "raygui.h"
5+
#undef RAYGUI_IMPLEMENTATION
6+
7+
int main() {
8+
InitWindow(800, 450, "raylib - rotation cube");
9+
SetTargetFPS(60);
10+
11+
Camera3D camera = {0};
12+
camera.position = (Vector3) {10, 6.5, 10};
13+
camera.target = (Vector3) {0.0f, 1.5f, 5.0f};
14+
camera.up = (Vector3) {0.0f, 1.0f, 0.0f};
15+
camera.fovy = 45.0f;
16+
camera.type = CAMERA_PERSPECTIVE;
17+
18+
float cubeSpeed = 5;
19+
Vector3 cubePosition = {0,1.5,0};
20+
auto cubeColor = DARKPURPLE;
21+
22+
while (!WindowShouldClose()) {
23+
BeginDrawing();
24+
ClearBackground(RAYWHITE);
25+
26+
BeginMode3D(camera);
27+
rlPushMatrix();
28+
rlRotatef(GetTime()*cubeSpeed*20,0,1,0);
29+
DrawCube(cubePosition,3,3,3,cubeColor);
30+
DrawCubeWires(cubePosition,3,3,3,DARKGREEN);
31+
DrawGrid(10,10);
32+
rlPopMatrix();
33+
EndMode3D();
34+
35+
/* GUI */
36+
GuiPanel((Rectangle){0,0,400,450});
37+
DrawText("Cube speed",120,10,30,LIGHTGRAY);
38+
cubeSpeed = GuiSlider((Rectangle){20,50,360,30}, nullptr, nullptr,cubeSpeed,0,10);
39+
DrawText("Cube color",120,150,30,LIGHTGRAY);
40+
cubeColor = GuiColorPicker((Rectangle){100,200,200,200},cubeColor);
41+
42+
EndDrawing();
43+
}
44+
CloseWindow();
45+
return 0;
6246
}

0 commit comments

Comments
 (0)