Skip to content

Commit 0c0c23b

Browse files
committed
Added SDL_ttf
1 parent 8b764d6 commit 0c0c23b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ALLFILES := $(wildcard $(SRC_HOME)/*) $(wildcard $(INCL_HOME)/*)
88
export CXX := g++
99
export LD := g++
1010
export CXXFLAGS := -g -I$(INCL_HOME) -std=c++0x -Wall
11-
export LDFLAGS := -L/usr/local/lib -lSDL2 -lGL -lGLU
11+
export LDFLAGS := -L/usr/local/lib -lSDL2 -lSDL2_ttf -lGL -lGLU
1212

1313
.PHONY: all
1414
all: $(EXECUTABLE)

include/Renderer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef RENDERER_H
22
#define RENDERER_H
33

4+
#include <string>
5+
46
#include <SDL2/SDL.h>
57
#include <SDL2/SDL_opengl.h>
68
#include <GL/gl.h>
@@ -12,6 +14,8 @@ void renderBoard(const GameBoard& board, const Player& perspective);
1214

1315
GLuint loadImageAsTexture(const std::string& name);
1416

17+
void renderText(const std::string& font, int fontSize, const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const std::string& text);
18+
1519
std::pair<float, float> coordToScreen(const Coordinate& coord);
1620
Coordinate screenToCoord(const std::pair<float, float>&);
1721

src/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <SDL2/SDL.h>
55
#include <SDL2/SDL_opengl.h>
6+
#include <SDL2/SDL_ttf.h>
67

78
#include <GL/gl.h>
89
#include <GL/glu.h>
@@ -49,11 +50,18 @@ void updateViewport(int width, int height) {
4950
* Main. Initializes SDL and the model, view, and controller. Also has the main game loop.
5051
*/
5152
int main(int argc, char *argv[]) {
53+
const int windowWidth = 900, windowHeight = 800;
54+
55+
if(TTF_Init()==-1) {
56+
std::cout << "Error in TTF_Init: " << TTF_GetError() << std::endl;
57+
return 2;
58+
}
59+
5260
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
5361
SDL_Window* displayWindow;
5462
SDL_Renderer* displayRenderer;
5563
SDL_RendererInfo displayRendererInfo;
56-
SDL_CreateWindowAndRenderer(900, 800, SDL_WINDOW_OPENGL, &displayWindow, &displayRenderer);
64+
SDL_CreateWindowAndRenderer(windowWidth, windowHeight, SDL_WINDOW_OPENGL, &displayWindow, &displayRenderer);
5765
SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
5866
/*TODO: Check that we have OpenGL */
5967
if ((displayRendererInfo.flags & SDL_RENDERER_ACCELERATED) == 0 ||
@@ -66,7 +74,7 @@ int main(int argc, char *argv[]) {
6674

6775
initOpenGL();
6876

69-
updateViewport(1024, 768);
77+
updateViewport(windowWidth, windowHeight);
7078

7179
vector<unique_ptr<Player>> players;
7280
players.emplace_back(unique_ptr<Player>(new Player("test")));

0 commit comments

Comments
 (0)