draw quad for player

This commit is contained in:
Josh Holtrop 2013-02-14 23:00:39 -05:00
parent 56605c2900
commit a9ea9216ab

View File

@ -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();