I’m looking for a way to render a pixel buffer directly to a screen. I need a way to do it on both OSX and Linux, although I know I will probably need to do it through different methods for each OS (although a cross platform library would be nice.) Where do you start?
Share
You can always use an orthographic projection of a quad to your backbuffer/surface.
Or just send the quad in NDC space (-1 to +1) without needing any matrix multiplication.
Update because this apparently isn’t clear enough:
For the “fullscreen quad” approach, send two tris or one quad like this:
The configuration/order of verts is dependant on your winding order and the primitive mode.
Zvalue should be between-1to1. You can just choose-1. Projection and ModelView matrix should be an identity matrix (that is all zeros, then 1’s on the main diagonal)In other words you dont need to do any matrix multiplication so you dont actually need any matrix ops in your shaders, since the coords are already in Normalized Device Coordinates (NDC).
i.e. it is alread inside the target device interval of
Here is some code:
The vertex shader is then just a direct passthrough to the pixel/fragment shader. Obviously you would set the relevant pixel/texture buffer as a shader resource/variable and sample it in the pixel/fragment shader. And dont forget to set the texcoord UV’s of the vertexes to their corresponding texture values (
0-1).Alternatively you could also use the corresponding windowing system to blit the texture directly to the window surface. This is highly dependant on what you are using for window management (e.g. SDL) and may also require a certain texture format/layout to work (or conversion).