Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok so, when I asked about "solid colour", I meant - "in that 8x8 pixel area in the .png that you are copying from, do all 64 pixels have the same identical RGB value?" It looks that way in your diagram, so how about this:</p> <p>How about creating an <code>SDL_Surface</code>, and directly painting 8x8 pixel areas of the memory pointed to by the <code>pixels</code> member of that <code>SDL_Surface</code> with the values read from the original .png.</p> <p>And then when you're done, convert that surface to an <code>SDL_Texture</code> and render <em>that</em>?</p> <p>You would avoid all the <code>SDL_UpdateTexture()</code> calls. </p> <p>Anyway here is some example code. Let's say that you create a class called <code>EightByEight</code>. </p> <pre><code> class EightByEight { public: EightByEight( SDL_Surface * pDest, Uint8 r, Uint8 g, Uint8 b): m_pSurface(pDest), m_red(r), m_green(g), m_blue(b){} void BlitToSurface( int column, int row ); private: SDL_Surface * m_pSurface; Uint8 m_red; Uint8 m_green; Uint8 m_blue; }; </code></pre> <p>You construct an object of type <code>EightByEight</code> by passing it a pointer to an <code>SDL_Surface</code> and also some values for red, green and blue. This RGB corresponds to the RGB value taken from the particular 8x8 pixel area of the .png you are currently reading from. You will paint a particular 8x8 pixel area of the <code>SDL_Surface</code> pixels with this RGB value.</p> <p>So now when you want to paint an area of the <code>SDL_Surface</code>, you use the function <code>BlitToSurface()</code> and pass in a column and row value. For example, if you divided the <code>SDL_Surface</code> into 8x8 pixel squares, BlitToSurface(3,5) means the paint the square at the 4th column, and 5th row with the RGB value that I set on construction.</p> <p>The <code>BlitToSurface()</code> looks like this:</p> <pre><code>void EightByEight::BlitToSurface(int column, int row) { Uint32 * pixel = (Uint32*)m_pSurface-&gt;pixels+(row*(m_pSurface-&gt;pitch/4))+column; // now pixel is pointing to the first pixel in the correct 8x8 pixel square // of the Surface's pixel memory. Now you need to paint a 8 rows of 8 pixels, // but be careful - you need to add m_pSurface-&gt;pitch - 8 each time for(int y = 0; y &lt; 8; y++) { // paint a row for(int i = 0; i &lt; 8; i++) { *pixel++ = SDL_MapRGB(m_pSurface-&gt;format, m_red, m_green, m_blue); } // advance pixel pointer by pitch-8, to get the next "row". pixel += (m_pSurface-&gt;pitch - 8); } } </code></pre> <p>I'm sure you could probably speed things up further by pre-calculating an RGB value on construction. Or if you're reading a pixel from the texture, you could probably dispense with the SDL_MapRGB() (but it's just there in case the Surface has different pixel format to the .png). </p> <p><code>memcpy</code> is probably faster than 8 individual assignments to the RGB value - but I just want to demonstrate the technique. You could experiment. </p> <p>So, all the <code>EightByEight</code> objects you create, all point to the same <code>SDL_Surface</code>. </p> <p>And then, when you're done, you just convert that <code>SDL_Surface</code> to an <code>SDL_Texture</code> and blit that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload