That and how mindless drivel can seem funny when your're tired. Rest assured however that the code works properly.
After searching too long for a way to draw circles, meaning FILLED circles in irrlicht, nothing was found.
So, something was written. Feel free to integrate this inside your copies of irrlicht (it would be great for this to be added to the main branch, but whatever...)
You'll need to update CNullDriver.h, CNullDriver.cpp, IVideoDriver.h, IVideoDriver.cpp and your own code. Also works with OpenGL ES (for interested parties).
Code: Select all
void CNullDriver::draw2DPolygon(core::position2d<s32> center,
f32 radius, bool filled, bool outline, video::SColor color, s32 count)
{
if (count < 2)
return;
if(outline)
{
core::position2d<s32> first;
core::position2d<s32> a,b;
for (s32 j=0; j<count; ++j)
{
b = a;
f32 p = j / (f32)count * (core::PI*2);
a = center + core::position2d<s32>((s32)(sin(p)*radius), (s32)(cos(p)*radius));
if (j==0)
first = a;
else
draw2DLine(a, b, color);
}
draw2DLine(a, first, color);
}
// DRAW A FILLED CIRCLE IF ASKED FOR ONE
if(filled)
{
S3DVertex* vertices = new S3DVertex[count];
u16* indices = new u16[count];
vertices[0] = video::S3DVertex((f32)center.X, (f32)center.Y, 0.f, 0, 0, 1,color, 0, 0);
indices[0] = 0;
for (s32 i = 1; i < count; i++)
{
f32 p = i / (f32)(count - 2) * (core::PI*2);
vertices[i] = video::S3DVertex(
(f32)center.X + (radius * cos(p)),
(f32)center.Y + (radius * sin(p)),
0.f, 0, 0, 1, color, 0, 0);
indices[i] = i;
}
indices[count - 1] = 1;
video::SMaterial mtl;
mtl.Lighting = false;
mtl.Wireframe = false;
mtl.BackfaceCulling = false;
setMaterial(mtl);
draw2DVertexPrimitiveList(vertices, count, indices, count - 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT);
}
}
Code: Select all
void COGLES1Driver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
{
setTexture(0, Material.getTexture(0));
if (Material.MaterialType == EMT_ONETEXTURE_BLEND)
{
E_BLEND_FACTOR srcFact;
E_BLEND_FACTOR dstFact;
E_MODULATE_FUNC modulo;
u32 alphaSource;
unpack_texureBlendFunc ( srcFact, dstFact, modulo, alphaSource, Material.MaterialTypeParam);
setRenderStates2DMode( alphaSource&video::EAS_VERTEX_COLOR, (Material.getTexture(0) != 0), (alphaSource&video::EAS_TEXTURE) != 0 );
}
else
{
setRenderStates2DMode(Material.MaterialType == EMT_TRANSPARENT_VERTEX_ALPHA, (Material.getTexture(0) != 0), Material.MaterialType == EMT_TRANSPARENT_ALPHA_CHANNEL);
}
drawVertexPrimitiveList2d3d(vertices, vertexCount, (const u16*)indexList, primitiveCount, vType, pType, iType);
}
If Public Domain isn't recognized in your country, take a pick between WTFPL or zlib, as you see fit.
Also, if you believe I didn't credit someone else's work properly, please mention.
PS: If all goes well, I'll post a fixed-pipeline OpenGL ES texture splatting material snippet here soon.