3D texture Opengl

Started by
7 comments, last by DaxGraphics 14 years, 3 months ago
Hi, I have a problem. Can anyone help me to use a 3d texturing on Opengl? My difficult is the loading of the image (bitmap) as texture. In the 2D case I don't have problems because I use auxDIBImageLoad. Is the same for 3D loading? This is my code:

  tex[0] = auxDIBImageLoad("Immagine1.bmp");
  if (!tex[0]) return 0;
  glGenTextures(1, &texture[0]);
  glBindTexture(GL_TEXTURE_3D, texture[0]); 
  glTexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
  glTexImage3D(GL_TEXTURE_3D, 0, 3, 65, 65,65, 0, GL_RGB,GL_UNSIGNED_BYTE, tex[0]->data);     
I hope someone could help me! Thanks, Dax
Advertisement
bmp files are for 2d images.
If you want some 3D textures, usually they are in the Microsoft DDS format and there might be some free ones in the nvidia SDK and also the AMD SDK

developer.nvidia.com
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Firstly, do you know what you use 3D textures for? and what is your usecase, is it possible what you actually want is a cubemap?

You can create a 3D texture with BMPs but you have to provide several slices to the OpenGL driver, it can then filter between these slices, the more slices you have the better fidelity your 3D texture will be.

a simple example:
GLuint tex;const int WIDTH=128;const int HEIGHT=128;const int CHANNELS=3;//RGB8const int NUM_SLICES=4;unsigned char* buffer = new unsigned char[WIDTH*HEIGHT*CHANNELS*NUM_SLICES];loadAllSlices(buffer, NUM_SLICES);glGenTextures(1, &tex);glBindTexture(GL_TEXTURE_3D, tex);glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB8, WIDTH, HEIGHT, NUM_SLICES, 0, GL_RGB,              GL_UNSIGNED_BYTE, buffer);delete[] buffer;


Where loadAllSlices simply copies all the BMPs image data into buffer to appear consecutively in memory.

"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Quote:Original post by silvermace
Firstly, do you know what you use 3D textures for? and what is your usecase, is it possible what you actually want is a cubemap?

You can create a 3D texture with BMPs but you have to provide several slices to the OpenGL driver, it can then filter between these slices, the more slices you have the better fidelity your 3D texture will be.

a simple example:
*** Source Snippet Removed ***

Where loadAllSlices simply copies all the BMPs image data into buffer to appear consecutively in memory.


Fantastic!!! Is the solution of my problem.
My bitmap is image of a sphere. I would i cube whit this image and the 3d texture is composed whit 64 similar image.

Your code is perfect for my problem because i can see how create a buffer whit my image. But where I specified the file name?

unsigned char* buffer = new unsigned char[WIDTH*HEIGHT*CHANNELS*NUM_SLICES];loadAllSlices(buffer, NUM_SLICES);


This is the creation of the buffer but where is the filename of my 64 textures?

Thaks!!!
Thats up to you to figure out [smile], all you have to do is write the loadAllSlices method, in this function you can know about the files which you need to load.
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Ops.. sure! :P

How I put my bitmap on this buffer? I think put directly the byte that compose it. I wrong?
yes, basically its like packing 64 images into one array and sending that to the OpenGL driver.

say I have 2 images A and B, each has 4 bytes total. then the buffer would be 8 bytes in size and look like this in memory: AAAABBBB
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Ok, I understand.

Thanks, Tomorrow I do this implementation, then testing my code.

Bye
Hi, I have another problem :(

This is my implementation of loadAllSlice. It compile correctly but it doesn't work texture mapping.

  FILE *pfile;  FILE *pfileW;  AUX_RGBImageRec *TextureImage[64];  char nomefile[20];  char c;  int k = 0;  int i;  int j = 0;    pfile = fopen("Common\\elenco.ini","r");  if(!pfile) exit(0);  pfileW = fopen("Common\\bitmap.bmp","w");  while(fgets(nomefile,20,pfile)!= NULL){    nomefile[strlen(nomefile)-1] = '\x0';    TextureImage[k] = auxDIBImageLoad(nomefile);     //Caricamento nel buffer    i = 0;    while(i < HEIGHT*WIDTH*CHANNELS){      buffer[j] = TextureImage[k]->data;        i++;      j++;    }    k++;  }


Elenco.it is a file whit inside all name of my bitmap.

Bye

This topic is closed to new replies.

Advertisement