I want to load a texture and fill several arrays with texture data. I mean to load the image and maybe use glTexSubImage2D() to copy tiles from a loaded .bmp file into Glubyte arrays. Im not sure how to do this, what is the syntax for doing this? A tile is 14 pixels by 14 pixels and the large image will contain these tiles. How do you fill the Glubyte array?
glTexSubImage2D
copies data from client memory into an existing texture. glGetTexImage
copies the data from an existing texture into client memory. glGetTextureSubImage
(requires OpenGL 4.5 or the ARB_get_texture_sub_image
extension) copies a rectangle from an existing texture into client memory.
If you’re copying from client memory to client memory, that isn’t something OpenGL deals with.
The large file is loaded into a texture unit. Like its going to be used but its an atlas, which function can be used to copy the data into a array of glubyte or gluint. The array is like this.
//define colors for simplicity
#define White {0x00, 0x00, 0x00}
#define Black {0xff, 0xff, 0xff}
#define Red {0xff, 0x00, 0x00}
#define Blue {0x00, 0x00, 0xff}
//Create a texture
GLubyte ExampleWall[][3] =
{
Black, White,
Blue, Red,
};
I want to update this 2x2 texture array to hold 14 texels by 14 texels that is a piece of a large loaded texture file.
Im guessing you will have to copy the contents using
glReadPixels( x, y, width, height, GL_RGB , type);
Im not sure which type to select for the loaded texture but theres trial and error.
//LoadFromTextureAtlas Function
void LFTA(int LFTAStartX, LFTAStartY, int LFTAWidth, int LFTAHeight)
int num_components = 3; // For RGB
GLubyte* LFTAPixelData = new GLubyte[width * height * num_components];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, LFTAPixelData);
How do I make a function so I can load the data into texture arrays like the one I posted above? The array needs to be updated with the atlas information. I want
GLubyte ExampleWall[][3] = LFTA(0,14,14,14)
This call to LFTA should update or make a array in the programs ram so there can be as many textures as the ram can hold. Since its a GLubyte array it can be loaded using
glTexImage2D(GL_TEXTURE_2D, 0, 3, 14, 14, 0, GL_RGB, GL_UNSIGNED_BYTE, ExampleWall);
How do I make a function that makes a array named in the function call so it can be used with a string to name the new texture array.
For example
LFTA("NewTextureName",0,14,14,14);
This will make a new GLubyte array named NewTextureName that has 14 by 14 texels. It is offset 14 pixels into the image like it has skipped a tile of the same size.
//LoadFromTextureAtlas Function
void LFTA(???, int LFTAStartX, LFTAStartY, int LFTAWidth, int LFTAHeight)
int num_components = 3; //3 For RGB
GLubyte* LFTAPixelData = new GLubyte[width * height * num_components];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, LFTAPixelData);
The following is from an example
//Declare a 3D array to hold the pixel data
GLubyte pixels[w][h][3];
//Read pixels from the framebuffer into the array
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
I just need it in a function where I name the array by adding a name as a string to the function that doesnt have spaces.