draw quad for player
This commit is contained in:
parent
56605c2900
commit
a9ea9216ab
31
src/game.d
31
src/game.d
@ -6,6 +6,13 @@ import derelict.opengl.glu;
|
|||||||
enum int WIDTH = 800;
|
enum int WIDTH = 800;
|
||||||
enum int HEIGHT = 600;
|
enum int HEIGHT = 600;
|
||||||
|
|
||||||
|
class Player
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
@ -13,26 +20,22 @@ void init()
|
|||||||
glViewport(0, 0, WIDTH, HEIGHT);
|
glViewport(0, 0, WIDTH, HEIGHT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
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);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.0, 0.0, -10.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void display()
|
void display(Player p)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(SDL_GetTicks() * 90.0 / 1000, 0, 0, 1);
|
glTranslatef(p.x, p.y, 0);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(1, 1, 1);
|
|
||||||
glVertex3f(5.0, 5.0, 0.0);
|
|
||||||
glColor3f(1, 0, 0);
|
glColor3f(1, 0, 0);
|
||||||
glVertex3f(-5.0, 5.0, 0.0);
|
glVertex3f(10, 20, 0.0);
|
||||||
glColor3f(0, 0, 1);
|
glVertex3f(-10, 20, 0.0);
|
||||||
glVertex3f(-5.0, -5.0, 0.0);
|
glVertex3f(-10, -20, 0.0);
|
||||||
glColor3f(0, 1, 0);
|
glVertex3f(10, -20, 0.0);
|
||||||
glVertex3f(5.0, -5.0, 0.0);
|
|
||||||
glEnd();
|
glEnd();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
@ -44,6 +47,10 @@ int main(char[][] args)
|
|||||||
DerelictGL.load();
|
DerelictGL.load();
|
||||||
DerelictGLU.load();
|
DerelictGLU.load();
|
||||||
|
|
||||||
|
Player p1 = new Player();
|
||||||
|
p1.x = WIDTH / 2;
|
||||||
|
p1.y = HEIGHT / 2;
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING))
|
if (SDL_Init(SDL_INIT_EVERYTHING))
|
||||||
{
|
{
|
||||||
writefln("Failed to initialize SDL!");
|
writefln("Failed to initialize SDL!");
|
||||||
@ -74,7 +81,7 @@ int main(char[][] args)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
display();
|
display(p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user