Сам пользуюсь SDL2+OpenGL, самое простенькое что у себя нашёл - это пробная програмка для проверки взаимодействия SDL_ttf и OpenGL
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <climits>
void RenderText(std::string message, SDL_Color color, int x, int y, int size) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 1024, 0, 768); // m_Width and m_Height is the resolution of window
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
TTF_Font * font = TTF_OpenFont("trebucbd.ttf", size);
SDL_Surface * sFont = TTF_RenderText_Blended(font, message.c_str(), color);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sFont->w, sFont->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, sFont->pixels);
glBegin(GL_QUADS);
{
glTexCoord2f(0,0); glVertex2f(x, y);
glTexCoord2f(1,0); glVertex2f(x + sFont->w, y);
glTexCoord2f(1,1); glVertex2f(x + sFont->w, y + sFont->h);
glTexCoord2f(0,1); glVertex2f(x, y + sFont->h);
}
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glDeleteTextures(1, &texture);
TTF_CloseFont(font);
SDL_FreeSurface(sFont);
}
int main()
{
SDL_DisplayMode info;
info.w = 1024;
info.h = 768;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
{
return false;
}
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
SDL_Window* Surf_Display = SDL_CreateWindow("Window",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
info.w, info.h,
SDL_WINDOW_OPENGL);
if (Surf_Display == NULL)
{
std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_Renderer* sdlRender = SDL_CreateRenderer(Surf_Display, -1, 0);
if(sdlRender == NULL)
{
std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_GLContext GLContext = SDL_GL_CreateContext(Surf_Display);
if (TTF_Init() == -1)
{
printf("Unable to initialize SDL_ttf: %s \n", TTF_GetError());
}
SDL_Color color = {255, 0, 0, 0}; // Red
RenderText("Hello World", color, 5, 10, 12);
SDL_GL_SwapWindow(Surf_Display);
SDL_Delay(5000);
return 0;
}