Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void make_tga_texture()
- {
- // open the file
- FILE *file = fopen("assets/ship3.tga","rb");
- assert( file != NULL && "could not open file" );
- // find length and allocate buffer
- fseek(file, 0, SEEK_END);
- int length = ftell(file);
- uchar *tmp = new uchar[length];
- // read the file
- fseek(file, 0, SEEK_SET);
- fread(tmp, 1, length, file);
- fclose(file);
- // convert the data
- TgaHeader *header = (TgaHeader*)tmp;
- uchar *data = tmp + sizeof(TgaHeader);
- int width = le2(header->width);
- int height = le2(header->height);
- // make sure this is the GIMP flavour
- assert(header->identsize == 0);
- assert(header->colourmaptype == 0);
- assert(header->imagetype == 2);
- assert(header->bits == 32);
- assert(header->descriptor == 8);
- // swap red and blue!
- /*
- for (int y = 0; y != width; ++y)
- {
- for (int x = 0; x != height; ++x)
- {
- uchar red = data[y * width * 3 + x*3 + 2];
- uchar blue = data[y * width * 3 + x*3 + 0];
- data[y * width * 3 + x*3 + 0] = red;
- data[y * width * 3 + x*3 + 2] = blue;
- }
- }
- */
- // build the texture
- glBindTexture(GL_TEXTURE_2D, state.textures[1]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void*)data);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- delete [] tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement