Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background image support for OpenGL #4226

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

yunusey
Copy link

@yunusey yunusey commented Dec 31, 2024

Partially fixes #3645.

Ghostty.Background.Image.Demo.Scaled.mp4

I apologize for the video quality - GitHub limits videos to be less than 10MB.

This PR adds support for setting background image dynamically for OpenGL only. Metal still needs its own implementation.

Because the only way to read the image data and decode to RGB/RGBA so that it is ready to be uploaded to the GPU is to use kitty.terminal.graphics with the project's current state, we only support PNG.

src/renderer/OpenGL.zig Outdated Show resolved Hide resolved
@yunusey yunusey requested a review from jcollie January 1, 2025 18:58
Copy link
Collaborator

@jcollie jcollie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to look very good! I'm sure others will have more to say about the rendering code as they have more experience, but I like it!

Screenshot From 2025-01-01 21-32-10

src/config/Config.zig Show resolved Hide resolved
src/renderer/opengl/BackgroundImageProgram.zig Outdated Show resolved Hide resolved
src/renderer/OpenGL.zig Outdated Show resolved Hide resolved
src/config/Config.zig Outdated Show resolved Hide resolved
@yunusey yunusey requested a review from jcollie January 2, 2025 20:56
src/config/Config.zig Show resolved Hide resolved
src/config/Config.zig Show resolved Hide resolved
src/renderer/OpenGL.zig Outdated Show resolved Hide resolved
src/renderer/shaders/bgimage.f.glsl Outdated Show resolved Hide resolved
src/renderer/OpenGL.zig Outdated Show resolved Hide resolved
src/renderer/OpenGL.zig Outdated Show resolved Hide resolved
@yunusey yunusey requested a review from jcollie January 2, 2025 22:20
Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work. I've left some review comments but overall this is looking good.

src/config/Config.zig Show resolved Hide resolved
src/config/Config.zig Show resolved Hide resolved
Copy link
Collaborator

@jcollie jcollie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good to me!

@yunusey yunusey requested a review from mitchellh January 3, 2025 03:38
@yunusey yunusey requested a review from jcollie January 6, 2025 19:08
@yunusey
Copy link
Author

yunusey commented Jan 12, 2025

@mitchellh, could you take a look at this? Are there any other changes needed here, or is it ready to go?

pseudocc pushed a commit to pseudocc/ghostty that referenced this pull request Jan 14, 2025
pseudocc pushed a commit to pseudocc/ghostty that referenced this pull request Jan 14, 2025
@jarodtaylor
Copy link

Ohhhh I can't wait for this to get in!

@sagg0t
Copy link

sagg0t commented Jan 31, 2025

Amazing work here, thank you very much!

And though it's kinda late to ask for such changes may I suggest another option for background-image-mode.
The reason being is that of all the modes implemented so far, if I want an image to fill my whole screen, I'm pretty much choosing between "scaled" mode, which deforms the image or "zoomed" mode, which leaves parts of the window uncovered by the image. And I personally don't find any of those aesthetically pleasing.

The way it should work is that the image is placed in the center, scaled to fill all the window background while preserving aspect ratio, and if the aspect ratio of the image doesn't match one of the terminal window, the part of the image that exceeds the window gets cut off (maybe name it "cropped" mode.)

For reference I can suggest MacOS wallpaper modes:

  • "zoomed" mode would be "Fit to Screen";
  • "scaled" mode would be "Stretch to Fill Screen";
  • and what I'm suggesting is "Fill screen".

I know it's a lot and I'd gladly implement it myself, but I'm barely familiar with Zig and have zero experience with shaders.
So please consider.

@yunusey
Copy link
Author

yunusey commented Feb 1, 2025

Amazing work here, thank you very much!

Thank you so much!

And though it's kinda late to ask for such changes may I suggest another option for background-image-mode. The reason being is that of all the modes implemented so far, if I want an image to fill my whole screen, I'm pretty much choosing between "scaled" mode, which deforms the image or "zoomed" mode, which leaves parts of the window uncovered by the image. And I personally don't find any of those aesthetically pleasing.

The way it should work is that the image is placed in the center, scaled to fill all the window background while preserving aspect ratio, and if the aspect ratio of the image doesn't match one of the terminal window, the part of the image that exceeds the window gets cut off (maybe name it "cropped" mode.)

I think that's a pretty nice mode. I've just implemented it, and as you requested, the mode's name is cropped. In order to use it, assuming you are on MacOS from your comment, you will probably need to wait until the same feature is implemented for Metal, which MacOS uses. @Rohit-Bevinahally probably will take care of that as well!

Here is a video demonstrating how the mode acts when the terminal is resized:

Ghostty.Cropped.Mode.mp4

The video quality is pretty bad, but hope is sufficient for demonstration purposes.

I know it's a lot and I'd gladly implement it myself, but I'm barely familiar with Zig and have zero experience with shaders.
So please consider.

Thanks a lot for commenting again, I think it is a pretty nice feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Window background image configuration option
8 participants