Sdl_ttf & opengl problem

someone sent such a code for text rendering with sdl_ttf&opengl before::
*int TET_RenderText(char *text,TTF_Font *font,SDL_Color color,SDL_Rect
*location)
{

SDL_Surface *initial;
SDL_Surface *intermediary;
SDL_Rect rect;
int w,h;
int texture;
Uint32 rmask, gmask, bmask, amask;

/* Use SDL_TTF to render our text */
initial = TTF_RenderText_Blended(font, text, color);

/* Convert the rendered text to a known format */
w = nextpoweroftwo(initial->w);
h = nextpoweroftwo(initial->h);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;

#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, 50, 50, 32,
                               rmask, gmask, bmask, amask);

if(intermediary==NULL) exit(0);
SDL_BlitSurface(initial, 0, intermediary, 0);

/* Tell GL about our new texture */
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_BGRA,
        GL_UNSIGNED_BYTE, intermediary->pixels );

/* GL_NEAREST looks horrible, if scaled... */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    

/* prepare to render our texture */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f, 1.0f, 1.0f);

/* Draw a quad at location */
glBegin(GL_QUADS);
    /* Recall that the origin is in the lower-left corner
       That is why the TexCoords specify different corners
       than the Vertex coors seem to. */
    glTexCoord2f(0.0f, 1.0f);
        glVertex2f(location->x    , location->y);
    glTexCoord2f(1.0f, 1.0f);
        glVertex2f(location->x + w, location->y);
    glTexCoord2f(1.0f, 0.0f);
        glVertex2f(location->x + w, location->y + h);
    glTexCoord2f(0.0f, 0.0f);
        glVertex2f(location->x    , location->y + h);
glEnd();

/* Bad things happen if we delete the texture before it finishes */
glFinish();

/* return the deltas in the unused w,h part of the rect */
location->w = initial->w;
location->h = initial->h;

/* Clean up */
SDL_FreeSurface(initial);
SDL_FreeSurface(intermediary);
glDeleteTextures(1, &texture);

}

i use it in my code and only thing i see on the screen is a
rectangle(its edges) and my other opengl drawings…what are the possible
problems that i may do?Or that piece of code has errors in it?what is
missing? (note:in an sdl-only program i can easily display text on the
screen,but when openl enters the picture i have problems)*

El Viernes 22 Junio 2007, engin escribi?:

? ? intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, 50, 50, 32,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rmask, gmask, bmask, amask);

I’d say that it is caused because your texture’s width and height are not
power of two, and your card doesn’t handle it. It’s common on not so new
hardware. Try changing 50, 50 wtih 64, 64, for example.

SDL is primarily a software blitter, so it handles non power of two
regardless of the hardware (note that a software surface is being
requested).On 22/06/07, Alberto Luaces wrote:

El Viernes 22 Junio 2007, engin escribi?:

intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, 50, 50, 32,
rmask, gmask, bmask, amask);

I’d say that it is caused because your texture’s width and height are not
power of two, and your card doesn’t handle it. It’s common on not so new
hardware. Try changing 50, 50 wtih 64, 64, for example.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sorry, missed the rest of the code, the initial post was sent to my
spam filter for some reason. With opengl that would be a problem,
sorry.On 22/06/07, Brian <@Brian_Barrett> wrote:

SDL is primarily a software blitter, so it handles non power of two
regardless of the hardware (note that a software surface is being
requested).

On 22/06/07, Alberto Luaces wrote:

El Viernes 22 Junio 2007, engin escribi?:

intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, 50, 50, 32,
rmask, gmask, bmask, amask);

I’d say that it is caused because your texture’s width and height are not
power of two, and your card doesn’t handle it. It’s common on not so new
hardware. Try changing 50, 50 wtih 64, 64, for example.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

thanks for the replies but;

int nextpoweroftwo(int x)
{
double logbase2 = log(x) / log(2);
return round(pow(2,ceil(logbase2)));
}

there s the function above,i think it handles the "power of two"
problem…i changed the values 50,50 to 64,64 as Alberto Luaces said.But
i still see only the rectangle at the position that text should be???

Brian yazm??:> Sorry, missed the rest of the code, the initial post was sent to my

spam filter for some reason. With opengl that would be a problem,
sorry.

On 22/06/07, Brian <brian.ripoff at gmail.com> wrote:

SDL is primarily a software blitter, so it handles non power of two
regardless of the hardware (note that a software surface is being
requested).

On 22/06/07, Alberto Luaces wrote:

El Viernes 22 Junio 2007, engin escribi?:

intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, 50, 50, 32,
rmask, gmask, bmask, amask);

I’d say that it is caused because your texture’s width and height are not
power of two, and your card doesn’t handle it. It’s common on not so new
hardware. Try changing 50, 50 wtih 64, 64, for example.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You have to call SDL_CreateRGBSurface with the size of the text to be
rendered, so you have to write:

intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
rmask, gmask, bmask, amask);

so they match the subsequent call to

glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_BGRA,? ? ? ? ?
GL_UNSIGNED_BYTE, intermediary->pixels );

Also check what values are held into ‘w’, ‘h’, ‘color’, check that 'font’
and ‘text’ are valid pointers…

El Viernes 22 Junio 2007, engin escribi?:> thanks for the replies but;

int nextpoweroftwo(int x)
{
double logbase2 = log(x) / log(2);
return round(pow(2,ceil(logbase2)));
}

there s the function above,i think it handles the "power of two"
problem…i changed the values 50,50 to 64,64 as Alberto Luaces said.But
i still see only the rectangle at the position that text should be???

Brian yazm??:

Sorry, missed the rest of the code, the initial post was sent to my
spam filter for some reason. With opengl that would be a problem,
sorry.

On 22/06/07, Brian <brian.ripoff at gmail.com> wrote:

SDL is primarily a software blitter, so it handles non power of two
regardless of the hardware (note that a software surface is being
requested).

On 22/06/07, Alberto Luaces <@Alberto_Luaces_Ferna> wrote:

El Viernes 22 Junio 2007, engin escribi?:

intermediary = SDL_CreateRGBSurface(SDL_SWSURFACE, 50, 50, 32,
rmask, gmask, bmask, amask);

I’d say that it is caused because your texture’s width and height are
not power of two, and your card doesn’t handle it. It’s common on not
so new hardware. Try changing 50, 50 wtih 64, 64, for example.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org