create a font and render a string
This commit is contained in:
parent
fe6a3bfdb0
commit
ee3670777e
@ -2,10 +2,15 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#define WIDTH 500
|
#define WIDTH 500
|
||||||
#define HEIGHT 500
|
#define HEIGHT 500
|
||||||
|
|
||||||
|
static FTFont * font;
|
||||||
|
|
||||||
void init(void)
|
void init(void)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, WIDTH, HEIGHT);
|
glViewport(0, 0, WIDTH, HEIGHT);
|
||||||
@ -14,21 +19,27 @@ void init(void)
|
|||||||
glShadeModel(GL_FLAT);
|
glShadeModel(GL_FLAT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(60.0, (GLfloat)WIDTH/(GLfloat)WIDTH, 1.0, 30.0);
|
gluOrtho2D(0, WIDTH, 0, HEIGHT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.0, 0.0, -3.6);
|
font = new FTTextureFont("/usr/share/fonts/truetype/freefont/FreeMono.ttf");
|
||||||
|
if (font->Error())
|
||||||
|
{
|
||||||
|
cerr << "Could not create font" << endl;
|
||||||
|
}
|
||||||
|
font->FaceSize(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(SDL_Window * window)
|
void display(SDL_Window * window)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex3f(-2.0, -1.0, 0.0);
|
glVertex3f(2.0, 202.0, 0.0);
|
||||||
glVertex3f(-2.0, 1.0, 0.0);
|
glVertex3f(2.0, 210.0, 0.0);
|
||||||
glVertex3f(0.0, 1.0, 0.0);
|
glVertex3f(10.0, 210.0, 0.0);
|
||||||
glVertex3f(0.0, -1.0, 0.0);
|
glVertex3f(10.0, 202.0, 0.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
font->Render("Hello");
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user