OpenGL Scale Single Pixel Line

后端 未结 2 1980
独厮守ぢ
独厮守ぢ 2020-11-27 23:47

I would like to make a game that is internally 320x240, but renders to the screen at whole number multiples of this (640x480, 960,720, etc). I am going for retro 2D pixel g

2条回答
  •  余生分开走
    2020-11-28 00:26

    There is no "320x240 glOrtho canvas". There is only the window's actual resolution: 960x720.

    All you are doing is scaling up the coordinates of the primitives you render. So, your code says to render a line from, for example, (20, 20) to (40, 40). And OpenGL (eventually) scales those coordinates by 3 in each dimension: (60, 60) and (120x120).

    But that's only dealing with the end points. What happens in the middle is still based on the fact that you're rendering at the window's actual resolution.

    Even if you employed glLineWidth to change the width of your lines, that would only fix the line widths. It would not fix the fact that the rasterization of lines is based on the actual resolution you're rendering at. So diagonal lines won't have the pixelated appearance you likely want.

    The only way to do this properly is to, well, do it properly. Render to an image that is actual 320x240, then draw it to the window's actual resolution.

    You'll have to create a texture of that size, then attach it to a framebuffer object. Bind the FBO for rendering and render to it (with the viewport set to the image's size). Then unbind the FBO, and draw that texture to the window (with the viewport set to the window's resolution).

提交回复
热议问题