Colorful shapes
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -3,8 +3,8 @@
|
||||
|
||||
void Camera_Init(Camera* c)
|
||||
{
|
||||
c->position[0] = -50.0f;
|
||||
c->position[1] = 130.0f;
|
||||
c->position[0] = 5.0f;
|
||||
c->position[1] = 0.0f;
|
||||
c->position[2] = 0.0f;
|
||||
c->width[0] = 0.6f;
|
||||
c->width[1] = 5.8f;
|
||||
|
||||
11
src/game.c
11
src/game.c
@@ -19,10 +19,13 @@ void Game_Update(GameState *gs)
|
||||
{
|
||||
vec3 move;
|
||||
glm_vec3_zero(move);
|
||||
if (gs->input.w) move[0] = 0.3f;
|
||||
else if (gs->input.s) move[0] = -0.3f;
|
||||
if (gs->input.a) move[1] = 0.3f;
|
||||
else if (gs->input.d) move[1] = -0.3f;
|
||||
const float speed = 0.3f;
|
||||
if (gs->input.w) move[0] = speed;
|
||||
else if (gs->input.s) move[0] = -speed;
|
||||
if (gs->input.a) move[1] = speed;
|
||||
else if (gs->input.d) move[1] = -speed;
|
||||
if (gs->input.q) move[2] = speed;
|
||||
else if (gs->input.e) move[2] = -speed;
|
||||
glm_vec3_add(gs->camera.position, move, gs->camera.position);
|
||||
|
||||
Camera_UpdateVectors(&gs->camera);
|
||||
|
||||
@@ -12,6 +12,8 @@ typedef struct
|
||||
bool a;
|
||||
bool s;
|
||||
bool d;
|
||||
bool q;
|
||||
bool e;
|
||||
} InputState;
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -27,6 +27,8 @@ static void HandleKeyDown(GameState *gs, SDL_KeyCode sym)
|
||||
case SDLK_a: gs->input.a = true; break;
|
||||
case SDLK_s: gs->input.s = true; break;
|
||||
case SDLK_d: gs->input.d = true; break;
|
||||
case SDLK_q: gs->input.q = true; break;
|
||||
case SDLK_e: gs->input.e = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +40,8 @@ static void HandleKeyUp(GameState *gs, SDL_KeyCode sym)
|
||||
case SDLK_a: gs->input.a = false; break;
|
||||
case SDLK_s: gs->input.s = false; break;
|
||||
case SDLK_d: gs->input.d = false; break;
|
||||
case SDLK_q: gs->input.q = false; break;
|
||||
case SDLK_e: gs->input.e = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ bool Render_Init(GameState *gs)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
|
||||
gs->window = SDL_CreateWindow("Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);;
|
||||
gs->window = SDL_CreateWindow("Sandbox", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);;
|
||||
gs->glContext = SDL_GL_CreateContext(gs->window);
|
||||
printf("Created OpenGL window.\n");
|
||||
|
||||
@@ -236,7 +236,7 @@ bool Render_Init(GameState *gs)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
printf("Initialized OpenGL.\n");
|
||||
|
||||
Shape *shape = Shape_MakePyramid(3);
|
||||
Shape *shape = Shape_MakePyramid(5);
|
||||
gs->testShape = shape;
|
||||
glGenVertexArrays(1, &shape->VAO);
|
||||
glGenBuffers(1, &shape->VBO);
|
||||
|
||||
@@ -62,15 +62,15 @@ Shape *Shape_MakePyramid(int numInstances)
|
||||
for (int i = 0; i < numInstances; i++)
|
||||
{
|
||||
ShapeInstance *instance = shape->instances + i;
|
||||
instance->position[0] = -4.0f;
|
||||
instance->position[0] = 0.0f;
|
||||
instance->position[0] = (5.0f * i) - 2.0f;
|
||||
instance->position[0] = 0.0f;
|
||||
instance->position[0] = (5.0f * i) - 10.0;
|
||||
instance->scale = 1.0f;
|
||||
instance->collisionRadius = 1.0f;
|
||||
glm_vec3_zero(instance->velocity);
|
||||
glm_vec3_zero(instance->rotation);
|
||||
float *textureId = shape->instanceData + (i * 17);
|
||||
*textureId = 0;
|
||||
*textureId = i;
|
||||
mat4 *matrix = (void*)(textureId + 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user