Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use a dynamically sized texture array with glTexImage2D?
    primarykey
    data
    text
    <p>Currently, I'm able to load in a static sized texture which I have created. In this case it's 512 x 512.</p> <p>This code is from the header:</p> <pre><code>#define TEXTURE_WIDTH 512 #define TEXTURE_HEIGHT 512 GLubyte textureArray[TEXTURE_HEIGHT][TEXTURE_WIDTH][4]; </code></pre> <p>Here's the usage of glTexImage2D:</p> <pre><code>glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureArray); </code></pre> <p>And here's how I'm populating the array (rough example, not exact copy from my code):</p> <pre><code>for (int i = 0; i &lt; getTexturePixelCount(); i++) { textureArray[column][row][0] = (GLubyte)pixelValue1; textureArray[column][row][1] = (GLubyte)pixelValue2; textureArray[column][row][2] = (GLubyte)pixelValue3; textureArray[column][row][3] = (GLubyte)pixelValue4; } </code></pre> <p>How do I change that so that there's no need for TEXTURE_WIDTH and TEXTURE_HEIGHT? Perhaps I could use a pointer style array and dynamically allocate the memory...</p> <h3>Edit:</h3> <p>I think I see the problem, in C++ it can't really be done. The work around as pointed out by Budric is to use a single dimensional array but use all 3 dimensions multiplied to represent what would be the indexes:</p> <pre><code>GLbyte *array = new GLbyte[xMax * yMax * zMax]; </code></pre> <p>And to access, for example x/y/z of 1/2/3, you'd need to do:</p> <pre><code>GLbyte byte = array[1 * 2 * 3]; </code></pre> <p>However, the problem is, I don't think the <code>glTexImage2D</code> function supports this. Can anyone think of a workaround that would work with this OpenGL function?</p> <h3>Edit 2:</h3> <p>Attention OpenGL developers, this can be overcome by using a single dimensional array of pixels...</p> <blockquote> <p>[0]: column 0 > [1]: row 0 > [2]: channel 0 ... n > [n]: row 1 ... n > [n]: column 1 .. n</p> </blockquote> <p>... no need to use a 3 dimensional array. In this case I've had to use this work around as 3 dimensional arrays are apparently not strictly possible in C++.</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.
 

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