1

I want the view of OpenGL to be pixelated.

I have tried using multiple shaders from around the internet, which shows a pixelated image as their outcome. But they work on textures and not in 3D models (Their edges to be pixelated).

This is what I have tried

And this is a reference of what I am expecting:

img

Is there any way of accomplishing it with shaders, or with code?

EDIT:

I used glFramebuffer from Makogan's answer, and it seems to be pixelated.

But another problem is encountered. The Framebuffer seems to be copying itself, which eventually creates a mess.

This is how it looks

This code is what I used to create the Framebuffer:

FBO = glGenFramebuffers(1)
DBO = glGenRenderbuffers(1)

glBindRenderbuffer(GL_RENDERBUFFER, DBO)
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1280, 720)

glBindFramebuffer(GL_FRAMEBUFFER, FBO)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DBO)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)

And this piece of code is in the main loop:

# draw everything

glBindFramebuffer(GL_FRAMEBUFFER, 0)
    
glBlitFramebuffer(
        640 - 256,
        360 - 144,
        640 + 256,
        360 + 144,
        0,
        0,
        640,
        360,
        GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
        GL_NEAREST
)
  • 1
    see [OpenGL Scale Single Pixel Line](https://stackoverflow.com/a/43654398/2521214) so simply you render into texture and then scale the texture ... – Spektre Nov 08 '20 at 09:28

1 Answers1

0

If you want to pixelate your output, just downscale the dimensions of the framebuffer you are rendering to to very small dimensions (say 256 x 256) and turn off all anti aliasing.

You will have 3D pixelated rendering.

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • Thanks for answering, I did some research on framebuffers and got it to work. Even though I am encountering a problem. The pixelated framebuffer is copying itself, as if it is repeating. How to fix that? Here is a picture: https://imgur.com/a/2FWa3yQ –  Nov 11 '20 at 10:27
  • That looks like you are not mapping the FB correctly to your viewport. – Makogan Nov 11 '20 at 15:16
  • Yes. I am mapping the FB as `(0, 0, 640, 360)`, while the window is `(0, 0, 1920, 1080)`. I created a new question on this problem here (things are mode detailed there): https://stackoverflow.com/questions/64786701/low-resolution-framebuffer-repeats-itself# –  Nov 11 '20 at 17:31