简体   繁体   中英

OpenGL 2D pixel perfect rendering

I'm trying to render a 2D image so that it will cover the entire window exactly.
For my test, I setup a window so that the client area is exactly 320x240 and the texture is also this size.
I setup my orthographic projection for a 1x1x1 cube centered at the origin, and set my viewport to 0,0,320,240
The texture is mapped to a quad of size 1x1 centered in the origin.
The shader is a trivial shader doing the Proj ModelView Pos

I created a test texture that will allow me to verify the rendering, and I see a consistent discrepancy I can't shake.
校准图片

The results of the rendering always some stretching that puts some of the pixels up and to the right of the window, and seem to be always by the same amount, regardless of the window size (same amount of pixels, if I replace 320x240 by another value)
在此处输入图片说明

I think it has to do with window decoration widths, but I'm not sure how to fix it so that the solution is not platform / machine specific.

EDITS:
The code is straight C++ using freeglut and glew
Verified that this doesn't happen if I call glutFullScreen, so it's definitely windowed mode related.

Note: this was answered before the language tag was added

Not sure what module you are using for this. If you are using Pyglet the easiest way is achieve this is:

import pyglet

width = 320
height = 240
window = pyglet.window.Window(width, height)
image = pyglet.resource.image('image.png')

@window.event
def on_draw():
    window.clear()
    image.blit(0, 0, 0, width, height)

pyglet.app.run()

You can find more information about this here: http://www.pyglet.org/doc/programming_guide/size_and_position.html http://www.pyglet.org/doc/programming_guide/displaying_images.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM