Guest User

Untitled

a guest
Jan 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. void render(unsigned int width, unsigned int height)
  2. {
  3.     // Allocate space for target image
  4.     float *pixel_data = new float[width * height * 3];
  5.  
  6.     // Do other stuff
  7.  
  8.     // Main rendering loop
  9.     float calculated_data[3];
  10.     for (unsigned int y = 0; y < height; ++y)
  11.     {
  12.         for (unsigned int x = 0; x < width; ++x)
  13.         {
  14.             // Calculate stuff
  15.             // and store in calculated_data
  16.  
  17.             // Write pixel
  18.             unsigned int pixel_index = (x + y*width)*3;
  19.             pixel_data[pixel_index + 0] = calculated_data[0];
  20.             pixel_data[pixel_index + 1] = calculated_data[1];
  21.             pixel_data[pixel_index + 2] = calculated_data[2];
  22.         }
  23.     }
  24.  
  25.     // Write image to png/bmp/...
  26.  
  27.     // Free memory (would be WAY more involved for a 3D array)
  28.     delete [] pixel_data;
  29. }
Add Comment
Please, Sign In to add comment