TTF_RenderText_Solid错误

时间:2016-12-02 15:58:00

标签: c++ opengl sdl

我目前在使用SDL_TTF和OpenGL渲染文本时遇到了一个奇怪的错误。

当我使用 TTF_RenderText_Blended 时,所有文本都显示良好且没有任何问题

Rendering text with TTF_RenderText_Blended

但是当我想切换到 TTF_RenderText_Solid " buggy"显示黑色矩形,我不知道从表面创建正确的纹理时指定SDL_TTF或OpenGL的问题 TTF_RenderText_Solid

从textInfo(字体,大小)加载曲面的功能

% Your first plot is going to use the 0 - 2pi range for theta
theta1 = linspace(0, 2*pi, 1000);
rho1 = sin(theta1 * 5);
plot1 = polar(theta1, rho1);

hold on

% For your second plot, just transform your 0 - 100 range to be 0 - 360 instead
theta2 = 0:100;
rho2 = linspace(0, 1, numel(theta2));
modtheta2 = 2*pi * (theta2 ./ 100);
plot2 = polar(modtheta2, rho2);

% Now we need to modify all of the labels

% Find all of the original labels
labels = findall(gca, 'type', 'text');

% Figure out which ones are the radial labels. To do this we compute the distance 
% from the center of the plot and find the most common distance
distances = cellfun(@(x)norm(x(1:2)), get(labels, 'Position'));

% Figure out the most common
[~, ~, b] = unique(round(distances * 100));
h = hist(b, 1:max(b));
labels = labels(b == find(h == max(h)));

% Make a copy of these labels (have to use arrayfun for 4.0.x compatibility)
blacklabels = arrayfun(@(L)copyobj(L, gca), labels);

% Shift these labels outward by 15%
arrayfun(@(x)set(x, 'Position', get(x, 'Position') * 1.15), blacklabels);

% Now set the other labels to red and change their values
set(labels, 'COlor', 'red')
for k = 1:numel(labels)
    value = str2num(get(labels(k), 'String'))

    % Convert the value to be between 0 and 100
    newvalue = 100 * (value / 360);

    set(labels(k), 'String', sprintf('%0.2f', newvalue))
end

}

从SDL_Surface创建OpenGL纹理的功能

void TextSprite::loadSprite(const std::string& text, textInfo* info){
SDL_Surface* tmpSurface = nullptr;

tmpSurface = TTF_RenderText_Solid(info->font,text.c_str(), *_color);
if (tmpSurface==nullptr){
    ErrorManager::systemError("Cannot make a text texture");
}
createTexture(tmpSurface);

}

感谢您的帮助。

0 个答案:

没有答案