Can texture map only 1 object and nothing else

I adopted nehe’s example in tut #24 for texture mapping .TGA files. I can get it to texture map using the Floor.TGA file but File.TGA does not work. I tried using the File.TGA in textures[0].textID and the base won’t texture map. I’m suspecting something is wrong with my File.TGA but I’m not completely sure. Is there something wrong with my code, am I leaving something out or have lines of code in the wrong place?
here is my code http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=1573

Do you have a file called “File.TGA”?
Is it in the same directory?
Did you create both files?

Are thay saved as compressed or uncompressed TGA files?

Check my website and the GLblackjack source for the TGA loader I use. http://www.angelfire.com/linux/nexusone/

Originally posted by ltrain_riders:
I adopted nehe’s example in tut #24 for texture mapping .TGA files. I can get it to texture map using the Floor.TGA file but File.TGA does not work. I tried using the File.TGA in textures[0].textID and the base won’t texture map. I’m suspecting something is wrong with my File.TGA but I’m not completely sure. Is there something wrong with my code, am I leaving something out or have lines of code in the wrong place?
here is my code http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=1573

// Build A Texture From The Data
glGenTextures(2, &texture[0].texID); // Generate OpenGL texture IDs
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered

if (texture[0].bpp==24)            // Was The TGA 24 Bits
{
    type=GL_RGB;                // If So Set The 'type' To GL_RGB
}
glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);

In that section of code,use texture instead of texture[0]
You are creating the first texture twice.

Hope this helps. Claude

Both files will texture map. My code in the void init( ) function:
if( (LoadTGA(&textures[0],“wood.TGA”)) | | (LoadTGA(&textures[1],“Floor.TGA”) ))
whatever file gets loaded into &textures[0] will work and texture maps correctly. The files that try to get texture mapped into &textures[1] just turns all my objects gray. Somebody said in my LoadTGA file I should change texture[0] to texture. I tried that and I got a bunch of compile errors. &textures[0] and &textures[1] should be passed to texture[0] (notice no ‘s’) one at a time and will be generated, when &textures[1] is called, it too will overwrite texture[0] and generate and bind to textures[1]. I took this code straight from NeHe’s tutorial #24. I’ve changed the right variables so it could handle 2 textures instead of 1, but something isn’t right. Here is my code: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=1611

Does the texture have dimensions that are a power of 2? (e.g. 64x64, 128x64, 256x256)

are you remembering to bind each texture before it’s respective geometry?

jebus

Should have read:
In that section of code,use texture-> instead of texture[0].

texture is a pointer and you need -> to access structure members in that case.

Hope this helps. Claude

I found out where the problem was.
void init ( void )
{
if( (LoadTGA(&textures[0],“wood.TGA”)) && (LoadTGA(&textures[1],“Floor.TGA”) )) // Load The Font Texture
{ }

…should have been && instead of | |. When the call to the first LoadTGA came true it didn’t need to test for the second LoadTGA, therefor textrues[1] wasn’t being created. However another problem arose. When I press ‘f’ or ‘w’ to resize my window I lose my textures. Here’s updated code: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=1637

Hi, the problem is that when you press “w” to reshape the window glut sends the new dimensions through a reshape callback. Your “reshape” function does not define a clipping volumn. I think this is your problem, others plz correct if wrong. I think you just have to do something simple like this:

void Resize( int width, int height )
{
GLfloat fAspect;

if( height == 0 ) height = 1;

glViewport(0,0,width,height);

fAspect = (GLfloat)width/(GLfloat)height;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f,fAspect,0.1f,400.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

because if you dont define a clipping volume whatever you are rendering can become distorted.

Edit: Ah, nevermind I guess you should recall your camera function in your reshape function. Sorry, didnt see that the first time around. You should call gluLookAt after glMatrixMode(GL_MODELVIEW);
Old GLman

[This message has been edited by Old GLman (edited 11-04-2002).]

You can’t call a function inside a function… I can’t call camerMode( ) inside reshape(…). I tried moving gluLookAt( ) after glMatrixMode(GL_MODELVIEW); but that does not work, it only distorts my view.

You should not put camerMode inside of main()
It needs to be called every time you re-draw the scene.

change it to something like this:

display(void)
{
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

camerMode(); // This is where most people call it. if it does not look correct after calling it here, then you are not setting up you view correctly.
//draw stuff

}

reshape function is only for when the windows is resized. You do not call it yourself.

Originally posted by ltrain_riders:
You can’t call a function inside a function… I can’t call camerMode( ) inside reshape(…). I tried moving gluLookAt( ) after glMatrixMode(GL_MODELVIEW); but that does not work, it only distorts my view.

[This message has been edited by nexusone (edited 11-04-2002).]

thanks but what does this error mean? implicit declaration of function `int camerMode(…)’ http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=1645

I forgot to the camerMode( ) prototype. This still did not fix my problem though. =*( When I resize or go to full screen all my objects turn gray. Do I have to recall my init() function maybe? …

Here is a basic glut structure setup. You should try this setup to get things working correctly.

void RenderScene( )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

    // draw what you want

glutSwapBuffers();
}

void OpenGLSetup( )
{
glClearColor(0.0f,0.0f,0.0f,1.0f);

glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);

    // set up anything else you may need
    // to set up. OpenGL states, variables, etc...

}

void Resize( int width, int height )
{
GLfloat fAspect;

if( height == 0 ) height = 1;

glViewport(0,0,width,height);

fAspect = (GLfloat)width/(GLfloat)height;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f,fAspect,0.1f,400.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main( )
{
// setup your window
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(0,0);
glutInitWindowSize(512,512);
glutCreateWindow(“glutapp”);

    // register any callbacks your using

glutReshapeFunc(Resize);
glutDisplayFunc(RenderScene);
glutTimerFunc(2,Timer,1);

    // setup your scene

OpenGLSetup();

    // go go go

glutMainLoop();

return( 0 );
}

Its helpful to read the glut documentation on this site to find out more about how glut works.

Old GLman