Sign in to follow this  

NeHe's OpenGL tutorial -- Need texture mapping help

This topic is 3712 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 recently started working through a tutorial here: http://nehe.gamedev.net/lesson.asp?index=02 Ive run into a few snags, but everything has worked out fine until now... I'm doing lesson covering texture mapping. Now, for some reason when I compile the code I don't get any errors, but when the window comes up all I get is a black, blank window. No object. This is interesting, because from what I'm led to believe if the texture was applied incorrectly I would see a completely white object, correct? I know it has nothing to do with the path to the image, because when I put in a fake image path I get an error message, which I'm not getting here. Heres a link to my source: http://rapidshare.com/files/61930347/OPENGL_TEXTURE_MAPPING.cpp.html I'm very new to this, and would appreciate any help I can get. Im sure I made some stupid, easy to spot mistake. =P Thanks, -8bit

Share this post


Link to post
Share on other sites

int DrawGLScene(GLvoid){ // Start Drawing
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-15.0f); // Move Into The Screen 5 Units
return TRUE; //<<PROBLEM HERE>> // Everything Went OK

/..other code here



I'm not sure if you missed this or if you don't realise whats happened, but you're hitting this 'return true' line near the start of your rendering. return true makes the function end, so anything code after it won't be ran.

taking that out seems to fix the problem.

Share this post


Link to post
Share on other sites
thanks for the help.

I removed that line, but now when I compile the code compiles fine, but when it tries to bring up the window it says:

"ERROR

Initialization failed."

Do you have any idea whats wrong now?

My guess is that it has something to do with the section before this one in my code which loads the texture, but I'm not sure where to go from there... It might have something to do with my texture though.

I'm using a 16x16 pxl 24-bit BMP for my texture. Would that create a problem?

also, Do you know what directory its looking in for the texture, because that might be the problem too. I have it in the root directory for my compiler. (DevC++)


Edit: Ok, I removed the line that gives that error message, and now I'm getting a floating white cube, so Im pretty sure it has something to do with the texture. Any ideas?

On an unrelated note, watching this white cube slowly rotate suspended in nothingness is surprisingly hypnotizing...

Share this post


Link to post
Share on other sites
can you host the image somewhere? so i can see if it's that texture

or try using the default nehe texture. if that works then we know the texture is the problem.

I tried renaming my texture and I also get the same problems, so the problem is almost definatley that it can't find the texture.

If you wanted you could expand the error messages to give more details...for example..



if (TextureImage[0]=LoadBMP("NeHe.bmp"))
{
Status=TRUE;/ Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create The Texture
glBindTexture(GL_TEXTURE_2D, texture[0]); // Typical Texture Generation Using Data From The Bitmap
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Generate Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
}

else
{
MessageBox(NULL, "Failed to load texture", NULL, NULL);
}




could even take it a step further by writing the texture name to the message box too.


Quote:

also, Do you know what directory its looking in for the texture, because that might be the problem too. I have it in the root directory for my compiler. (DevC++)


er, root directory of the project or root directory of the compiler? i.e.
C:\ Program files \ microsoft visual studio \
or
C:\Documents and settings\Clifford T. Forumposter\My Documents\Visual Studio Stuff\ NeHeTextures

cause the first one is a bad idea, second one not so much. The app takes file paths reletive to the directory of the project (not the sollution file). So wherever you have your 'nehetextures.vcproj' file is where you should shove your texture.

i've recreated your errors and yes, it looks like the app can't find/load the texture, and as a result just gives you a white box (loading the texture would've failed, so binding that texture would just bind NULL, which will give you that white box).

Share this post


Link to post
Share on other sites


glEnable(GL_TEXTURE_2D );

Are you enabling texturing before trying to bind the texture to your object?

I am pretty rusty at opengl but I know that not enabling this will lead to the symptoms you are suggesting.

Hope that helps!

Share this post


Link to post
Share on other sites
Yeah, I tried using NeHe's image as my texture and it still isn't working. Ive placed the image in the directory with the project, cpp file, the root directory for my compiler, the root for my OS, my desktop, and my documents. (as unlikely as the last two were I was desperate)

I tried changing the name of the image in my source from NeHe.bmp to NeHe.BMP, NeHe, and NeHe.bitmap.

I'm not sure whats wrong, but I'm wondering if theres a way to alter my code so it will start looking for the image in the root directory for my OS? maybe it'll see it if I navigate to it from there.

thanks.

Share this post


Link to post
Share on other sites
I ran your program, and it worked fine. Spinning cube textured. (*After removing the early return in the DrawGLScene function)

I did change the file name of the texture (to "test.bmp") - and the program will look in your project directory. I.e.:

C:\My Documents\Visual Studio 2005\Projects\<YourProjectName>\test.bmp

This line was failing as you probably know - returning false, failing the initialization:

if (TextureImage[0]=LoadBMP("v2triforce.bmp")) //false - cannot find "v2trifoce.bmp" in your project directory.
//If you're still completely unsure, you can be explicit:
if (TextureImage[0]=LoadBMP("C:\\v2triforce.bmp"))
//and put it in your hard drive root





One thing:

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL




What the f**k is THAT!? If that's NeHe's example code someone should be held accountable for this travesty.

Share this post


Link to post
Share on other sites
Ah, I figured out what my problem was. Way back when I first posted this thread I removed the lines:

if (!InitGL()){
KillGLWindow();
MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}


So when I rendered the cube it apparently skipped the texturing step or something.

Quote:
What the f**k is THAT!? If that's NeHe's example code someone should be held accountable for this travesty.


It looks like its creating an array to hold the texture? Yes, it was in the tutorial. I'm new at this, is there something wrong with that? Is there a better way to do this?

Share this post


Link to post
Share on other sites
Sorry for overreacting :)


AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL






It's allocating an array of 1 pointer.
Then setting an area of memory to zero, the size of which is undefined.
It'll work, most certainly, your compiler will most likely assume the void* is a 32bit pointer, but it's horrible, risky, undefined and I'm sure you'll agree is just plain unnecessarily complicated and difficult to read.

It should just be simply:


AUX_RGBImageRec *textureImage = NULL;


//or if you absolutely must insist:
const int numTextures = 20;

AUX_RGBImageRec *textureImages[numTextures];
memset(textureImages, 0, sizeof(AUX_RGBImageRec*) * numTextures);

Share this post


Link to post
Share on other sites

This topic is 3712 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this