Texture Mapping Problem - Altering Lesson 6

Started by
6 comments, last by zippo 23 years, 11 months ago
I took the code from Lesson 6 of the OpenGL tutorials found on NeHe and made a few alterations to a particular function so that I could load multiple textures (6) and then use them as sides to the cube created later on in the program. Basically, I took the LoadGLTextures function and changed it to run through a for loop and load each of the bitmaps. I made sure to change the TextureImage array to the number of bitmaps I would be loading. I then ran the function through a for loop and had it go through a switch statement to change the filename. Below is my code: int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[6]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL char FileName[] = "images/side1.bmp"; // Load The Bitmap, Check For Errors, If Bitmap''s Not Found Quit for(int i = 0;i<6;i++) { TextureImage=LoadBMP(FileName); Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); if (TextureImage) // If Texture Exists { if (TextureImage->data) // If Texture Image Exists { free(TextureImage->data); // Free The Texture Image Memory } free(TextureImage); // Free The Image Structure } switch (i) { case 0: strcpy(FileName,"images/side2.bmp"); break; case 1: strcpy(FileName,"images/side3.bmp"); break; case 2: strcpy(FileName,"images/side4.bmp"); break; case 3: strcpy(FileName,"images/side5.bmp"); break; case 4: strcpy(FileName,"images/side6.bmp"); break; default: strcpy(FileName,"images/side6.bmp"); break; } } return Status; // Return The Status } That''s the function in its entirety. I compile it, and recieve no problems whatsoever. When I link it, however (using VC6), I recieve the following errors: error LNK2001: unresolved external symbol _main fatal error LNK1120: 1 unresolved externals After getting these errors when I try to link it, I now find a new folder in the "File View" of my program called "External Dependencies", with the header file "basetsd.h" in it. I''m awfully bewildered here. I''m really not sure what my problem is when I try to link it. Any advice or replies are more than welcome. Thanks! Z¡PPÕ </i>
Advertisement
did you use the project-file (*.dsw) from lesson6?

you have to make sure that you choose "win32 application" in VC when you create your project. if you''re using glut, you should choose "win32 console application"
I just created a new project, being sure to make it "win32 console application", then added the source file, and still recieve the same error when linking. im stumped.

Z¡PPÕ
Just noticed in the documentation on NeHe, and have changed it to a "win32 application". it gets by the linking now, no problem. but now i have to deal with an illegal operation error when the window tries to load up. =P

Z¡PPÕ
Okay, ran it through the debugger. Seems to have a problem on the following line of code, excerted from my first post:

glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);<br><br>You''ll notice on the first post, I had left out int i for the last 3 of the calls to TextureImage. I corrected this, but am still recieving an "Access Violation" error by the debugger for this line of code. Any thoughts? I''ll be working on it. Thanks!<br><br>Z¡PPÕ </i>
I may be wrong but I don''t think you can do it this way.
The access violation comes from the fact that you have just written one texture to memory and then you try and overwrite that same texture.
you can only call glGenTextures once
and you need to make space for all six textures not just for one that you overwirte each time.
why not try assigning a different value for each texture and then in the draw routine bind the texture to the correct plane
so we get
GLuint texture[6]; (space for all 6 textures)
load each of the six textures to a different number
after making an array for them
AUX_RGBImageRec textures[6]; //not sure if you can do this (I just had a different Aux_RGBIMAGEREC for each texture)
the do glGenTextures(6,texture)
then do the build texture part with different numbers for each texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, textures[1]->sizeX, textures[1]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, textures[1]->data);

hope this helps...
Check out my shadows page and send me some feedback
I think it''s the memset function.

first you declare TextureImage as a array of pointers...
Thereby TextureImage becomes a pointer to the area where those six pointers are, but then you set (via memset ) TextureImage to NULL....Then upon access of TextureImage[ number ] you actually access memory at address 0....

PS. glGenTextures can be called as many times as you want ( it works for me )

Ries
You''re right on the money with memset. I contacted Jeff Molofee, and he worked on the code for me. I can now see where I''ve made my mistakes. Memset now clears space for all 6 textures.
I run the LoadBMP function for each image seperately, and use them in an if statement for error checking, then run GenTextures with the parameters (6, &texture[0]). I''m a little lost why it''s &texture[0] and not &texture, but it''s no big deal, probably just an oversight by me. Then I run through a for loop and bind the textures, set the height, width and data, and all is well! Thanks immensely to Jeff Molofee for his help, and to everyone that''s replied to this post!

One step further,

zippo

This topic is closed to new replies.

Advertisement