Advertisement
KanjiCoder

QUORA_GRAPHICS_QUESTION

Mar 8th, 2022
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1.     #include <stdint.h>
  2.  
  3.     //:For Example, in non-toy code don't allocate on
  4.     //:the stack like this.
  5.     #define WID  32  
  6.     #define HIG  64
  7.     #define RGBA  4
  8.     uint8_t img[ WID * HIG * RGBA ]={ 0 };
  9.  
  10.     //:Y loop on outside to traverse pixels in order,
  11.     //:which should help prevent cache misses.
  12.     for( int y = 0 ; y <=( HIG-1 ) ; y ++ ){
  13.     for( int x = 0 ; x <=( WID-1 ) ; x ++ ){
  14.  
  15.         //: xy to index formula ://
  16.         int  i =( x + ( y * WID ) );
  17.  
  18.         //:Set a pixel:
  19.         img[ (i*RGBA)+0 ]=( 0xFF ) ; //:Set Red  ://
  20.         img[ (i*RGBA)+1 ]=( 0x44 ) ; //:Set Green://
  21.         img[ (i*RGBA)+2 ]=( 0x12 ) ; //:Set Blue ://
  22.         img[ (i*RGBA)+3 ]=(  255 ) ; //:Set Alpha://
  23.  
  24.     };;};;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement