Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SetPixel and GetPixel

Name: Anonymous 2018-04-28 14:18

Just look at this:
https://stackoverflow.com/questions/39430404/drawing-pixels-in-opengl
a person asks how he can access individual pixels of the framebuffer, to which an expert programmer gives following answer:
it sounds like you're trying to use OpenGL in place of a really old graphics library that is required for a class. Since computer graphics have changed so much that what you're trying to do in modern OpenGL is unreasonable

Since when SetPixel became unreasonable? And people still believe that progress would make things easier, not harder! Naive idiots!

I'm starting to think Unabomber was right on all accounts. We need to bomb Khronos Group offices right away!

Name: Anonymous 2018-04-30 14:47

>>3
1193 lines

Why does it have to be so bloated? I can write triangle drawing code in C in less than 100 lines:
typedef struct lerp {
double x;
double i;
} lerp;

static void lerp_init(lerp *l, int sx, int ex, int first_step, int steps) {
l->i = (double)(ex - sx) / steps;
l->x = (double)sx + first_step*l->i;
}

static void lerp_advance(lerp *l) {
l->x += l->i;
}

#define SWAP(x,y) do {int t_ = x; x = y; y = t_;} while(0)

#define TRIANGLE_ROW(a,b) do { \
int x1 = (int)a.x; \
int x2 = (int)b.x; \
if (x1 < x2) gfx_hline(gfx, color, x1, y, x2-x1); \
else gfx_hline(gfx, color, x2, y, x1-x2); \
} while (0)

void gfx_triangle(gfx_t *gfx, uint32_t color, int ax, int ay, int bx, int by, int cx, int cy) {
int beg_y, cen_y, end_y;
int y, e;
lerp l, r;

if(ax < 0 && bx < 0 && cx < 0) return;
if(ax >= gfx->w && bx >= gfx->w && cx >= gfx->w) return;
if(ax == bx && ax == cx) return;

if (ay > by) {
SWAP(ax,bx);
SWAP(ay,by);
}

if (ay > cy) {
SWAP(ax,cx);
SWAP(ay,cy);
}

if(by > cy) {
SWAP(bx,cx);
SWAP(by,cy);
}

beg_y = ay;
cen_y = by;
end_y = cy;

if(end_y == beg_y || end_y < 0 || beg_y >= gfx->h) return;

if (beg_y < 0) {
lerp_init(&r, ax, cx, -beg_y, end_y-beg_y);
y = 0;
} else {
lerp_init(&r, ax, cx, 0, end_y-beg_y);
y = beg_y;
}

if (y < cen_y) {
if (beg_y < 0) lerp_init(&l, ax, bx,-beg_y, cen_y-beg_y);
else lerp_init(&l, ax, bx, 0, cen_y-beg_y);

if (cen_y > gfx->h) e = gfx->h;
else e = cen_y;

for (; y < e; ++y) {
TRIANGLE_ROW(l,r);
lerp_advance(&l);
lerp_advance(&r);
}
}

if(cen_y < end_y) {
lerp_init(&l, bx, cx, y-cen_y, end_y-cen_y);
if (end_y > gfx->h) end_y = gfx->h;

for (; y < end_y; ++y) {
TRIANGLE_ROW(l,r);
lerp_advance(&l);
lerp_advance(&r);
}
}
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List