From 340b4b2f344096034cc574c0a11b1aadb0aee0b5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 9 Jun 2014 19:38:59 -0400 Subject: [PATCH] add template source from sdl-opengl-bare --- .gitignore | 2 ++ Makefile | 11 +++++++++ Rakefile.rb | 19 ++++++++++++++++ freetype2gl3.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 Rakefile.rb create mode 100644 freetype2gl3.cc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a982578 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build +/.rsconscache diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..82f9409 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: default +default: + @rake $@ + +.PHONY: test +test: + @rake $@ + +.PHONY: clean +clean: + @rake $@ diff --git a/Rakefile.rb b/Rakefile.rb new file mode 100644 index 0000000..3afe0d5 --- /dev/null +++ b/Rakefile.rb @@ -0,0 +1,19 @@ +require "bundler" +Bundler.setup(:default) + +require "rake/clean" +require "rscons" + +NAME = "freetype2gl3" + +task :default do + Rscons::Environment.new do |env| + env.build_root = "build" + env["LIBS"] += ["SDL2", "GL"] + env.Program("^/#{NAME}", Dir["*.{cc,c}"]) + end +end + +task :clean do + Rscons.clean +end diff --git a/freetype2gl3.cc b/freetype2gl3.cc new file mode 100644 index 0000000..ef1f570 --- /dev/null +++ b/freetype2gl3.cc @@ -0,0 +1,59 @@ +#include +#include +#include + +#define WIDTH 500 +#define HEIGHT 500 + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); +} + +void display(SDL_Window * window) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + SDL_GL_SwapWindow(window); +} + +int main(int argc, char *argv[]) +{ + if (SDL_Init(SDL_INIT_VIDEO)) + { + printf("Failed to initialize SDL!\n"); + return 1; + } + + atexit(SDL_Quit); + + SDL_Window * window = SDL_CreateWindow(argv[0], + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + WIDTH, + HEIGHT, + SDL_WINDOW_OPENGL); + if (!window) + { + printf("Failed to create window!\n"); + SDL_Quit(); + return 2; + } + + SDL_GLContext gl_context = SDL_GL_CreateContext(window); + + init(); + display(window); + SDL_Event event; + while (SDL_WaitEvent(&event)) + { + if (event.type == SDL_QUIT) + break; + else if (event.type == SDL_KEYDOWN) + { + if (event.key.keysym.sym == SDLK_ESCAPE) + break; + if (event.key.keysym.sym == SDLK_RETURN) + display(window); + } + } +}