#include "GLGuiButton.h" GLGuiButton::GLGuiButton() { texture.initLoader(); posX = 0; posY = 0; width = 0; heigth = 0; text = ""; texturePath = ""; click = false; button = GLUT_LEFT_BUTTON; state = GLUT_DOWN; } GLGuiButton::~GLGuiButton() { //Nothing } // === Fonction principal === void GLGuiButton::GLGuiButtonInit() { GLfloat infoViewport[4]; glGetFloatv(GL_VIEWPORT, infoViewport); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0.0, infoViewport[2], 0.0, infoViewport[3]); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glDisable(GL_DEPTH_TEST); } void GLGuiButton::GLGuiButtonClose() { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEnable(GL_DEPTH_TEST); } void GLGuiButton::GLGuiButtonDraw(int x, int y, int w, int h, void *font_name, string txt, string pathTexture) { posX = x; posY = y; width = w; heigth = h; text = txt; font = font_name; texturePath = pathTexture; glEnable(GL_TEXTURE_2D); texture.loadPNG(pathTexture); glBindTexture(GL_TEXTURE_2D, texture.getTexture()); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(posX, posY); glTexCoord2i(0, 1); glVertex2i(posX, posY+heigth); glTexCoord2i(1, 1); glVertex2i(posX+width, posY+heigth); glTexCoord2i(1, 0); glVertex2i(posX+width, posY); glEnd(); } void GLGuiButton::GLGuiButtonManageMouse(int mousse_button, int mouse_state, int mouse_x, int mouse_y, GLfloat vue) { if(mousse_button != button || mouse_state != state) //Vérifie que le bouton droite et cliqué return; GLint hits; GLuint slcbuffer[512]; GLfloat infoViewport[4]; glGetFloatv(GL_VIEWPORT, infoViewport); glSelectBuffer(512, slcbuffer); (void) glRenderMode(GL_SELECT); //Entre de le mode de selection (rien n'est dessiné) glInitNames(); //initialise la pile de nom glPushName(0); //Met la pile de nom a 0 glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix((GLdouble) mouse_x, (GLdouble) (infoViewport[3]-mouse_y), 5.0, 5.0, (GLint*) infoViewport); gluOrtho2D(0.0, infoViewport[2], 0.0, infoViewport[3]); glMatrixMode(GL_MODELVIEW); glLoadName(1); GLGuiButtonDraw(posX, posY, width, heigth, font, text, texturePath); glPopName(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits=glRenderMode(GL_RENDER); cout<0) { cout<<"[O.K] -> "<