Hi everyone
i am also having troubles using SDL_ttf with SLD2.0, not at compilation but at execution time.
i don’t know whether i should create a new discussion, please move it if need be.
what happens is that the surface created using the TTF_RenderText_Shaded() function doesn’t look like it is usable by SDL2.0. (i also tried with the ‘solid’ version).
it throws a violation access exception when used by SDL_CreateTextureFromSurface().
i then tried to convert it to another format before i try to create a texture from it, creating an RGB surface and copying the text surface in it, but i got the same violation access error at the SDL_BlitSurface() function call.
here is my code:
Code:
void CMagivCtl::addProgressText(string str)
{
int ret=0;
SDL_Window w_progress;
SDL_Renderer r_progress;
//SDL_Rect dst_progress;
TTF_Font *font_progress;
SDL_Color text_color_progress = {0, 255, 255};
SDL_Color text_color_2 = {1,234,45};
log("entering %s",__FUNCTION__);
w_progress = SDL_CreateWindow("opening...",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
445, 300,
SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS);
r_progress = SDL_CreateRenderer(w_progress, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
log("%s: created renderer",__FUNCTION__);
SDL_SetRenderDrawColor(r_progress, 0, 0, 0, 255);
SDL_RenderClear(r_progress);
SDL_RenderPresent(r_progress);
// Load a font
font_progress = TTF_OpenFont(POLICY_CLIBRIL.c_str(), 10);
if (font_progress == NULL)
{
log("%s: TTF_OpenFont() Failed: %d\n",__FUNCTION__,TTF_GetError);
}
SDL_Surface *surface = TTF_RenderText_Shaded(font_progress,"hello",text_color_progress,text_color_2);
if (surface == NULL)
{
log("%s: error creating text surface",__FUNCTION__);
}
else
log("%s: text surface created ok: %d, 0x%x",__FUNCTION__,surface,surface);
SDL_Surface *recast = SDL_CreateRGBSurface(0,surface->w,surface->h,24,0,0,0,0);
log("%s: surface w: %d, surface h: %d",__FUNCTION__,surface->w,surface->h);
ret = SDL_BlitSurface(surface,NULL,recast,NULL);
if(ret != 0)
log("%s: error %d in blit surface: %s",__FUNCTION__,ret,SDL_GetError());
SDL_Texture *texture = SDL_CreateTextureFromSurface(r_progress,recast);
if(texture == 0)
log("%s: unable to create texture: error: %s",__FUNCTION__,SDL_GetError());
else
{
log("%s: texture created",__FUNCTION__);
//SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
ret = SDL_RenderCopy(r_progress,texture,NULL,NULL);
if(ret < 0)
log("%s: unable to copy texture to renderer: error: %s (%d)",__FUNCTION__,SDL_GetError(),ret);
else
{
log("%s: texture copied to renderer",__FUNCTION__);
SDL_RenderPresent(r_progress);
SDL_DestroyTexture( texture );
SDL_FreeSurface( recast );
SDL_FreeSurface( surface );
}
}
}
I am implementing an ActiveX control using Visual Studio 8 under Windows7 (64bits)
I am using the SDL_VS2008.sln solution from the SDL-2.0.0-7046 package, and SDL_ttf-2.0.11 library.
what am i doing wrong?
in the previous post, sam talks about “hardware accelerated font system”, and openGL.
could that solve my issue, or it is just for compilation issues?
thanks for your help, in advance.
Etienne