Jump to content
  • Advertisement
Sign in to follow this  
CodeBox

textures??

This topic is 4857 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

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(); 
}

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!