glium icon indicating copy to clipboard operation
glium copied to clipboard

How to render to a different resolution than window?

Open jjant opened this issue 4 years ago • 2 comments

Hi, I want to render a 128x128 canvas into a window of a possibly different size, how can I do this?

jjant avatar Dec 29 '21 19:12 jjant

I was having the same issue as yours, and I discovered what you have to do. I'm not 100% sure if this is what you're looking for, but there you go:

On your Window Builder variable, set it like this: let wb = glutin::window::WindowBuilder::new().with_inner_size(glium::glutin::dpi::LogicalSize::new(width, height)) replace the width and height variables with your desired resolution, which is 128x128.

I don't know what exactly each word on this code really means, because I'm a beginner. But I hope it helped to achieve what you want.

pvini07BR avatar Dec 30 '21 01:12 pvini07BR

You can render to any OpenGL texture using what are called framebuffer objects. In Glium, these are called "Surfaces".

Thus, you can simply create a 128x128 empty texture and then call texture.as_surface(), and render to it in the same way as the window.

However, I do recommend you specify a 16 bit format, since the default 8 bit textures only have enough resolution if you use an SRGB format. However, you can't use an SRGB texture as a surface.

fayalalebrun avatar May 12 '22 06:05 fayalalebrun