Hash :
752330a5
Author :
Thomas de Grivel
Date :
2024-08-08T17:20:11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
/* kc3
* Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
/** @file types.h
* @brief Module KC3.Window.SDL2
*
* Struct for all GUI window SDL2 graphics operations.
*/
#ifndef LIBKC3_WINDOW_SDL2_TYPES_H
#define LIBKC3_WINDOW_SDL2_TYPES_H
#include <GL/glew.h>
#include <SDL.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <png.h>
#include <libkc3/types.h>
#include "../types.h"
#define GL_CAMERA_LIGHT_MAX 16 // keep in sync with shader
typedef struct dmat3 s_dmat3;
typedef struct dmat4 s_dmat4;
typedef struct dvec2 s_dvec2;
typedef struct dvec3 s_dvec3;
typedef struct dvec4 s_dvec4;
typedef struct gl_camera s_gl_camera;
typedef struct gl_cylinder s_gl_cylinder;
typedef struct gl_font s_gl_font;
typedef struct gl_light s_gl_light;
typedef struct gl_lines s_gl_lines;
typedef struct gl_material s_gl_material;
typedef struct gl_object s_gl_object;
typedef struct gl_ortho s_gl_ortho;
typedef struct gl_sphere s_gl_sphere;
typedef struct gl_sprite s_gl_sprite;
typedef struct gl_square s_gl_square;
typedef struct gl_text s_gl_text;
typedef struct gl_triangle s_gl_triangle;
typedef struct gl_vertex s_gl_vertex;
typedef struct mat3 s_mat3;
typedef struct mat4 s_mat4;
typedef struct rgb s_rgb;
typedef struct rgba s_rgba;
typedef struct vec2 s_vec2;
typedef struct vec3 s_vec3;
typedef struct vec4 s_vec4;
typedef struct window_sdl2 s_window_sdl2;
/* return false to break event loop */
typedef bool (*f_window_sdl2_button) (s_window_sdl2 *window,
u8 button, sw x, sw y);
/* return false to break event loop */
typedef bool (*f_window_sdl2_key) (s_window_sdl2 *window,
SDL_Keysym *keysym);
/* return false to break event loop */
typedef bool (*f_window_sdl2_load) (s_window_sdl2 *window);
/* return false to break event loop */
typedef bool (*f_window_sdl2_motion) (s_window_sdl2 *window, sw x,
sw y);
/* return false to break event loop */
typedef bool (*f_window_sdl2_render) (s_window_sdl2 *window);
/* return false to break event loop */
typedef bool (*f_window_sdl2_resize) (s_window_sdl2 *window,
uw w, uw h);
typedef bool (*f_window_sdl2_sequence_load) (s_sequence *seq,
s_window_sdl2 *window);
typedef bool (*f_window_sdl2_sequence_render) (s_sequence *seq,
s_window_sdl2 *window,
void *context);
typedef void (*f_window_sdl2_unload) (s_window_sdl2 *window);
/* 1 */
struct dmat3 {
f64 xx;
f64 yx;
f64 zx;
f64 xy;
f64 yy;
f64 zy;
f64 xz;
f64 yz;
f64 zz;
};
struct dmat4 {
f64 xx;
f64 xy;
f64 xz;
f64 xt;
f64 yx;
f64 yy;
f64 yz;
f64 yt;
f64 zx;
f64 zy;
f64 zz;
f64 zt;
f64 tx;
f64 ty;
f64 tz;
f64 tt;
};
struct dvec2 {
f64 x;
f64 y;
};
struct dvec3 {
f64 x;
f64 y;
f64 z;
};
struct dvec4 {
f64 x;
f64 y;
f64 z;
f64 t;
};
struct gl_font {
FT_Face ft_face;
s_str path;
f32 point_size;
f32 point_per_pixel;
s_str real_path;
};
struct gl_lines {
s_array vertex;
GLuint gl_vao;
GLuint gl_vbo;
};
struct mat3 {
f32 xx;
f32 yx;
f32 zx;
f32 xy;
f32 yy;
f32 zy;
f32 xz;
f32 yz;
f32 zz;
};
struct mat4 {
f32 xx;
f32 xy;
f32 xz;
f32 xt;
f32 yx;
f32 yy;
f32 yz;
f32 yt;
f32 zx;
f32 zy;
f32 zz;
f32 zt;
f32 tx;
f32 ty;
f32 tz;
f32 tt;
};
struct gl_object {
s_array vertex;
s_array triangle;
u32 gl_mode;
u32 gl_vao;
u32 gl_vbo;
u32 gl_ebo;
};
struct gl_sprite {
uw dim_x;
uw dim_y;
uw frame_count;
s_str path;
uw pix_w;
uw pix_h;
f32 pt_w;
f32 pt_h;
s_str real_path;
GLuint *texture;
uw total_w;
uw total_h;
};
struct gl_text {
const s_gl_font *font;
uw pix_w;
uw pix_h;
f32 pt_w;
f32 pt_h;
s_str str;
GLuint texture;
};
struct gl_triangle {
GLuint a;
GLuint b;
GLuint c;
};
struct rgb {
f32 r;
f32 g;
f32 b;
};
struct rgba {
f32 r;
f32 g;
f32 b;
f32 a;
};
struct vec2 {
f32 x;
f32 y;
};
struct vec3 {
f32 x;
f32 y;
f32 z;
};
struct vec4 {
f32 x;
f32 y;
f32 z;
f32 t;
};
/* Subtype of s_window. See libkc3/window/types.h */
struct window_sdl2 {
sw x;
sw y;
uw w;
uw h;
bool fullscreen;
f_window_sdl2_button button;
f_window_sdl2_key key;
f_window_sdl2_load load;
f_window_sdl2_motion motion;
f_window_sdl2_render render;
SDL_Window *sdl_window;
f_window_sdl2_resize resize;
s_sequence *seq;
s_sequence *sequence;
uw sequence_count;
uw sequence_pos;
s_tag tag; // TODO: move sequence to tag
const char *title;
f_window_sdl2_unload unload;
uw gl_w;
uw gl_h;
float dpi;
float dpi_w;
float dpi_h;
};
/* 2 */
struct gl_cylinder {
s_gl_object object;
uw segments_u;
uw segments_v;
};
struct gl_light {
s_vec4 position; // in camera coordinates
s_rgb intensity;
};
struct gl_material {
f32 roughness;
bool metal;
s_rgba color;
};
struct gl_sphere {
s_gl_object object;
uw segments_u;
uw segments_v;
};
struct gl_square {
s_gl_object object;
uw segments_u;
uw segments_v;
};
struct gl_vertex {
f32 pos_x;
f32 pos_y;
f32 pos_z;
f32 normal_x;
f32 normal_y;
f32 normal_z;
f32 tex_coord_x;
f32 tex_coord_y;
};
struct sdl2_sprite {
s_gl_object object;
s_str path;
s_str real_path;
uw total_w;
uw total_h;
uw dim_x;
uw dim_y;
uw frame_count;
uw w;
uw h;
uw tex_w;
uw tex_h;
GLuint *texture;
};
/* 3 */
struct gl_camera {
f32 aspect_ratio;
f32 clip_z_far;
f32 clip_z_near;
f32 fov_y;
s_vec3 position;
s_vec3 rotation;
s_vec3 scale;
s_mat4 projection_matrix;
s_mat4 view_matrix;
s_mat4 model_matrix;
GLint light_count;
s_vec3 light_pos[GL_CAMERA_LIGHT_MAX];
s_vec3 light_pos_cam[GL_CAMERA_LIGHT_MAX];
s_rgb light_color[GL_CAMERA_LIGHT_MAX];
GLuint gl_projection_matrix_loc;
GLuint gl_view_matrix_loc;
GLuint gl_model_matrix_loc;
GLuint gl_enable_tex2d_loc;
GLuint gl_tex2d_loc;
GLuint gl_light_pos_loc;
GLuint gl_light_color_loc;
GLuint gl_material_rough_loc;
GLuint gl_material_metal_loc;
GLuint gl_material_color_loc;
GLuint gl_shader_program;
};
struct gl_ortho {
f32 x1;
f32 x2;
f32 y1;
f32 y2;
f32 clip_z_near;
f32 clip_z_far;
s_vec3 position;
s_vec3 rotation;
s_vec3 scale;
s_mat4 projection_matrix;
GLuint gl_projection_matrix_loc;
s_mat4 view_matrix;
GLuint gl_view_matrix_loc;
s_mat4 model_matrix;
GLuint gl_model_matrix_loc;
GLuint gl_enable_tex2d_loc;
GLuint gl_tex2d_loc;
GLuint gl_color_loc;
GLuint gl_shader_program;
s_gl_square square;
};
#endif /* LIBKC3_WINDOW_SDL2_TYPES_H */