Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "hud.h"
- #include "cl_util.h"
- #include "com_model.h"
- #include <windows.h>
- #include <gl/gl.h>
- #include <gl/glext.h>
- #pragma comment(lib,"Opengl32.lib")
- #pragma warning(disable:4018)
- #pragma pack(push,1)
- typedef struct
- {
- byte identsize; // size of ID field that follows 18 byte header (0 usually)
- byte colourmaptype; // type of colour map 0=none, 1=has palette
- byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
- short colourmapstart; // first colour map entry in palette
- short colourmaplength; // number of colours in palette
- byte colourmapbits; // number of bits per palette entry 15,16,24,32
- short xstart; // image x origin
- short ystart; // image y origin
- short width; // image width in pixels
- short height; // image height in pixels
- byte bits; // image bits per pixel 8,16,24,32
- byte descriptor; // image descriptor bits (vh flip bits)
- } TGA_HEADER;
- #pragma pack(pop)
- int glLoadTgaFromPak(char* name,int dest)
- {
- // Длина файла и буффер под него:
- int len;
- byte*buff=gEngfuncs.COM_LoadFile(name,5,&len); // грузим файл
- int width,height; // размеры картинки
- TGA_HEADER hdr; // Заголовок файла
- if (!buff) // Если буффер=0 то файл не найден
- {
- return 0;
- }
- // копируем заголовок в отдельную переменную
- memcpy(&hdr,&buff[0],18);
- width=hdr.width;
- height=hdr.height;
- // предполагаем что у нас 24 битная картинка
- int type=GL_RGB;
- int bpp;
- // проверяем это
- switch(hdr.bits)
- {
- case 24:
- bpp=3;
- break;
- case 32:
- type=GL_RGBA;
- bpp=4;
- break;
- default:
- gEngfuncs.Con_Printf("glLoadTga(): file %s has unsupported bpp num: %d !\n",hdr.bits);
- return -1;
- }
- int imgsize=width*height*bpp;
- byte temp;
- // преобразуем BGR в RGB
- for(int i=18; i<int(imgsize); i+=bpp)
- {
- temp=buff[i];
- buff[i]=buff[i+2];
- buff[i+2] = temp;
- }
- byte*oldbuff=(byte*)malloc(imgsize);
- memcpy(oldbuff,&buff[18],imgsize);
- int dest_offset=18;
- for(i=height-1;i>=0;i--)
- {
- byte*src_line=&oldbuff[width*bpp*i];
- memcpy(&buff[dest_offset],src_line,width*bpp);
- dest_offset+=width*bpp;
- }
- free(oldbuff);
- glBindTexture(GL_TEXTURE_2D, dest); // делаем её текушей
- // Настраиваем мип маппинг
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glHint( GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST );
- glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE );
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, type,width,height,0, type, GL_UNSIGNED_BYTE, &buff[18]);
- gEngfuncs.COM_FreeFile(buff);
- return dest;
- }
- bool g_tex_loaded=false;
- // запихнуть в CHud::Redraw - просто и надежно.
- void UploadWorldHDTextures()
- {
- if (g_tex_loaded) return;
- g_tex_loaded=true;
- model_t*world=gEngfuncs.GetEntityByIndex(0)->model;
- for(int i=0;i<world->numtextures;i++)
- {
- char file_path[260];
- sprintf(file_path,"gfx/textures/%s.tga",world->textures[i]->name);
- glLoadTgaFromPak(file_path,world->textures[i]->gl_texturenum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement