👨‍💻
Guide
Laura's GithubSimon's Github
  • What is this gitbook for?
  • 🛠️Useful tools
    • 🏁Header files
    • 🧱C Structures
    • 🔗Linked Lists (todo)
    • 📄Makefiles
    • 🔄Switch statement
    • 🗃️File descriptors (FD)
  • 🖌️MiniLibX
    • MiniLibX Helper Function
    • MiniLibX Hook Examples
  • 0️⃣ Rank 00
    • Libft
      • 📑LIBC functions
        • ft_isalpha
        • ft_isdigit
        • ft_isalnum
        • ft_isascii
        • ft_isprint
        • ft_strlen
        • ft_memset
        • ft_bzero
        • ft_memcpy
        • ft_memmove
        • ft_strlcpy
        • ft_strlcat
        • ft_toupper
        • ft_tolower
        • ft_strchr
        • ft_strrchr
        • ft_strncmp
        • ft_memchr
        • ft_memcmp
        • ft_strnstr
        • ft_atoi
        • ft_calloc
        • ft_strdup
      • 📑Additional functions
        • ft_substr
        • ft_strjoin
        • ft_strtrim
        • ft_split
        • ft_itoa
        • ft_strmapi
        • ft_striteri
        • ft_putchar_fd
        • ft_putstr_fd
        • ft_putendl_fd
        • ft_putnbr_fd
      • 📑Bonus functions
        • ft_lstnew
        • ft_lstadd_front
        • ft_lstsize
        • ft_lstlast
        • ft_lstadd_back
        • ft_lstdelone
        • ft_lstclear
        • ft_lstiter
        • ft_lstmap
  • 1️⃣ Rank 01
    • Born2beRoot
      • 📠What's a virtual machine ?
      • 📠Install your virtual machine
      • 📠P2P Evaluation - Questions
    • ft_printf
      • ▪️Variadic functions
      • ▪️Building the thing
    • get_next_line
      • ▪️open() & read()
      • ▪️Static variables
      • ▪️Building the thing
      • ▪️Commented solution
  • 2️⃣ Rank 02
    • so_long
      • ▪️Understand so_long
      • ▪️Core concepts
      • ▪️Building the thing
    • pipex
      • ▪️Understand pipex
      • ▪️Functions used
      • ▪️Building the thing
    • minitalk
      • ▪️Understand minitalk
      • ▪️Functions used
      • ▪️Building the thing
    • push_swap
      • ▪️Algorithms
      • ◾Building the thing
    • FdF
      • 🗡️Understand FdF
      • 🗡️Graphics programming
      • 🗡️Building the thing
  • 3️⃣ RANK 03
    • Philosophers
      • ▪️Understand Philosophers
      • ▪️Functions used
      • ▪️Building the thing
    • Minishell
      • ▪️Understand Minishell
      • ▪️Functions
      • ◾Building the thing
  • 4️⃣ RANK 04
    • CPP (00 - 04) (doing)
      • CPP00
      • CPP01
      • CPP02
      • CPP03
      • CPP04 (doing)
    • NetPractice
      • Theory
      • Level 1 & 2
    • MiniRT
      • Understand MiniRT
      • Building the thing
  • 5️⃣ RANK 05
    • CPP (05-09) (to-do)
      • CPP05
      • CPP06 (to-do)
      • CPP07
      • CPP08 (to-do)
      • CPP09 (to-do)
    • Inception (doing)
      • 🕓The basics (Docker, Images, etc...)
      • Project Files
    • webserv (to-do)
  • 6️⃣ rank 06
    • ft_transcendence (to-do)
  • 🛂Exams
    • Exam Rank 02
      • Level 1
        • first_word
        • fizz_buzz
        • *ft_putstr
        • *ft_strcpy
        • *ft_strlen
        • ft_swap
        • repeat_alpha
        • rev_print
        • rot_13
        • rotone
        • search_and_replace
        • ulstr
      • Level 2
        • alpha_mirror
        • camel_to_snake
        • do_op
        • *ft_atoi
        • *ft_strcmp
        • ft_strcspn
        • ft_strspn
        • *ft_strdup
        • ft_strpbrk
        • ft_strrev
        • inter
        • last_word
        • ft_is_power_2
        • max
        • print_bits
        • reverse_bits
        • wdmatch
        • swap_bits
        • union
        • snake_to_camel
      • Level 3
        • add_prime_sum
        • epur_str
        • expand_str
        • ft_atoi_base
        • ft_list_size
        • ft_range
        • ft_rrange
        • hidenp
        • lcm
        • paramsum
        • pgcd
        • print_hex
        • rstr_capitalizer
        • str_capitalizer
        • tab_mult
      • Level 4
        • flood_fil
        • fprime
        • ft_split
        • ft_itoa
        • ft_list_foreach
        • ft_list_remove
        • rev_wstr
        • rotstring
        • sort_int_tab
        • sort_list
    • Exam Rank 03
    • Exam Rank 04
    • Exam Rank 05
      • Module 0
  • 👥Team
