Skip to main content
gamedev.net
🔒 Locked

textures?

Started by CodeBox Nov 30, 2005 at 8:09 AM 4 replies 800+ views
Original Post
CodeBox
CodeBox
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(); 
}


extralongpants
extralongpants
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.
MatrixCubed
MatrixCubed
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.
CodeBox
CodeBox
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?
dhm
dhm
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
mrbastard
mrbastard
add code to check the file exists and that you are actually loading it.
[size="1"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.