Jump to content
  • Advertisement
Sign in to follow this  
CodeBox

textures?

This topic is 4861 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 can any one tell me what I am doing wrong?
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
There could be a few things wrong, especially with the amount of code you posted.

The first questions that come to mind are:

Are your texture dimensions powers of two (64x64, 128x128, 256x256, etc.)?

Are you enabling texturing before you load your textures? If not, try throwing a call to glEnable(GL_TEXTURE_2D) at the top of your LoadTexture() function.

Does anything show up? Are you seeing a white quad or nothing at all? If you don't see anything, make sure your winL, winR, winB, and winT variables are initialized correctly, and make sure that glFrontFace is set to GL_CCW.

This thread would probably get a better response in the OpenGL forum, by the way.

Good luck.

Share this post


Link to post
Share on other sites
CodeBox, one thing you may wish to do is add in some error checking after each gl_____() call by using the glGetError() function. Any OpenGL reference guide will have information on when it can/should be called. In your case, it would help you pinpoint the precise location of the error.

Share this post


Link to post
Share on other sites
I just see a white quad and my dimaentions are of the powers you said and in the same folder too!

I tried doing what you said but am not really sure where you are meant to put the code although I tried several places with the code you said glfrontface and nothing happened, I also tried to call to glEnable(GL_TEXTURE_2D) at the top of the LoadTexture() function, but again just white quad?

any ideas?

Share this post


Link to post
Share on other sites
When you are specifying the coordinates for your geometry are you specifying texture coordinates too?


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, redBuildingId);
glBegin(GL_QUADS);
glTexCoord2f(.., ..); glVertex2f(..,..);
glTexCoord2f(.., ..); glVertex2f(..,..);
glTexCoord2f(.., ..); glVertex2f(..,..);
glTexCoord2f(.., ..); glVertex2f(..,..);
glEnd();

glBindTexture(GL_TEXTURE_2D, waterId);
glBegin(GL_QUADS);
glTexCoord2f(.., ..); glVertex2f(..,..);
glTexCoord2f(.., ..); glVertex2f(..,..);
glTexCoord2f(.., ..); glVertex2f(..,..);
glTexCoord2f(.., ..); glVertex2f(..,..);
glEnd();

glDisable(GL_TEXTURE_2D);



Cheers,
dhm

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!