Powered by GitBook
On this page
  • Display VS Window VS Image
  • Interacting with your program (with hooks)

Was this helpful?

  1. 2️⃣ Rank 02
  2. FdF

Graphics programming

Explanations of certain concepts to reduce confusion during the realization of the project

I had a lot of difficulty at the beginning to distinguish between all the terms I had just found on the web. This new chapter is a big one. Let's try to get some practice on this brand new chapter which is graphic programming (it's really fun, trust me :-) )

Display VS Window VS Image

When you start coding, the first thing you'll do is initialize your workspace. There are these three terms that I find very similar and I couldn't tell them apart, but in the end they are very different:

Display

A display is something that shows visual information. In the context of graphical programming, it refers to the physical device that displays the graphical user interface. For example, when you are using a computer, the display could be a monitor or a TV connected to the computer via HDMI.

Window

A window is a graphical element that represents a rectangular area on the display. It is used to display content, such as text, images, or videos. For example, a window might contain a text editor, a web browser, or a video player.

Image

An image is a two-dimensional array of pixels that can be displayed on the display. It can be a static image, such as a photograph, or a dynamic image, such as a video. In graphical programming, images are often used to display graphical elements, such as icons, backgrounds, or visual effects. They can be displayed by themselves or as part of a window.

Your displays, windows, and images can have several different sizes (defined in pixels). It's up to you to define which size best fits what you do and what you need. Here is a small diagram to better visualize:

[insert scheme]

Example in C

Before starting to do graphic programming you should always think about initiating a display and one or more windows and images.

int	main(void)
{
	void	*mlx; //display
	void	*mlx_win; //window
	t_data	image; //image

	mlx = mlx_init(); //display init
	mlx_win = mlx_new_window(mlx, 1920, 1080, "Hello world!"); //window init
	image.img = mlx_new_image(mlx, 1920, 1080); //image init
}

Interacting with your program (with hooks)

When you work on a graphic project, you will be able to interact with the window you are working on. You can for example close a window, zoom in/out and many other things. This can be done thanks to a thing called "hook".

A hook in computer science is a way to intercept and modify the behavior of a function or system call. It is often used to add additional functionality or to customize the behavior of a program or operating system.

Simple example of a hook

Imagine that you have a program that displays a message on the screen every time you press a certain key on the keyboard. You might want to add some additional behavior to this program, such as changing the color of the message or playing a sound every time the key is pressed.

To do this, you could "hook" the function that handles the key press events. When the key is pressed, your hook function would intercept the event and perform the additional behavior you want, such as changing the color of the message or playing a sound. Then, it would pass the event along to the original function so that the message can be displayed as usual.

Here is some pseudocode that shows how this might work:

//Original function that handles key press events
void OnKeyPress(Key key)
{
    // Display a message
    DisplayMessage("You pressed the key: " + key);
}

// Hook function that intercepts key press events
void Hooked_OnKeyPress(Key key)
{
    // Perform additional behavior
    ChangeMessageColor(Color.Red);
    PlaySound("beep.wav");

    // Pass the event along to the original function
    OnKeyPress(key);
}

// Hook the OnKeyPress function
void HookOnKeyPress()
{
    // Replace the OnKeyPress function with our hook function
    OnKeyPress = Hooked_OnKeyPress;
}

// Main program loop
void Main()
{
    // Hook the OnKeyPress function
    HookOnKeyPress();

    // Wait for key press events
    while (true)
    {
        Key key = WaitForKeyPress();
        OnKeyPress(key);
    }
}

This concept will be really userful for the rest of the project.

PreviousUnderstand FdFNextBuilding the thing

Last updated 1 year ago

Was this helpful?

🗡️