LCGE  v0.3.0-alpha
A Lightweight C game engine built with OpenGL
lcge.h
Go to the documentation of this file.
1 /*
2  LCGE - A Lightweight C Game Engine
3  Copyright (C) 2021 Satvik Reddy
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 
20  Satvik Reddy <reddy.satvik@gmail.com>
21 */
22 
23 /*
24  ___ ________ ________ _______
25  |\ \ |\ ____\|\ ____\|\ ___ \
26  \ \ \ \ \ \___|\ \ \___|\ \ __/|
27  \ \ \ \ \ \ \ \ \ __\ \ \_|/__
28  \ \ \____\ \ \____\ \ \|\ \ \ \_|\ \
29  \ \_______\ \_______\ \_______\ \_______\
30  \|_______|\|_______|\|_______|\|_______| v1.1.0
31 */
32 
33 #ifndef LCGE_H
34 #define LCGE_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _WIN32
41 #define LCGE_IMPORT __declspec(dllimport)
42 #else
43 #define LCGE_IMPORT
44 #endif
45 
46 #define LCGE_WINDOW_OPEN 1
47 #define LCGE_WINDOW_CLOSED 0
48 
49 #define LCGE_INIT_ERR -1
50 #define LCGE_INIT_OK 0
51 
52 #define LCGE_RESIZEABLE 1
53 #define LCGE_NON_RESIZEABLE 0
54 
55 #define LCGE_CONTEXT_ERR -1
56 #define LCGE_CONTEXT_OK 1
57 
139 LCGE_IMPORT extern int lcge_init(const char *lcge_res_dir);
140 
147 LCGE_IMPORT extern int lcge_create_context(unsigned int width,
148  unsigned int height,
149  const char *title, int resizable);
150 
158 
165 LCGE_IMPORT extern void lcge_exit();
166 
173 
178 
185 typedef struct LCGE_rect LCGE_rect;
186 
195 LCGE_IMPORT extern LCGE_rect *lcge_rect_load(float x, float y, float width,
196  float height);
197 
202 
208 LCGE_IMPORT extern void lcge_rect_draw(LCGE_rect *rect, float r, float g,
209  float b);
210 
217 LCGE_IMPORT extern void lcge_rect_set(LCGE_rect *rect, float x, float y,
218  float width, float height);
219 
225 LCGE_IMPORT extern void lcge_rect_rotate(LCGE_rect *rect, float angle);
226 
231 
236 
241 
246 
253 typedef struct LCGE_image LCGE_image;
254 
261 LCGE_IMPORT extern LCGE_image *lcge_image_load(const char *filepath, float x,
262  float y, float width,
263  float height);
264 
269 
275 LCGE_IMPORT extern void lcge_image_rotate(LCGE_image *image, float angle);
276 
281 
287 LCGE_IMPORT extern void lcge_image_set(LCGE_image *image, float x, float y,
288  float width, float height);
289 
294 
299 
304 
309 
314 
321 typedef struct LCGE_clock LCGE_clock;
322 
329 LCGE_IMPORT extern LCGE_clock *lcge_clock_create(unsigned int fps);
330 
335 
342 
343 /* Same values as GLFW keys */
344 #define LCGE_KEY_SPACE 32
345 #define LCGE_KEY_APOSTROPHE 39 /* ' */
346 #define LCGE_KEY_COMMA 44 /* , */
347 #define LCGE_KEY_MINUS 45 /* - */
348 #define LCGE_KEY_PERIOD 46 /* . */
349 #define LCGE_KEY_SLASH 47 /* / */
350 #define LCGE_KEY_0 48
351 #define LCGE_KEY_1 49
352 #define LCGE_KEY_2 50
353 #define LCGE_KEY_3 51
354 #define LCGE_KEY_4 52
355 #define LCGE_KEY_5 53
356 #define LCGE_KEY_6 54
357 #define LCGE_KEY_7 55
358 #define LCGE_KEY_8 56
359 #define LCGE_KEY_9 57
360 #define LCGE_KEY_SEMICOLON 59 /* ; */
361 #define LCGE_KEY_EQUAL 61 /* = */
362 #define LCGE_KEY_A 65
363 #define LCGE_KEY_B 66
364 #define LCGE_KEY_C 67
365 #define LCGE_KEY_D 68
366 #define LCGE_KEY_E 69
367 #define LCGE_KEY_F 70
368 #define LCGE_KEY_G 71
369 #define LCGE_KEY_H 72
370 #define LCGE_KEY_I 73
371 #define LCGE_KEY_J 74
372 #define LCGE_KEY_K 75
373 #define LCGE_KEY_L 76
374 #define LCGE_KEY_M 77
375 #define LCGE_KEY_N 78
376 #define LCGE_KEY_O 79
377 #define LCGE_KEY_P 80
378 #define LCGE_KEY_Q 81
379 #define LCGE_KEY_R 82
380 #define LCGE_KEY_S 83
381 #define LCGE_KEY_T 84
382 #define LCGE_KEY_U 85
383 #define LCGE_KEY_V 86
384 #define LCGE_KEY_W 87
385 #define LCGE_KEY_X 88
386 #define LCGE_KEY_Y 89
387 #define LCGE_KEY_Z 90
388 #define LCGE_KEY_LEFT_BRACKET 91 /* [ */
389 #define LCGE_KEY_BACKSLASH 92 /* \ */
390 #define LCGE_KEY_RIGHT_BRACKET 93 /* ] */
391 #define LCGE_KEY_GRAVE_ACCENT 96 /* ` */
392 #define LCGE_KEY_WORLD_1 161 /* non-US #1 */
393 #define LCGE_KEY_WORLD_2 162 /* non-US #2 */
394 #define LCGE_KEY_ESCAPE 256
395 #define LCGE_KEY_ENTER 257
396 #define LCGE_KEY_TAB 258
397 #define LCGE_KEY_BACKSPACE 259
398 #define LCGE_KEY_INSERT 260
399 #define LCGE_KEY_DELETE 261
400 #define LCGE_KEY_RIGHT 262
401 #define LCGE_KEY_LEFT 263
402 #define LCGE_KEY_DOWN 264
403 #define LCGE_KEY_UP 265
404 #define LCGE_KEY_PAGE_UP 266
405 #define LCGE_KEY_PAGE_DOWN 267
406 #define LCGE_KEY_HOME 268
407 #define LCGE_KEY_END 269
408 #define LCGE_KEY_CAPS_LOCK 280
409 #define LCGE_KEY_SCROLL_LOCK 281
410 #define LCGE_KEY_NUM_LOCK 282
411 #define LCGE_KEY_PRINT_SCREEN 283
412 #define LCGE_KEY_PAUSE 284
413 #define LCGE_KEY_F1 290
414 #define LCGE_KEY_F2 291
415 #define LCGE_KEY_F3 292
416 #define LCGE_KEY_F4 293
417 #define LCGE_KEY_F5 294
418 #define LCGE_KEY_F6 295
419 #define LCGE_KEY_F7 296
420 #define LCGE_KEY_F8 297
421 #define LCGE_KEY_F9 298
422 #define LCGE_KEY_F10 299
423 #define LCGE_KEY_F11 300
424 #define LCGE_KEY_F12 301
425 #define LCGE_KEY_F13 302
426 #define LCGE_KEY_F14 303
427 #define LCGE_KEY_F15 304
428 #define LCGE_KEY_F16 305
429 #define LCGE_KEY_F17 306
430 #define LCGE_KEY_F18 307
431 #define LCGE_KEY_F19 308
432 #define LCGE_KEY_F20 309
433 #define LCGE_KEY_F21 310
434 #define LCGE_KEY_F22 311
435 #define LCGE_KEY_F23 312
436 #define LCGE_KEY_F24 313
437 #define LCGE_KEY_F25 314
438 #define LCGE_KEY_KP_0 320
439 #define LCGE_KEY_KP_1 321
440 #define LCGE_KEY_KP_2 322
441 #define LCGE_KEY_KP_3 323
442 #define LCGE_KEY_KP_4 324
443 #define LCGE_KEY_KP_5 325
444 #define LCGE_KEY_KP_6 326
445 #define LCGE_KEY_KP_7 327
446 #define LCGE_KEY_KP_8 328
447 #define LCGE_KEY_KP_9 329
448 #define LCGE_KEY_KP_DECIMAL 330
449 #define LCGE_KEY_KP_DIVIDE 331
450 #define LCGE_KEY_KP_MULTIPLY 332
451 #define LCGE_KEY_KP_SUBTRACT 333
452 #define LCGE_KEY_KP_ADD 334
453 #define LCGE_KEY_KP_ENTER 335
454 #define LCGE_KEY_KP_EQUAL 336
455 #define LCGE_KEY_LEFT_SHIFT 340
456 #define LCGE_KEY_LEFT_CONTROL 341
457 #define LCGE_KEY_LEFT_ALT 342
458 #define LCGE_KEY_LEFT_SUPER 343
459 #define LCGE_KEY_RIGHT_SHIFT 344
460 #define LCGE_KEY_RIGHT_CONTROL 345
461 #define LCGE_KEY_RIGHT_ALT 346
462 #define LCGE_KEY_RIGHT_SUPER 347
463 #define LCGE_KEY_MENU 348
464 
465 #define LCGE_KEY_PRESSED 1
466 #define LCGE_KEY_RELEASED -1
467 
468 #define LCGE_MOUSE_BUTTON_1 0
469 #define LCGE_MOUSE_BUTTON_2 1
470 #define LCGE_MOUSE_BUTTON_3 2
471 #define LCGE_MOUSE_BUTTON_4 3
472 #define LCGE_MOUSE_BUTTON_5 4
473 #define LCGE_MOUSE_BUTTON_6 5
474 #define LCGE_MOUSE_BUTTON_7 6
475 #define LCGE_MOUSE_BUTTON_8 7
476 #define LCGE_MOUSE_BUTTON_LAST LCGE_MOUSE_BUTTON_8
477 #define LCGE_MOUSE_BUTTON_LEFT LCGE_MOUSE_BUTTON_1
478 #define LCGE_MOUSE_BUTTON_RIGHT LCGE_MOUSE_BUTTON_2
479 #define LCGE_MOUSE_BUTTON_MIDDLE LCGE_MOUSE_BUTTON_3
480 
481 #define LCGE_MOUSE_BUTTON_PRESSED 1
482 #define LCGE_MOUSE_BUTTON_RELEASED -1
483 
489 LCGE_IMPORT extern int lcge_get_key(int key);
490 
501 
502 typedef struct LCGE_cursor_pos {
503  float x, y;
505 
507 
513 typedef struct LCGE_font LCGE_font;
514 
521 LCGE_IMPORT LCGE_font *lcge_font_load(const char *filepath, float height);
522 
527 
534 typedef struct LCGE_text LCGE_text;
535 
542 LCGE_IMPORT LCGE_text *lcge_text_load(const char *text, float x, float y,
543  LCGE_font *font);
544 
549 
555 LCGE_IMPORT void lcge_text_draw(LCGE_text *text, float r, float g, float b);
556 
562 LCGE_IMPORT void lcge_text_set(LCGE_text *text, const char *n_text, float x,
563  float y);
564 
571 
578 
583 
588 
589 typedef struct LCGE_line LCGE_line;
590 
591 LCGE_IMPORT LCGE_line *lcge_line_load(float x0, float y0, float x1, float y1);
593 
594 LCGE_IMPORT void lcge_line_draw(LCGE_line *line, float r, float g, float b);
595 LCGE_IMPORT void lcge_line_set(LCGE_line *line, float x0, float y0, float x1,
596  float y1);
597 
598 #ifdef __cplusplus
599 }
600 #endif
601 
602 #endif
LCGE_IMPORT void lcge_image_rotate(LCGE_image *image, float angle)
Rotates an image.
LCGE_IMPORT int lcge_init(const char *lcge_res_dir)
Initializes LCGE.
LCGE_IMPORT LCGE_clock * lcge_clock_create(unsigned int fps)
Creates a clock.
LCGE_IMPORT void lcge_image_delete(LCGE_image *image)
Deletes an image.
LCGE_IMPORT void lcge_text_set(LCGE_text *text, const char *n_text, float x, float y)
Set new data for text.
LCGE_IMPORT float lcge_image_get_width(LCGE_image *image)
Gets image width.
LCGE_IMPORT void lcge_image_draw(LCGE_image *image)
Draws a loaded image to the screen.
LCGE_IMPORT float lcge_image_get_height(LCGE_image *image)
Gets image height.
LCGE_IMPORT int lcge_window_is_open()
Returns whether or not the window is still open.
struct LCGE_cursor_pos LCGE_cursor_pos
LCGE_IMPORT void lcge_font_delete(LCGE_font *font)
Deletes a font.
LCGE_IMPORT void lcge_rect_draw(LCGE_rect *rect, float r, float g, float b)
Draw a loaded rectangle to the screen.
LCGE_IMPORT LCGE_rect * lcge_rect_load(float x, float y, float width, float height)
Loads rectangle data and returns a handle.
LCGE_IMPORT LCGE_line * lcge_line_load(float x0, float y0, float x1, float y1)
#define LCGE_IMPORT
Definition: lcge.h:43
LCGE_IMPORT float lcge_text_get_x(LCGE_text *text)
Gets x value of text.
LCGE_IMPORT void lcge_clock_tick(LCGE_clock *clock)
tickst the clock.
struct LCGE_clock LCGE_clock
Basic FPS clock.
Definition: lcge.h:321
LCGE_IMPORT LCGE_font * lcge_font_load(const char *filepath, float height)
Loads a font.
struct LCGE_rect LCGE_rect
A 2D rectangle.
Definition: lcge.h:185
LCGE_IMPORT float lcge_text_get_width(LCGE_text *text)
Gets the width of the text.
LCGE_IMPORT LCGE_cursor_pos lcge_get_cursor_position()
LCGE_IMPORT int lcge_create_context(unsigned int width, unsigned int height, const char *title, int resizable)
Create a window and get back a handle.
struct LCGE_font LCGE_font
A true type font.
Definition: lcge.h:513
LCGE_IMPORT float lcge_text_get_y(LCGE_text *text)
Gets y value of text.
struct LCGE_line LCGE_line
Definition: lcge.h:589
LCGE_IMPORT void lcge_image_set(LCGE_image *image, float x, float y, float width, float height)
Sets new data for a loaded image.
LCGE_IMPORT LCGE_image * lcge_image_load(const char *filepath, float x, float y, float width, float height)
Loads an image from a file.
LCGE_IMPORT float lcge_image_get_y(LCGE_image *image)
Gets image y.
LCGE_IMPORT void lcge_rect_set(LCGE_rect *rect, float x, float y, float width, float height)
Updates rectangle data for a loaded rectangle.
LCGE_IMPORT void lcge_line_delete(LCGE_line *line)
LCGE_IMPORT int lcge_get_mouse_button(int button)
Gets input status of a mouse button.
struct LCGE_text LCGE_text
2D text.
Definition: lcge.h:534
LCGE_IMPORT void lcge_text_delete(LCGE_text *text)
Deletes a text struct.
LCGE_IMPORT float lcge_image_get_x(LCGE_image *image)
Gets image x.
LCGE_IMPORT float lcge_rect_get_height(LCGE_rect *rect)
Gets the rectangle height.
LCGE_IMPORT float lcge_rect_get_x(LCGE_rect *rect)
Gets the rectangle x value.
LCGE_IMPORT void lcge_window_update()
Updates the window and polls for events.
LCGE_IMPORT void lcge_window_clear()
Clears the window.
LCGE_IMPORT void lcge_exit()
Exits lcge.
LCGE_IMPORT void lcge_rect_rotate(LCGE_rect *rect, float angle)
Rotates a loaded rectangle.
LCGE_IMPORT void lcge_clock_delete(LCGE_clock *clock)
Deletes a clock.
LCGE_IMPORT int lcge_get_key(int key)
Gets the input status of a key.
LCGE_IMPORT void lcge_text_draw(LCGE_text *text, float r, float g, float b)
Draws 2D text.
LCGE_IMPORT LCGE_text * lcge_text_load(const char *text, float x, float y, LCGE_font *font)
Loads a 2D text struct.
LCGE_IMPORT void lcge_image_reflect(LCGE_image *image)
Reflects an image horizontally 180 deg.
struct LCGE_image LCGE_image
A 2D image.
Definition: lcge.h:253
LCGE_IMPORT float lcge_rect_get_width(LCGE_rect *rect)
Gets the rectangle width.
LCGE_IMPORT float lcge_rect_get_y(LCGE_rect *rect)
Gets the rectangle y value.
LCGE_IMPORT void lcge_line_set(LCGE_line *line, float x0, float y0, float x1, float y1)
LCGE_IMPORT float lcge_text_get_height(LCGE_text *text)
Gets the height of the text.
LCGE_IMPORT void lcge_line_draw(LCGE_line *line, float r, float g, float b)
LCGE_IMPORT void lcge_rect_delete(LCGE_rect *rect)
Deletes a rectangle.
Definition: lcge.h:502
float y
Definition: lcge.h:503
float x
Definition: lcge.h:503