1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include "MPGE.h"
#define WIDTH 800
#define HEIGHT 600
MPGEint main (MPGEint argc, char** argv )
{
WindowHandler window;
EventHandler event;
FileHandler file;
Colorf bgcolor(0.0,0.0,1.0);
window.init(WIDTH,HEIGHT,32,MPGE_OPENGL_2D,false);
Primitive2D background ,carre;
Shader* v=file.loadShader("Shaders/defaultVertexShader_texture.txt",EST_VERTEX);
Shader* f=file.loadShader("Shaders/defaultFragmentShader_texture.txt",EST_FRAGMENT);
Shader* v1=file.loadShader("Shaders/defaultVertexShader_flat.txt",EST_VERTEX);
Shader* f1=file.loadShader("Shaders/defaultFragmentShader_flat.txt",EST_FRAGMENT);
background.setColor(Colorf(0.2,0.2,0.2,1.0));
background.setTexture(file.loadTexture("media/textures/dark1.jpg"));
ShaderHandler sh,sh1;
sh.setShaders(v,f);
sh.compile();
sh.sendAttribute(EAA_VERTEX,"in_Position");
sh.sendAttribute(EAA_COLOR,"in_Color");
sh.sendAttribute(EAA_TEXTURE,"in_TexCoord");
sh.execute();
sh1.setShaders(v1,f1);
sh1.compile();
sh1.sendAttribute(EAA_VERTEX,"in_Position");
sh1.sendAttribute(EAA_COLOR,"in_Color");
sh1.execute();
background.setPosition(Vector(400.0,400.0,0.0,0.0));
carre.setDimension(Vector(200,300));
carre.setPosition(Vector(20,280));
event.setFrameRate(30);
while (event.quit())
{
event.update();
window.beginDraw(bgcolor);
if(carre.isCollision(event.getMousePosition())) carre.setColor(Colorf(0.7,0.7,0.7,0.2));
else carre.setColor(Colorf(0.5,0.5,0.5,0.2));
window.pushProjectionMatrix();
sh.use(true);
sh.sendMatrix("mvMatrix",window.getModelViewMatrixStack().getCurrentMatrix());
sh.sendMatrix("pMatrix",window.getProjectionMatrixStack().getCurrentMatrix());
background.draw();
sh.use(false);
window.popProjectionMatrix();
window.pushProjectionMatrix();
window.setTranslation(carre.getPosition());
sh1.use(true);
sh1.sendMatrix("mvMatrix",window.getModelViewMatrixStack().getCurrentMatrix());
sh1.sendMatrix("pMatrix",window.getProjectionMatrixStack().getCurrentMatrix());
carre.draw();
sh1.use(false);
window.popProjectionMatrix();
window.endDraw();
event.delay();
}
(void)argc;
(void)argv;
return 0;
} |