Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include <stdio.h>
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- #define rmask 0xff000000
- #define gmask 0x00ff0000
- #define bmask 0x0000ff00
- #define amask 0x000000ff
- #define rshift 24
- #define gshift 16
- #define bshift 8
- #define ashift 0
- #else
- #define rmask 0x000000ff
- #define gmask 0x0000ff00
- #define bmask 0x00ff0000
- #define amask 0xff000000
- #define rshift 0
- #define gshift 8
- #define bshift 16
- #define ashift 24
- #endif
- void PutPixel32( SDL_Surface *surface, int x, int y, Uint32 pixel )
- {
- //Convert the pixels to 32 bit
- Uint32 *pixels = (Uint32 *)surface->pixels;
- //Set the pixel
- pixels[ ( y * surface->w ) + x ] = pixel;
- }
- int main(int argc, char ** argv)
- {
- SDL_Window * window=NULL;
- SDL_Renderer *ren;
- SDL_Surface * Smain,*s1,*s2;
- SDL_Texture * Tmain,*t1,*t2;
- int x,y;
- SDL_Rect r;
- //Initialize SDL
- if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
- {
- return -1;
- }
- //create windows and renderer
- window = SDL_CreateWindow( "test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN );
- ren=SDL_CreateRenderer(window,-1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
- //create the main surfaces
- Smain= SDL_CreateRGBSurface(0,500,500,32,rmask,gmask,bmask,amask);
- s1= SDL_CreateRGBSurface(0,500,500,32,rmask,gmask,bmask,amask);
- s2= SDL_CreateRGBSurface(0,500,500,32,rmask,gmask,bmask,amask);
- //white background
- SDL_FillRect(Smain,NULL,0xffffffff);
- Tmain=SDL_CreateTextureFromSurface(ren,Smain);
- //create surface 1 with varied opacity with red color
- for(x=0;x<256;x++)
- {
- for(y=0;y<500;y++)
- {
- PutPixel32(s1,x,y,rmask| (x<<ashift));
- }
- }
- //fill the rest of red color, opacity 100%
- r.x=256;
- r.y=0;
- r.w=500-r.x;
- r.h=500;
- SDL_FillRect(s1,&r,rmask|amask);
- //blit surface when it should have the bug
- SDL_BlitSurface(s1,NULL,s2,NULL);
- //create the rest of texture
- t1=SDL_CreateTextureFromSurface(ren,s1);
- t2=SDL_CreateTextureFromSurface(ren,s2);
- while (1)
- {
- //render t1
- SDL_RenderClear(ren);
- SDL_RenderCopy(ren,Tmain,NULL,NULL);
- SDL_RenderCopy(ren,t1,NULL,NULL);
- SDL_RenderPresent(ren);
- puts("t1");
- SDL_Delay(500);//wait
- //render t2
- SDL_RenderClear(ren);
- SDL_RenderCopy(ren,Tmain,NULL,NULL);
- SDL_RenderCopy(ren,t2,NULL,NULL);
- SDL_RenderPresent(ren);
- puts("t2");
- SDL_Delay(500);//wait
- }
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement