Hey !
I recently started programming with OpenGL ans i want to draw a “GUI”.
I can draw text and i can draw quads with specific function i created.
The text is okay, the quad too, but when i draw both, the text no longer appears, as if it were hidden by quad…
Here is my code :
#include <GL\glew.h>
#include <GL\freeglut.h>
class Gui
{
private:
void Texte(int x, int y, char* txt);
void drawGuiBackground();
public:
Gui();
~Gui();
void drawGui();
};
#include "Gui.h"
#include <iostream>
void Gui::Texte(int x, int y, char * txt)
{
glRasterPos2f(x, y);
int len = (int)strlen(txt);
for (int i = 0; i < len; i++) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, txt[i]);
}
}
void Gui::drawGuiBackground()
{
const double w = glutGet(GLUT_WINDOW_WIDTH);
const double h = glutGet(GLUT_WINDOW_HEIGHT);
glRasterPos2f(0, 0);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0);
glVertex2f(0.0, 0.0);
glVertex2f(w, 0.0);
glVertex2f(w, h / 10);
glVertex2f(0.0, h / 10);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.0f, 1.0f, 0.0);
glVertex2f(0.0, 0.0);
glVertex2f(w/2, 0.0);
glVertex2f(w/2, h / 20);
glVertex2f(0.0, h / 20);
glEnd();
}
Gui::Gui()
{
}
Gui::~Gui()
{
}
void Gui::drawGui(){
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), 0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
Texte(0, 12, "Hey !");
drawGuiBackground();
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
Without quad draw:
[ATTACH=CONFIG]1503[/ATTACH]
with quad draw:
[ATTACH=CONFIG]1504[/ATTACH]
If you have a solution I’m interested.
Thanks