I've tried to create a 2D array where each row is going to hold a texture/image values (RGBA) (where each column of the texture will be placed after each other in a row). The base for my texture will be all white, therefore I set all values to 1. However, when I print out the value it is 0 and not 1. Why does data[layer][x*m_Size+y+a] = 1; not set the value of that position to 1?
data = new int*[m_Size];
for(unsigned i = 0; i<m_Size; ++i){
data[i] = new int[m_Size*m_Size*4];
}
for(unsigned layer=0; layer<m_NumLayers; layer++){
for (unsigned x = 0; x < m_Size; x++){
for (unsigned y = 0; y < m_Size*4; y+=4){
data[layer][x*m_Size+y+r] = 1;
data[layer][x*m_Size+y+g] = 1;
data[layer][x*m_Size+y+b] = 1;
data[layer][x*m_Size+y+a] = 1;
printf("in data: %f \n,",data[layer][x*m_Size+y+a]);
}
}
}
m_NumLayersis more thanm_Size, then your loop will overflowdata.printf("in data: %d \n,",data[layer][x*m_Size+y+a]);instead ofprintf("in data: %f \n,",data[layer][x*m_Size+y+a]);