From 56605c2900355616806088f78ff0c11249f8d53b Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 14 Feb 2013 22:52:26 -0500 Subject: [PATCH] initial build system and template SDL/OpenGL demo --- .gitignore | 1 + Makefile | 15 ++++++++++ src/game.d | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/game.d diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc22e61 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +game diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..331399c --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ + +DC := gdc +TARGET := game +SOURCES := $(shell find src -iname '*.d') +OBJECTS := $(patsubst %.d,%.o,$(SOURCES)) +DFLAGS := -I/usr/local/include/d +LDFLAGS := -lDerelictSDL -lDerelictGL -lDerelictGLU -lDerelictUtil -ldl -lGL -lGLU + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(DC) -o $@ $^ $(LDFLAGS) + +%.o: %.d + $(DC) -o $@ $(DFLAGS) -c $^ diff --git a/src/game.d b/src/game.d new file mode 100644 index 0000000..a481ded --- /dev/null +++ b/src/game.d @@ -0,0 +1,83 @@ +import std.stdio; +import derelict.sdl.sdl; +import derelict.opengl.gl; +import derelict.opengl.glu; + +enum int WIDTH = 800; +enum int HEIGHT = 600; + +void init() +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_SMOOTH); + glViewport(0, 0, WIDTH, HEIGHT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, cast(GLfloat)WIDTH/cast(GLfloat)HEIGHT, 1.0, 30.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); +} + +void display() +{ + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(SDL_GetTicks() * 90.0 / 1000, 0, 0, 1); + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glVertex3f(5.0, 5.0, 0.0); + glColor3f(1, 0, 0); + glVertex3f(-5.0, 5.0, 0.0); + glColor3f(0, 0, 1); + glVertex3f(-5.0, -5.0, 0.0); + glColor3f(0, 1, 0); + glVertex3f(5.0, -5.0, 0.0); + glEnd(); + glPopMatrix(); + SDL_GL_SwapBuffers(); +} + +int main(char[][] args) +{ + DerelictSDL.load(); + DerelictGL.load(); + DerelictGLU.load(); + + if (SDL_Init(SDL_INIT_EVERYTHING)) + { + writefln("Failed to initialize SDL!"); + return 1; + } + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + SDL_Surface *screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_OPENGL); + if (screen == null) + { + printf("Failed to set video mode!\n"); + SDL_Quit(); + return 2; + } + + init(); + SDL_Event event; + for (;;) + { + if (SDL_PollEvent(&event)) + { + if (event.type == SDL_QUIT) + break; + else if (event.type == SDL_KEYDOWN) + { + if (event.key.keysym.sym == SDLK_ESCAPE) + break; + } + } + display(); + } + + SDL_Quit(); + + return 0; +}