miniRT
By Marcelo Magalhães and Ygor G. Sena, 2023.
canvas.h
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* canvas.h :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2023/03/17 18:28:08 by mdias-ma #+# #+# */
9 /* Updated: 2023/06/16 13:39:52 by yde-goes ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
14 #ifndef CANVAS_H
15 # define CANVAS_H
16 
17 # include "libft.h"
18 # include "mlx.h"
19 # include "camera.h"
20 # include "world.h"
21 
22 # define SCREEN_WIDTH 800
23 # define SCREEN_HEIGHT 400
24 
25 # define K_ESCAPE 0xff1b
26 # define K_Q 0x0071
27 # define DESTROYNOTIFY 17
28 # define NOEVENTMASK 0L
29 
52 typedef struct s_canvas
53 {
54  void *mlx_ptr;
55  void *win_ptr;
56  void *img_ptr;
57  char *addr;
58  int bpp;
59  int line_len;
60  int endian;
61  int width;
62  int height;
64 
74 typedef struct s_scene
75 {
76  t_world world;
77  t_camera camera;
79 
80 /* ************************************************************************** */
81 /* CANVAS.C */
82 /* ************************************************************************** */
83 
94 void init_mlx_connection(t_canvas *canvas);
95 
112 t_bool new_canvas(t_canvas *canvas, int width, int height);
113 
125 t_bool put_on_window(t_canvas *canvas, char *title);
126 
137 int show_window(t_canvas *canvas);
138 
139 /* ************************************************************************** */
140 /* CONTROLS.C */
141 /* ************************************************************************** */
142 
156 int handle_keypress(int keysym, t_canvas *canvas);
157 
169 int quit(t_canvas *canvas);
170 
171 /* ************************************************************************** */
172 /* RENDER.C */
173 /* ************************************************************************** */
174 
189 t_bool render(t_scene *scene, t_canvas *canvas);
190 
201 void write_pixel(const t_canvas *canvas, int x, int y, int color);
202 
203 #endif
t_bool put_on_window(t_canvas *canvas, char *title)
The function tries to create a new window on screen with the established Xserver connection,...
Definition: canvas.c:41
int quit(t_canvas *canvas)
quit() frees every data regarding graphic initialization and window rendering. It destroys the create...
Definition: controls.c:15
int handle_keypress(int keysym, t_canvas *canvas)
This function is to be used as the second parameter of the MLX library function mlx_key_hook(),...
Definition: controls.c:24
struct s_canvas t_canvas
The struct of type t_canvas contains the necessary fields for graphic initialization and window rende...
void init_mlx_connection(t_canvas *canvas)
This function attempts to start a connection with Xserver using MLX library.
Definition: canvas.c:15
int show_window(t_canvas *canvas)
This function inserts an image to window. To do that, it needs from the parameter canvas a pointer to...
Definition: canvas.c:53
struct s_scene t_scene
The structure t_scene is how the user sees the ray tracing rendering. There is a camera from which th...
t_bool new_canvas(t_canvas *canvas, int width, int height)
This function attempts to start a connection with Xserver using MLX library. After that,...
Definition: canvas.c:24
t_bool render(t_scene *scene, t_canvas *canvas)
This functions renders a scene of ray casting objects. It attempts to initialize a connection to the ...
Definition: render.c:18
void write_pixel(const t_canvas *canvas, int x, int y, int color)
The function write_pixel() writes a pixel at (x, y) coordinates of the image, if a given coordinate i...
Definition: render.c:64
The structure of type t_camera contains the necessary information for camera configuration,...
Definition: camera.h:45
The struct of type t_canvas contains the necessary fields for graphic initialization and window rende...
Definition: canvas.h:53
The structure t_scene is how the user sees the ray tracing rendering. There is a camera from which th...
Definition: canvas.h:75
This struct contains everything related to the building of a ray tracing's world. The world has objec...
Definition: world.h:37