Advertisement
Guest User

sad

a guest
Nov 30th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. void load3DTexFromPVM(const char* fileName,
  2. int xSize=64,
  3. int ySize=64,
  4. int zSize=64) {
  5. const int size = xSize*ySize*zSize;
  6. FILE *pFile = fopen(fileName,"rb");
  7. if(NULL == pFile) {
  8. cerr << "Fail to open texture file" << endl;
  9. exit(EXIT_FAILURE);
  10. }
  11. GLubyte* texels=new GLubyte[size];
  12. fread(texels,sizeof(GLubyte),size,pFile);
  13. fclose(pFile);
  14.  
  15. //load data into a 3D texture
  16. glGenTextures(1, &texname);
  17. glBindTexture(GL_TEXTURE_3D, texname);
  18.  
  19. // set the texture parameters
  20. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  21. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  22. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
  23. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  24. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  25. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  26.  
  27. glTexImage3D(GL_TEXTURE_3D,0,GL_INTENSITY,xSize,ySize,zSize,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,texels);
  28. //glTexImage3D(GL_TEXTURE_3D,0,GL_RGB8,xSize,ySize,zSize,0,GL_RGB,GL_UNSIGNED_BYTE,texels);
  29. delete[] texels;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement