Note that there are some explanatory texts on larger screens.

plurals
  1. POMatch texture coordinates to primitive size
    primarykey
    data
    text
    <p>I'm working on font generation solution and facing texture problem. I'm creating texture atlas dynamically and then mapping every letter by their texture coordinates. </p> <p>Here's result of mapping "t" letter: (generated texture is on top and what I draw is on bottom)</p> <p><img src="https://i.stack.imgur.com/a1Yj3.png" alt="Problem"> It seem that the issue is that size of the primitive and texture region is not matching that's why openGL trying to resize it. I'm using GL_NEAREST on both Min and Mag when loading / rendering texture</p> <p>Here's the render code:</p> <pre><code>glBegin(GL_TRIANGLE_STRIP); float twidth = 7.f / 512.f; float theight = 11.f / 512.f; float width = 7.f; float height = 11.f; float w = width / 2.f; float h = height / 2.f; float x = 100; float y = 100; float tx = 135.f / 512.f; float ty = 0; glTexCoord2f(tx, ty); glVertex2f(x - w, y-h); glTexCoord2f(tx + twidth, ty); glVertex2f(x + w, y-h); glTexCoord2f(tx, ty + theight); glVertex2f(x - w, y+h); glTexCoord2f(tx + twidth, ty + theight); glVertex2f(x + w, y+h); glEnd(); </code></pre> <p>Here's initialization code:</p> <pre><code>glViewport(0,0,width,height); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); // Set up the GL state. glClearColor(1, 1, 1, 1); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); //glDisable(GL_BLEND); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, height, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); </code></pre> <p>Texture loading code:</p> <pre><code> glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, &amp;texBinary[0]); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload