Skip to content

Instantly share code, notes, and snippets.

@st4rk
Created Nov 25, 2016
Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#define FRAMEBUFFER_HEIGHT 256
#define FRAMEBUFFER_WIDTH 256
/** 24BPP Pixel */
typedef struct pixel {
unsigned char r;
unsigned char g;
unsigned char b;
} pixel;
int main(int argc, char **argv) {
pixel** framebuffer;
framebuffer = (pixel**) malloc (sizeof(pixel*) * FRAMEBUFFER_WIDTH);
for (int i = 0; i < FRAMEBUFFER_WIDTH; i++) {
framebuffer[i] = (pixel*) malloc (sizeof(pixel) * FRAMEBUFFER_HEIGHT);
}
for (int x = 0; x < FRAMEBUFFER_WIDTH; x++) {
for (int y = 0; y < FRAMEBUFFER_HEIGHT; y++) {
framebuffer[x][y].r = 255;
framebuffer[x][y].g = 0;
framebuffer[x][y].b = 25;
printf("R: %d\n", framebuffer[x][y].r);
printf("G: %d\n", framebuffer[x][y].g);
printf("B: %d\n", framebuffer[x][y].b);
}
}
for (int i = 0; i < FRAMEBUFFER_WIDTH; i++) {
free(framebuffer[i]);
}
free(framebuffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment