Sorry to dig up such an old topic ^^ But I gave up on GD (couldn't load pixel data into a texture, portability issues, trying to reduce external dependencies, lib doesn't seem to be maintained anymore, little to no community, etc.). I was thinking of using OpenGL functions to draw the chart directly, since I don't plan on using DirectX as a backend and OpenGL is already a requirement
Since I never tried using OpenGL directly (until now, Irrlicht's functions were enough for my needs), I searched a bit and found that I could do it with calling gluPartialDisk() in a GLUQuadric.
A bit of context first : I'm coding it in a custom GUI element (my game relies heavily on it).
So in the draw() method we have :
Code: Select all
const u32 m_width = this->AbsoluteRect.getWidth();
const u32 m_height = this->AbsoluteRect.getHeight();
const vector2di topLeft = this->AbsoluteRect.UpperLeftCorner;
// Prepare OpenGL view settings
glViewport(topLeft.X, topLeft.Y, m_width, m_height);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-0.5*m_width, 0.5*m_width, -0.5*m_height, 0.5*m_height, -1.0f, 1.0f);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glScaled(0.6f, 0.6f, 0.0f);
glTranslated(0.0, 0.0, 0.0);
GLUquadric* glQuadric = gluNewQuadric();
const u8 len = dataProvider.size();
for (u8 i = 0; i < len; ++i)
{
// Set color for the current data slice being drawn.
glColor3ub(dataProvider[i].color.getRed(), dataProvider[i].color.getGreen(), dataProvider[i].color.getBlue());
const f32 theAngle = (MAX_ANGLE / this->total) * dataProvider[i].value;
// Draw each portion of the pie chart
gluPartialDisk(glQuadric, 0, m_width / 2, slicesPerSegment, 1, lastAngle, theAngle);
lastAngle += theAngle;
}
gluDeleteQuadric(glQuadric);
In a pure OpenGL example app, this code (with a few modifications obviously) seems to work, but when I use it in my irrlicht GUI element, nothing shows up. I'm probably missing something (big). is it "safe" to make openGL calls in a GUIElement's draw() method ?
The GUI element is correctly positioned (calling driver->draw2DRectangle using its AbsoluteRect coordinates works fine). Also tried writing in a texture and save it to disk to see if anything was written on it, but the texture is blank (transparent).