Anyways, to show you how to use it, I wrote a tutorial.
https://magicsnippet.wordpress.com/2017 ... -irrlicht/
For those of you who want to cut to the chase (and read the example code because it gets chopped off on Wordpress), here is the example:
Code: Select all
#include <agg_basics.h>
#include <agg_rendering_buffer.h>
#include <agg_rasterizer_scanline_aa.h>
#include <agg_scanline_p.h>
#include <agg_renderer_scanline.h>
// Color
//#include <agg_pxlfmt_rgba.h>
// For unclosed curve
#include <agg_conv_unclose_polygon.h>
// Specifically for the curve
#include <agg_conv_stroke.h>
#include <agg_conv_bspline.h>
// To save time picking a color
#define AGG_ARGB32
#include <examples/pixel_formats.h>
//
#include <irrlicht.h>
//
#include <math.h>
#define PI 3.1415926539
inline double
degToRad(double p) {
return (p * PI) / 180.;
}
class SineWavePoly {
agg::point_d position;
unsigned increment;
double amplitude;
double phase;
unsigned startX;
unsigned endX;
public:
SineWavePoly()
: position(0,0)
, increment(0)
, amplitude(10)
, phase(0)
, startX(0)
, endX(0)
{}
SineWavePoly&
setPosition(double nx, double ny) {
position.x = nx;
position.y = ny;
return *this;
}
SineWavePoly&
setAmplitude(double a) {
amplitude = a;
return *this;
}
SineWavePoly&
setPhase(double p) {
phase = degToRad(p);
return *this;
}
SineWavePoly&
setStartX(unsigned x) {
startX = x;
return *this;
}
SineWavePoly&
setEndX(unsigned x) {
endX = x;
return *this;
}
void rewind(unsigned) {
increment = 0;
}
unsigned vertex(double* x, double* y) {
*x = double(startX + increment);
double tx = degToRad(*x);
*x = *x + position.x;
*y = amplitude * sin(tx + phase) + position.y;
if ( increment > endX )
return agg::path_cmd_stop;
if ( increment == endX ) {
++increment;
return agg::path_cmd_end_poly;
}
if ( increment == 0 ) {
++increment;
return agg::path_cmd_move_to;
}
++increment;
return agg::path_cmd_line_to;
}
};
bool renderPolygon(irr::video::IImage* pImage, double resolution) {
if (!pImage)
return false;
// Create AGG stuff, setting the Irrlicht image->getData() as the buffer
SineWavePoly sinePoly;
sinePoly.setPosition(10,250).setStartX(0).setEndX(480).setAmplitude(50);
// Yes, it's technically u32 data, but Anti-Grain treats it as pixels composed of 1 byte/8 bit colors.
irr::u8* imgDataPtr = (irr::u8*) pImage->getData();
irr::core::dimension2du imgSize = pImage->getDimension();
agg::rendering_buffer renderingBuffer;
renderingBuffer.attach(imgDataPtr, imgSize.Width, imgSize.Height, pImage->getPitch());
// Alternatively:
//agg::rendering_buffer renderingBuffer( ... same args as passed to .attach() );
agg::pixfmt_bgra32 pixelFormat(renderingBuffer);
agg::renderer_base<agg::pixfmt_bgra32> rendererBase(pixelFormat);
agg::scanline_p8 scanLine;
agg::rasterizer_scanline_aa<> rasterizerAA;
// function-scope-limited typedef
typedef agg::conv_bspline conv_bspline_type;
// Normal version ****
//rasterizerAA.add_path(sinePoly);
// Unfilled, thick lines with controllable ends ****
agg::conv_stroke convStrokeSinePoly(sinePoly);
convStrokeSinePoly.width(2.0);
rasterizerAA.add_path(convStrokeSinePoly);
agg::render_scanlines_aa_solid(rasterizerAA, scanLine, rendererBase, agg::rgba(0.0, 0.7, 0.9));
// Bezier version ****
//conv_bspline_type sineBspline(sinePoly);
//sineBspline.interpolation_step(1.0 / resolution);
//agg::conv_stroke sineStroke(sineBspline);
//sineStroke.width(3.0);
//rasterizerAA.add_path(sineStroke);
//agg::render_scanlines_aa_solid(rasterizerAA, scanLine, rendererBase, agg::rgba(1,1,1));
return true;
}
int main() {
irr::core::dimension2du screenSize(500,500);
irr::video::SColor white(0xffffffff);
irr::core::vector2di zeroVector(0);
irr::IrrlichtDevice* device = irr::createDevice(irr::video::EDT_BURNINGSVIDEO, screenSize);
if ( !device ) return 1;
irr::video::IVideoDriver* videoDriver = device->getVideoDriver();
videoDriver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS, false);
videoDriver->setTextureCreationFlag(irr::video::ETCF_ALLOW_NON_POWER_2, true);
irr::core::recti srcRect(0,0,(irr::s32)screenSize.Width,(irr::s32)screenSize.Height);
irr::video::IImage* img = videoDriver->createImage(irr::video::ECF_A8R8G8B8, screenSize);
if (! renderPolygon(img, 20.0) )
return 1;
irr::video::ITexture* tex = videoDriver->addTexture(irr::io::path("image name"), img);
while ( device->run() ) {
videoDriver->beginScene();
videoDriver->draw2DImage(tex, zeroVector, srcRect, 0, white, true);
videoDriver->endScene();
}
img->drop();
device->drop();
return 0;
}