all.h
raw
1#ifndef ALL_H
2#define ALL_H
3
4#include <stdio.h>
5#include <stdlib.h>
6
7#define GL_SILENCE_DEPRECATION
8#ifdef __APPLE__
9 #include <OpenGL/gl.h>
10 #include <GLUT/glut.h>
11#else
12 #include <GL/gl.h>
13 #include <GL/glut.h>
14#endif
15
16#ifndef M_PI
17 #define M_PI 3.14159265358979323846
18#endif
19
20typedef struct {
21 float x, y, z;
22} Vec2;
23
24typedef struct {
25 float x, y, z;
26} Vec3;
27
28typedef struct {
29 float x, y, z, w;
30} Vec4;
31
32typedef struct {
33 char format[3];
34 int width;
35 int height;
36 int color_space;
37 unsigned char *pixels;
38} Image;
39
40typedef struct {
41 int target_fps;
42 int width;
43 int height;
44 int last_time;
45
46 float x_offset;
47 float y_offset;
48 float cube_angle;
49 GLuint texture_id;
50} Game;
51
52extern Game game;
53
54#define COLOR_RED (Vec3){ .x = 1.0f, .y = 0.0f, .z = 0.0f }
55#define COLOR_GREEN (Vec3){ .x = 0.0f, .y = 1.0f, .z = 0.0f }
56#define COLOR_BLUE (Vec3){ .x = 0.0f, .y = 0.0f, .z = 1.0f }
57#define COLOR_WHITE (Vec3){ .x = 1.0f, .y = 1.0f, .z = 1.0f }
58#define COLOR_BLACK (Vec3){ .x = 0.0f, .y = 0.0f, .z = 0.0f }
59#define COLOR_YELLOW (Vec3){ .x = 1.0f, .y = 1.0f, .z = 0.0f }
60#define COLOR_CYAN (Vec3){ .x = 0.0f, .y = 1.0f, .z = 1.0f }
61#define COLOR_MAGENTA (Vec3){ .x = 1.0f, .y = 0.0f, .z = 1.0f }
62#define COLOR_ORANGE (Vec3){ .x = 1.0f, .y = 0.5f, .z = 0.0f }
63#define COLOR_PURPLE (Vec3){ .x = 0.5f, .y = 0.0f, .z = 0.5f }
64
65Image read_ppm_image(const char *filename);
66
67void handle_keyboard_event(unsigned char key, int x, int y);
68void handle_mouse_event(int button, int state, int x, int y);
69
70#endif