Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use</p> <pre><code>int width = 1024; int height = 1024; GLubyte * texture = new GLubyte[4*width*height]; ... glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureArray); delete [] texture; //remove the un-needed local copy of the texture; </code></pre> <p>However you still need to specify the width and height to OpenGL in glTexImage2D call. This call copies texture data and that data is managed by OpenGL. You can delete, resize, change your original texture array all you want and it won't make a different to the texture you specified to OpenGL.</p> <p><strong>Edit:</strong> C/C++ deals with only 1 dimensional arrays. The fact that you can do texture[a][b] is hidden and converted by the compiler at compile time. The compiler must know the number of columns and will do texture[a*cols + b].</p> <p>Use a class to hide the allocation, access to the texture.</p> <p>For academic purposes, if you really want dynamic multi dimensional arrays the following should work:</p> <pre><code>int rows = 16, cols = 16; char * storage = new char[rows * cols]; char ** accessor2D = new char *[rows]; for (int i = 0; i &lt; rows; i++) { accessor2D[i] = storage + i*cols; } accessor2D[5][5] = 2; assert(storage[5*cols + 5] == accessor2D[5][5]); delete [] accessor2D; delete [] storage; </code></pre> <p>Notice that in all the cases I'm using 1D arrays. They are just arrays of pointers, and array of pointers to pointers. There's memory overhead to this. Also this is done for 2D array without colour components. For 3D dereferencing this gets really messy. Don't use this in your code.</p>
 

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