int main(void) { array_init(); draw_array(-1, -1); SORT_FUNCTION(array, ARRAY_SIZE, sizeof(array[0]), intcmp); draw_array(-1, -1); return 0; }
int main(int argc, char **argv) { array_count = argc > 1 ? atoi(argv[1]) : 64; int array[array_count]; for (int i = 0; i < array_count; i++) array[i] = i; array_base = array; shuffle(); draw_array(-1, -1); qsort(array, array_count, sizeof(array[0]), intcmp); draw_array(-1, -1); return 0; }
static int intcmp(const void *a, const void *b) { const int *ia = (int *) a, *ib = (int *) b; draw_array(ia - array, ib - array); return *ia - *ib; }
static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { int i; if ((gr->parent && !gr->parent->overlay_enabled) || (gr->parent && gr->parent->overlay_enabled && !gr->overlay_enabled)) { return; } #if USE_OPENGLES set_color(gr, gc); draw_array(gr, p, count, GL_LINE_STRIP); #else graphics_priv_root->dirty = 1; GLUtesselator *tess = gluNewTess(); // create a tessellator if (!tess) return; // failed to create tessellation object, return 0 GLdouble quad1[count][3]; for (i = 0; i < count; i++) { quad1[i][0] = (GLdouble) (p[i].x); quad1[i][1] = (GLdouble) (p[i].y); quad1[i][2] = 0; } // register callback functions gluTessCallback(tess, GLU_TESS_BEGIN, (void (APIENTRY *)(void)) tessBeginCB); gluTessCallback(tess, GLU_TESS_END, (void (APIENTRY *)(void)) tessEndCB); // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB); gluTessCallback(tess, GLU_TESS_VERTEX, (void (APIENTRY *)(void)) tessVertexCB); gluTessCallback(tess, GLU_TESS_COMBINE, (void (APIENTRY *)(void)) tessCombineCB); // tessellate and compile a concave quad into display list // gluTessVertex() takes 3 params: tess object, pointer to vertex coords, // and pointer to vertex data to be passed to vertex callback. // The second param is used only to perform tessellation, and the third // param is the actual vertex data to draw. It is usually same as the second // param, but It can be more than vertex coord, for example, color, normal // and UV coords which are needed for actual drawing. // Here, we are looking at only vertex coods, so the 2nd and 3rd params are // pointing same address. glColor4f(gc->fr, gc->fg, gc->fb, gc->fa); gluTessBeginPolygon(tess, 0); // with NULL data gluTessBeginContour(tess); for (i = 0; i < count; i++) { gluTessVertex(tess, quad1[i], quad1[i]); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); // delete after tessellation #endif }
static void draw_rectangle_es(struct graphics_priv *gr, struct point *p, int w, int h) { struct point pa[4]; pa[0]=pa[1]=pa[2]=pa[3]=*p; pa[0].x+=w; pa[1].x+=w; pa[1].y+=h; pa[3].y+=h; draw_array(gr, pa, 4, GL_TRIANGLE_STRIP); }
void aa_display(float *ep, float *vp) { int view_pass; glClear(GL_ACCUM_BUFFER_BIT); for( view_pass=0; view_pass<VPASSES; view_pass++ ){ view_volume(ep, vp, 1); draw_array(); glAccum(GL_ACCUM,1.0/(float)(VPASSES)); } glAccum(GL_RETURN,1.0); glutSwapBuffers(); }
static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { if ((gr->parent && !gr->parent->overlay_enabled) || (gr->parent && gr->parent->overlay_enabled && !gr->overlay_enabled)) { return; } #if !USE_OPENGLES || USE_OPENGLES2 glLineWidth(gc->linewidth); #endif #if USE_OPENGLES set_color(gr, gc); draw_array(gr, p, count, GL_LINE_STRIP); #else graphics_priv_root->dirty = 1; glColor4f(gc->fr, gc->fg, gc->fb, gc->fa); if (!gr->parent && 0 < gc->dash_count) { glLineStipple(1, gc->dash_mask); glEnable(GL_LINE_STIPPLE); } glBegin(GL_LINE_STRIP); int i; for (i = 0; i < count; i++) { struct point p_eff; p_eff.x = p[i].x; p_eff.y = p[i].y; glVertex2f(p_eff.x, p_eff.y); } glEnd(); if (!gr->parent && 0 < gc->dash_count) { glDisable(GL_LINE_STIPPLE); } #endif }
int intcmp(const void *a, const void *b) { const int *ia = (int *) a, *ib = (int *) b; draw_array(ia - array_base, ib - array_base); return *ia - *ib; }