Hello, I am writing a program to generate and display two dimensional cellular automata as fast as possible.
In my quest for speed I am currently under the assumption that the fastest way to display the ca on screen is to write the ca data (0s and 1s) to a texture with some translation of the values to the desired rgba value (0 = black = 0, 0, 0, 0 and 1 = magenta = 255, 0, 255, 255). For the purpose of this question lets say that two arrays are neccessary(ca value & pixel color). I have plans to merge them once I can reliably control the display.
I am finding it difficult to use SDL_UpdateTexture for these purposes. I have some inherent misunderstanding of how the update texture reads the given pixel array, and was hoping to find some clarity.
ignoring the ca’s this is essentially what I have so far.
//init
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win;
SDL_Renderer *rend;
SDL_Texture *texture;
//define
win = SDL_CreateWindow("C.H.A.O.S.",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 800,
SDL_WINDOW_BORDERLESS);
rend = SDL_CreateRenderer(win,
-1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
t_length = 2
t_width = 2
texture = SDL_CreateTexture(rend,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
t_length,
t_width);
//pixels
int *pixels = malloc(( t_width * t_length* 4 * sizeof(int)));
for (int i=0; i<t_width * t_length * 4; i++){
*(pixels + i) = 0;
}
for (int i=0; i<t_width; i++) {
*(pixels + i) = 255;
}
SDL_UpdateTexture(texture, NULL, pixels, t_width * sizeof(*pixels));
SDL_RenderClear(rend);
SDL_RenderCopy(rend, texture, NULL, NULL);
SDL_RenderPresent(rend);
the final pixel array is [255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
this displays two blue boxes on the top of the screen and two black on the bottom.
I imagined the array would be interpreted as [r, g, b, a, r, g, b, a…], but that is where my intuition dies. Any help would be appreciated.
best, Chaotomata.