I have this code:
/* extract single color component from hexadecimal color */
uint8_t ext_col(uint32_t value, int color) {
return (value >> (color * 8)) & 0xff;
}
glBegin(GL_POINTS);
for (uint16_t y = 0; y < image->height; y+=1) {
for (uint16_t x = 0; x < image->width; x+=1) {
uint32_t p = image->data[y * image->width + x]; /* get pixel data */
glColor3ub(
ext_col(p, 0), /* red */
ext_col(p, 1), /* green */
ext_col(p, 2)); /* blue */
glVertex2i(x, y);
}
}
glEnd();
and it works fine, but just a bit slow, is there anyway to speed this up further, maybe some assembly tricks?
This is the furthest I've optimised it from my previous instance (5x faster), but it still renders a 750x350 image slower than 60 fps.
Since ext_col is such a small frequently called function I'd suggest making it inline to get rid of the overhead associated with calling a function. See https://stackoverflow.com/a/145841/7218062. Setting optimization to -O3 will probably do this automatically.