1 module meatbox.box;
2 
3 import meatbox.colour;
4 
5 import derelict.opengl3.gl;
6 
7 class Box
8 {
9 public:	
10 	alias color =colour;
11 	Colour colour;
12 	float x, y, width, height;
13 	this( float x, float y, float width, float height )
14 	{
15 		this.x =x; this.y =y;
16 		this.width =width; this.height =height;
17 	}
18 	this()
19 	{}
20 	static immutable float[8] vertices =
21 	[ 
22 		0f, 0f,
23 		1f, 0f,
24 		1f, 1f,
25 		0f, 1f
26 	];
27 	void render()
28 	{
29 		//glColor3ub( colour.red, colour.green, colour.blue );
30 		
31 		glPushMatrix();
32 		glTranslatef( x, y, 0);
33 		glScalef( width, height, 1f );
34 		glDrawArrays( GL_QUADS, 0, 4);
35 		glPopMatrix();	
36 	}
37 	static this()
38 	{
39 		//Preload box vectors into GPU memory.
40 		//Stick into base Box class?
41 	}
42 	///
43 	static void startRender()
44 	{
45 		glEnableClientState( GL_VERTEX_ARRAY );
46 		glEnable( GL_BLEND );
47 		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );	
48 		glColor4f( 1f, 1f, 1f, 1f );
49 		glVertexPointer( 2, GL_FLOAT, 0, Box.vertices.ptr );		
50 	}
51 	///
52 	static void endRender()
53 	{
54 		glDisable( GL_BLEND );
55 		glDisableClientState( GL_VERTEX_ARRAY );
56 	}
57 private:
58 }