I can currently load the static size texture that I created. In this case, it is 512 x 512.
This code is from the header:
#define TEXTURE_WIDTH 512
#define TEXTURE_HEIGHT 512
GLubyte textureArray[TEXTURE_HEIGHT][TEXTURE_WIDTH][4];
Here is the use of glTexImage2D:
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA,
TEXTURE_WIDTH, TEXTURE_HEIGHT,
0, GL_RGBA, GL_UNSIGNED_BYTE, textureArray);
And this is how I fill the array (an example, not an exact copy from my code):
for (int i = 0; i < 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;
}
How do I change this so that there is no need for TEXTURE_WIDTH and TEXTURE_HEIGHT? Perhaps I could use an array of pointer style and dynamically allocate memory ...
Edit:
I think I see a problem, in C ++ this cannot be done. The work that Budric talked about is to use a one-dimensional array, but use all 3 dimensions multiplied to represent the indices:
GLbyte *array = new GLbyte[xMax * yMax * zMax];
And for access, for example, x / y / z 1/2/3, you will need:
GLbyte byte = array[1 * 2 * 3];
, , glTexImage2D . - , OpenGL?
2:
OpenGL, , ...
[0]: column 0 > [1]: 0 > [2]: 0... n > [n]: 1... n > [n]: 1.. n
... . , 3- , -, ++.