说明
在AGG 2D渲染性能无法满足要求的情况下,尝试使用OpenGL作为2D渲染的底层库。当然在Android端,完全可以借助GPU的优势,进行渲染,这一点在以后的渲染中更具有优势,而且在需要使用到3D的情况下,OpenGL更是不二选择
目前在PC上测试渲染抗锯齿的直线,发现AGG的速度比OpenGL更好,当然没有充足的理由,并且实验的数据还仅仅是画线,具体的应用还需要有待研究
OpenGL代码
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <iostream>
#include <time.h>
#include <math.h>
//////////////////////////////////
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glLineWidth(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640,0.0,480);
}
/////////////////////////////////////
void myDisplay()
{
int start = clock();
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.f, 0.f);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
for (int i=0; i<100; i++)
{
glLineWidth(1);
glBegin(GL_LINES);
glVertex2d(200+i, 20);
glVertex2d(100+i, 300);
glEnd();
glFlush();
}
int end = clock();
int ret = end - start;
}
///////////////////////////////////////
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("my second attempt");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
AGG代码
void TestDrawSmoothLineSpeed()
{
int start = clock();
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ren_bas.clear(agg::rgba8(255,255,255));
agg::path_storage ps;
for (int i=0; i<1000; i++)
{
ps.move_to(200+i,20);
ps.line_to(100+i,300);
}
agg::conv_stroke<agg::path_storage> stroke(ps);
stroke.width(2);
ras.add_path(stroke);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
int end = clock();
int ret = end - start;
}