From a9ea9216abfffef0fc178dab08c8207ed2c88a94 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 14 Feb 2013 23:00:39 -0500 Subject: [PATCH] draw quad for player --- src/game.d | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/game.d b/src/game.d index a481ded..21983d3 100644 --- a/src/game.d +++ b/src/game.d @@ -6,6 +6,13 @@ import derelict.opengl.glu; enum int WIDTH = 800; enum int HEIGHT = 600; +class Player +{ + public: + int x; + int y; +}; + void init() { glClearColor (0.0, 0.0, 0.0, 0.0); @@ -13,26 +20,22 @@ void init() glViewport(0, 0, WIDTH, HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(60.0, cast(GLfloat)WIDTH/cast(GLfloat)HEIGHT, 1.0, 30.0); + glOrtho(0, WIDTH, 0, HEIGHT, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); } -void display() +void display(Player p) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); - glRotatef(SDL_GetTicks() * 90.0 / 1000, 0, 0, 1); + glTranslatef(p.x, p.y, 0); 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); + glVertex3f(10, 20, 0.0); + glVertex3f(-10, 20, 0.0); + glVertex3f(-10, -20, 0.0); + glVertex3f(10, -20, 0.0); glEnd(); glPopMatrix(); SDL_GL_SwapBuffers(); @@ -44,6 +47,10 @@ int main(char[][] args) DerelictGL.load(); DerelictGLU.load(); + Player p1 = new Player(); + p1.x = WIDTH / 2; + p1.y = HEIGHT / 2; + if (SDL_Init(SDL_INIT_EVERYTHING)) { writefln("Failed to initialize SDL!"); @@ -74,7 +81,7 @@ int main(char[][] args) break; } } - display(); + display(p1); } SDL_Quit();