[SDL] problem rendering fonts to texture

Artem Baguinski artm at v2.nl
Sat Oct 28 12:42:18 PDT 2006


On 28 Oct 2006, at 20:57, Sami Näätänen wrote:

>>>
>>> You can make a new surface with the width and height being values
>>> that are powers of two, and blit the SDL_ttf generated surface to
>>> it.
>>
>> better make an empty texture (pixels parameter to glTexImage2D ==
>> NULL) with power of two sizes and update / use only a part of it (use
>> glTexSubImage2D).
>
> This is faster and easier, but this still has the flat array problem
> (look my other mail). Although in this case it can be get around using
> the pitch/bpp instead of width (if the texture is wide enough of
> course).
> This can produce some artifact problems though.

it doesn't have flat array problem. (what's flat array???)

say your image is 65x65

you will have to use texture that is 128x128, you create it with e.g.
               glTexImage2D( GL_TEXTURE_2D, //GLenum target,
                             0, //GLint level,
                             GL_RGBA, //GLint internalformat,
                             128, //GLsizei width,
                             128, //GLsizei height,
                             0, //GLint border,
                             GL_RGBA, //GLenum format,
                             GL_UNSIGNED_BYTE, //GLenum type,
                             NULL); //const GLvoid *pixels )

then you will call
               glTexSubImage2D( GL_TEXTURE_2D, //GLenum target,
                                0, //GLint level,
                                0, //GLint xoffset,
                                0, //GLint yoffset,
                                65, //GLsizei width,
                                65, //GLsizei height,
                                GL_RGBA, //GLenum format,
                                GL_UNSIGNED_BYTE, //GLenum type,
                                surface->pixels); //const GLvoid  
*pixels )

this will redefine a 65x65 portion of the texture in the lower left  
corner.

when you display the texture you'll make the texture coordinates go  
from 0 to (65.0/128.0) in both dimensions (because you're only  
interested in part of the texture).






More information about the SDL mailing list