Jump to content
  • Advertisement
Sign in to follow this  
DaxGraphics

OpenGL 3D texture Opengl

This topic is 3248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;//RGB8
const 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.

Share this post


Link to post
Share on other sites
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!!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!