textures??

Started by
5 comments, last by CodeBox 18 years, 4 months ago
Ok I have the code below and it does not seem to be working! I don't know why it compiles but the images don't show on screen and I just see a white quad, can any one tell me what I am doing wrong? My texture dimensions are (64x64, 128x128), so thats not a problem!

GLuint LoadTexture(char *filename) { 
	GLuint texID; 

	AUX_RGBImageRec *image = auxDIBImageLoad(filename); 

	glGenTextures(1, &texID); 
	glBindTexture(GL_TEXTURE_2D, texID); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image->data); 

	return texID; 
} 

GLuint waterId=LoadTexture("water.bmp");
GLuint redBuildingId=LoadTexture("orangebuild.bmp");
GLuint blueBuildingId=LoadTexture("water.bmp");
GLuint orangeBuildingId=LoadTexture("water.bmp");

static void background(){
	glEnable(GL_TEXTURE_2D); 
	glBindTexture(GL_TEXTURE_2D,  waterId);
	glBegin(GL_QUADS); 
	glColor3f(1,1,1); 
	glTexCoord2f(10.0f, 10.0f); glVertex2d(winL,winT);
	glTexCoord2f(10.0f, 0.0f); glVertex2d(winL,winB);
	glTexCoord2f(0.0f, 0.0f); glVertex2d(winR,winB);
	glTexCoord2f(0.0f, 10.0f); glVertex2d(winR,winT);
	glEnd(); 
}

Advertisement
Well, I'm not 100% sure this is the problem, but texture coordinates tend to go from 0.0f to 1.0f, and you have them from 0.0f to 10.0f. This might be an issue if you are clipping the texture coordinates - I don't know.
my siteGenius is 1% inspiration and 99% perspiration
Because you are making the age old mistake that cost many of us a lot of time. NEVER load your textures to initialize globals. Without a context for GL (ie. before initializing OpenGL) all your calls to create the textures are doing pretty much nothing.
f@dzhttp://festini.device-zero.de
this just gives it a tile affect

but even so I have other textures with 1.0 that would work if that was the problem!

it works when I put glBindTexture(GL_TEXTURE_2D, LoadTexture("water.bmp"));

instead of the variable but then it then is not a pointer to it and there for it gets drawed several times and the memory fails!
Erm.. could you expand on that Trienco I not getting what you mean?

am I not placing code in correct place or setting variables up right?

can you expand on what igzacly am doing wrong?
Oh, right, didn't see that. Basically, when you initialize global variables, this happens before anything else in the program. Thus, you are trying to give your textures GL texture IDs before you've initialized OpenGL. This just results in them not really being assigned texture IDs. What you should do instead is to set up opengl, and then load the textures, instead of initializing global texture variables at the beginning of the program.
my siteGenius is 1% inspiration and 99% perspiration
I get ya it's working fine now!

I added void imageInit(void)

put all the variables in there.
E.g orangeBuildingId=LoadTexture("water.bmp");

then called it in the same place as the init and it works fine now!

This topic is closed to new replies.

Advertisement