Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // study in quadrance / Wildberger's chromogeometry
- // https://www.flickr.com/photos/140786894@N03/albums/72157670200898221/with/28173892446/
- // https://www.youtube.com/watch?v=xgS9JBs5RV0
- #include <SDL.h>
- #include <stdio.h>
- #define pixelsize 4
- Uint32 pixels[256*256*pixelsize];
- struct pixl8_t {
- Uint8 blue,green,red,alpha;
- };
- void quitf() {
- printf("%s\n",SDL_GetError() );
- exit(0);
- }
- int main( int argc, char* args[] )
- {
- if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) quitf();
- if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) quitf();
- SDL_Window *window = SDL_CreateWindow( "mpixel",
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
- 256,256,
- SDL_WINDOW_SHOWN );
- if (!window) quitf();
- SDL_Renderer* renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
- if (!renderer) quitf();
- SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 );
- SDL_RenderClear( renderer );
- // http://gamedev.stackexchange.com/questions/87727/sdl-updatetexture-is-slow
- SDL_Texture* texture = SDL_CreateTexture(renderer,
- SDL_PIXELFORMAT_ARGB8888,
- SDL_TEXTUREACCESS_STREAMING,
- 256, 256);
- if( !texture ) quitf();
- bool quit = false;
- while (!quit)
- {
- SDL_Event event;
- while( SDL_PollEvent( &event ) )
- {
- if( event.type == SDL_QUIT ) quit = true;
- if( event.type == SDL_KEYDOWN ) {
- if ( event.key.keysym.sym == SDLK_ESCAPE ) quit = true;
- }
- }
- for (Uint32 i=0;i<256;i++) {
- for (Uint32 j=0;j<256;j++) {
- struct pixl8_t *p;
- p = (struct pixl8_t *)&pixels[j*256+i];
- p->red = p->green = p->blue = i*i+j*j;
- }
- }
- SDL_Delay(400);
- SDL_UpdateTexture( texture, NULL, pixels, 256 * pixelsize);
- SDL_RenderCopy( renderer, texture, NULL, NULL );
- SDL_RenderPresent( renderer );
- }
- SDL_DestroyTexture( texture );
- SDL_DestroyRenderer( renderer );
- SDL_DestroyWindow( window );
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement