1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <iostream>
#include <SDL2/SDL.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int SCREENHEIGHT = 600;
const int SCREENWIDTH = 600;
SDL_Window *window;
SDL_Texture *texture;
SDL_Renderer *renderer;
SDL_Event event;
Uint32 *buffer;
char str[] = {'a','d','a','m','\0'};
void screenInit(){
cout << str << endl;
memset(&str[2],'x',2); // memcopy works here
cout << str << endl;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0){
cout << "init error" << endl;
}
buffer = new Uint32[SCREENHEIGHT * SCREENWIDTH];
window = SDL_CreateWindow("Pixel manip",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED
,SCREENWIDTH,SCREENHEIGHT,SDL_WINDOW_RESIZABLE);
texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_STATIC,SCREENWIDTH,SCREENHEIGHT);
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_PRESENTVSYNC);
}
void updateTexture(){
memset(buffer,0,SCREENHEIGHT * SCREENWIDTH * sizeof(Uint32));
SDL_UpdateTexture(texture,NULL,buffer,SCREENWIDTH * sizeof(Uint32));
}
void render(){
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer,texture,NULL,NULL);
SDL_RenderPresent(renderer);
}
int SDL_main(int argc,char* argv[])
{
screenInit();
bool quit = false;
while(!quit){
SDL_PollEvent(&event);
if(event.type == SDL_QUIT){
quit = true;
}
updateTexture();
render();
}
}
|