Advertisement
Aveneid

Untitled

Jan 9th, 2021
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. GLuint tex;
  2. GLbyte* loadTexture( GLint* w, GLint* h, GLint* ImComponents, GLenum* ImFormat) {
  3.     GLbyte* image;
  4.     int ch;
  5.     *ImComponents = GL_RGB8;
  6.     *ImFormat=GL_BGR_EXT;
  7.     GLbyte* pbitsperpixel = NULL;
  8.     image = (GLbyte*) stbi_load("t.jpg", w, h, &ch, 0);
  9.     if (image == NULL) {
  10.         std::cout << "error";
  11.         exit(2137);
  12.     }
  13.     switch (ch)
  14.     {
  15.         case 3:*ImFormat = GL_BGR_EXT;*ImComponents = GL_RGB8;break;
  16.         case 4:*ImFormat = GL_BGRA_EXT;*ImComponents = GL_RGBA8; break;
  17.         case 1:*ImFormat = GL_LUMINANCE;*ImComponents = GL_LUMINANCE8;break;
  18.     };
  19.     return image;
  20. }
  21.  
  22. void InitText() {
  23.     GLbyte* pBytes;
  24.     GLint ImWidth, ImHeight, ImComponents;
  25.     GLenum ImFormat;
  26.     glEnable(GL_CULL_FACE);
  27.     glCullFace(GL_FRONT);
  28.     pBytes = loadTexture(&ImWidth, &ImHeight, &ImComponents, &ImFormat);
  29.     glTexImage2D(GL_TEXTURE_2D, 0, ImComponents, ImWidth, ImHeight, 0, ImFormat, GL_UNSIGNED_BYTE, pBytes);
  30.     free(pBytes);
  31.     glEnable(GL_TEXTURE_2D);
  32.     glBindTexture(GL_TEXTURE_2D, 0);
  33.     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  34.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement