PDA

View Full Version : Pixel exact text rendering



cooky451
03-19-2013, 01:48 PM
Hi, I wrote a bitmap glyph renderer for text. It generates texture and screen coordinates for a given text, that I can then render. Okay. Now the shader looks like this:
float x = (text_pos.x + position.x) / dimensions.x * scale; float y = (text_pos.y + position.y) / dimensions.y * scale; gl_Position = vec4((x - 0.5) * 2, (-y + 0.5) * 2, 1.0, 1.0); It works quite good, but I wonder if there's a possibility to not have the dimensions division here and basically draw directly to the window pixels? Not only is this slightly slower, which is a minor concern considering I'm just rendering text here, but it also is kinda annoying to have to know the viewport resolution at this point.

tonyo_au
03-19-2013, 06:26 PM
Shaders don't know anything about windows so it cannot just "draw to a window pixel" they just set bits in a buffer on the gpu. You have to do the mapping like what you are doing.

cooky451
03-19-2013, 06:45 PM
Well at least the fragment shader has to more or less know something like a "pixel", since that's what it generates, isn't it? So I thought maybe I could kinda "avoid" the vertex shader, but that doesn't seem possible.

Alfonse Reinheart
03-19-2013, 06:52 PM
Well at least the fragment shader has to more or less know something like a "pixel", since that's what it generates, isn't it?

No. There's a reason why OpenGL doesn't call them "pixel shaders". Fragment shaders deal with fragments. A fragment is a piece of state generated by the rasterizer from a sample-sized section of a primitive. It isn't a pixel yet, and it may never become one.

If there are no primitives, then there can be no fragments. So yes, you need a vertex shader.