tassopsaltakis / FilOS

The Friendly Python OS
https://github.com/tassopsaltakis/FilOS/
1 stars 1 forks source link

Graphics #27

Open Rijndael1998 opened 6 months ago

Rijndael1998 commented 6 months ago

We can eventually draw graphics on a screen using SDL. This means we'll be able to have our own graphics environment, graphical text editors, a mouse cursor, etc.

Drawing directly to the screen from a TTY (teletypewriter) interface in Linux is a bit unconventional, as TTYs are typically used for text-based interaction. However, it is possible to draw graphics to the screen by using certain libraries that can interface directly with the framebuffer or by using terminal graphics. SDL (Simple DirectMedia Layer) is a library that can facilitate this, but it's usually used within a graphical environment (like X11 or Wayland), not from a raw TTY.

To use SDL from a TTY, you'd have to run your Python program without a window manager. You'd need to have SDL (and possibly pygame, which is a set of Python wrappers for SDL) installed on your system.

Here's how you could potentially do it:

  1. Install Pygame, which is a set of Python modules designed for writing video games, that includes SDL bindings.

    pip install pygame
  2. Make sure you have the necessary privileges to access the framebuffer device (usually /dev/fb0). You might need to add your user to the video group or run your script as root. Please be aware of the security implications and risks involved in running scripts with elevated privileges.

  3. Write a Python script that uses Pygame to draw directly to the framebuffer.

Here is a simple example that sets up a Pygame display and fills it with a color:

import os
import pygame

# Ensure you set the SDL to use the framebuffer device
os.environ["SDL_FBDEV"] = "/dev/fb0"
os.environ["SDL_VIDEODRIVER"] = "fbcon"

# Initialize Pygame and the display
pygame.init()
info = pygame.display.Info()
screen = pygame.display.set_mode((info.current_w, info.current_h))

# Fill the screen with red
screen.fill((255, 0, 0))
pygame.display.flip()

# Wait for a while to see the color
pygame.time.wait(5000)

pygame.quit()

Remember to test this on a system where it's safe to make these changes, as configuring your system to work this way can affect its stability.

Alternatively, you could draw ASCII art or use ANSI escape codes to control the color and position of the terminal cursor to "draw" graphics in a terminal, but this would be text-based and not involve SDL.

If you need more advanced graphical capabilities, consider using Linux's framebuffer directly or other libraries like DirectFB (though it's less commonly used now), or otherwise, develop your application to run within a graphical desktop environment where you can use the full features of SDL and Pygame.

tassopsaltakis commented 6 months ago

Yes, this is going to come in handy when we are developing the Desktop Environment. Can't wait for that!

tassopsaltakis commented 5 months ago

As Kernel Injection time nears, we must blow the dust off this.