alors je suis le code suivant (pièce):SDL renderer donne la merde sur ma fenêtre (comment utiliser renderer correctement)
_Bool create_new_window(rectanglestruct *rectangle, colorstruct *colorfill, char *winname)
{
....
log_printf("creating main renderer for window (window : %s)\n", ptr->winname);
// Setup renderer
SDL_Renderer *renderer = SDL_CreateRenderer(ptr->window, -1, SDL_RENDERER_ACCELERATED);
ptr->renderer = renderer;
if (colorfill != NULL)
{
log_printf("\n - background color set r=%d g=%d b=%d with opacity of %d\n", colorfill->r,colorfill->g,colorfill->b, colorfill->opacity);
// Set render color to red (background will be rendered in this color)
SDL_SetRenderDrawColor(ptr->renderer, colorfill->r,colorfill->g,colorfill->b, colorfill->opacity);
log_printf("background rendered\n");
}
// Clear window
SDL_RenderClear(ptr->renderer);
SDL_ShowWindow(ptr->window);
SDL_RenderPresent(ptr->renderer);
getchar();
avec
typedef struct SDL_Window SDL_Window;
typedef struct windowstruct {
char *winname;
SDL_Window *window;
SDL_Renderer *renderer;
struct windowstruct *next;
struct windowstruct *previous;
} windowstruct;
static windowstruct *root = NULL;
et
typedef struct colorstruct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t opacity;
} colorstruct;
Avec en:
_Bool start_SDL(void)
// scope this
{
//draw background
colorstruct *colorfill = malloc(sizeof(rectanglestruct));
colorfill->r = 0xFF;
colorfill->g = 0xFF;
colorfill->b = 0xFF;
colorfill->opacity = 0xFF;
rectanglestruct *winplace = malloc(sizeof(rectanglestruct));
winplace->x = 0;
winplace->y = 0;
winplace->w = 300;
winplace->h = 300;
create_new_window(winplace, colorfill, "appscreen");
free(colorfill);
free(winplace);
}
et
_Bool start_SDL(void)
{
//Initialization flag
_Bool success = true;
//Initialize SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
log_printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
success = false;
}
}
et je suis arrivé la sortie suivante (après deux ou trois fois):
Le point est que je pensais que le moteur de rendu était juste une copie de l'écran comme un tampon dans lequel vous pouvez écrire et actualiser sur l'écran. Mais je ne comprends pas?
pourquoi le downvote? S'il vous plaît fournir des commentaires constructifs. – MVT