I'm trying to modify a texture pixel by pixel using a framebuffer, In my code I'm trying to fill the texture with white pixels, nothing seems to work.
#include <iostream>
#include <SDL3/SDL.h>
int main() {
SDL_Window* window = SDL_CreateWindow("test", 500, 500, 0);
SDL_Renderer* renderer = SDL_CreateRenderer(window, "test");
SDL_Texture* screen_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 500, 500);
uint32_t framebuffer[500 * 500];
SDL_FRect dest_rect = {0, 0, 500, 500};
for (int i = 0; i < 500*500; i++) {
framebuffer[i] = 0xFFFFFFFF;
}
bool running = true;
SDL_Event e;
while (running) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
running = false;
}
}
SDL_RenderClear(renderer);
SDL_UpdateTexture(screen_texture, NULL, framebuffer, 500 * 4);
SDL_RenderTexture(renderer, screen_texture, nullptr, &dest_rect);
SDL_RenderPresent(renderer);
SDL_Delay(16);
}
}
Take a look at:
SDL_Renderer * SDL_CreateRenderer(SDL_Window *window, const char *name);
Function Parameters
| Type | Name | Description |
|---|---|---|
SDL_Window * |
window |
the window where rendering is displayed. |
const char * |
name |
the name of the rendering driver to initialize, or NULL to let SDL choose one. |
When you give it the name parameter "test", you request a driver named test, which most probably don't exist.
Let SDL3 choose one for you - and check the return values for errors:
SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
// let SDL3 choose driver ^^^^^^^
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateRenderer: %s",
SDL_GetError());
return 1;
}
You should also call SDL_Init(SDL_INIT_VIDEO) at startup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With