Sign in to follow this  
starfleetrp

Texture Trouble

Recommended Posts

Hi, I am experiencing a few problems and am not sure how I should fix them 1) Once I load a texture, my whole ortho scene seems to get very dull. Before it was very bright, and I would like it to stay that way. I am using no lighting. This happens wether or no I draw it. I am loading it like this:
AUX_RGBImageRec *LoadBMP(char *Filename)				// Loads A Bitmap Image
{
	FILE *File=NULL;									// File Handle

	if (!Filename)										// Make Sure A Filename Was Given
	{
		return NULL;									// If Not Return NULL
	}

	File=fopen(Filename,"r");							// Check To See If The File Exists

	if (File)											// Does The File Exist?
	{
		fclose(File);									// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}

	return NULL;										// If Load Failed Return NULL
}

int LoadGLTextures()									// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;									// Status Indicator

	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture

	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP("NeHe.bmp"))
	{
		Status=TRUE;									// Set The Status To TRUE

		glGenTextures(1, &texture[0]);					// Create The Texture

		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}

	if (TextureImage[0])									// If Texture Exists
	{
		if (TextureImage[0]->data)							// If Texture Image Exists
		{
			free(TextureImage[0]->data);					// Free The Texture Image Memory
		}

		free(TextureImage[0]);								// Free The Image Structure
	}

	return Status;										// Return The Status
}




2) It seems like when I change an alpha channel in a section of code after I draw the image (since its all under Render()) that my image fades out and eventually goes black. I have located the code that is causing this. It slowly fades down to an alpha value of 10%. I am not sure how to fix this problem either.
for(...)
{
...
glLoadIdentity();
glTranslatef(Particles.at(i).xPos + xOffset, Particles.at(i).yPos + yOffset,-10.0f);
glColor4ub(200,200,255,(GLubyte)Opaquity);
auxSolidSphere(Size);
}




This is done in a for loop to draw all of the points with their own size and alpha channel since they all change size and alhpa values over time. I have been trying to figure this out and can't seem to loacte the problem. I hope I have provided enough information, if not i'd be happy to post what you need! [Edited by - starfleetrp on April 24, 2006 7:33:38 PM]

Share this post


Link to post
Share on other sites
I have located the dulling to be taking effect when the image loads because of these two lines:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

However without them the image just does not appear, and with them everything is dull/very dark. I am not sure how to fix this.

Also if I ignore the line that says change the alpha value, the image does not change, but I need to change the alpha value of one texture/glGolor4ub(...). So I still am having trouble with this but I located the problem areas, atleast I think I have.

Share this post


Link to post
Share on other sites
Quote:
Original post by starfleetrp
I have located the dulling to be taking effect when the image loads because of these two lines:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

However without them the image just does not appear, and with them everything is dull/very dark. I am not sure how to fix this.

Also if I ignore the line that says change the alpha value, the image does not change, but I need to change the alpha value of one texture/glGolor4ub(...). So I still am having trouble with this but I located the problem areas, atleast I think I have.

It doesn't work without those lines becuase hte default min filter involves mipmaps. Unless you generate them or provide all the lod's yourself they're obviously not there and texturing doesn't work.

About things appearing dark, a screenshot would help - how is the textured quad / geometry placed in the scene?

Share this post


Link to post
Share on other sites
Well here are the screenshots (and yes I wont be using vibrant colors like I have, it was just for testing until I can get an image loaded)

Without the image loaded:
http://img186.imageshack.us/my.php?image=before5wb.jpg

With the image loaded:
http://img205.imageshack.us/my.php?image=after8jk.jpg

After moving for a while the image fades (and flickers, this is the brightest flicker). I think its caused from the glColor4ub():
http://img205.imageshack.us/my.php?image=aftermovingforawhile2hf.jpg


I showed how the trail was drawn in one of my post above, and the map tiles were drawn as: simple as of yet.

void cMap::RenderMap(void)
{
glLoadIdentity();
// Move back 3 units.
glTranslatef(100.0f, 100.0f, -999.0f);
for(int Cols = 0; Cols <= MapWidth; Cols++)
{
for(int Rows = 0; Rows <= MapHeight; Rows++)
{
glLoadIdentity();
TileHeight = 100;
TileWidth = 100;

glColor3ub(100,100,100);

// Bind that texture to the texture variable.
//glBindTexture(GL_TEXTURE_2D, Texture.ID);

glBegin(GL_QUADS);
glColor3ub(255, 0, 0);
//glTexCoord2f(0.0, 0.0);
glVertex3f(TileWidth + xOffset + (Cols * TileWidth), TileHeight + yOffset + (Rows * TileHeight),-999.0f);
glColor3ub(255, 255, 0);
//glTexCoord2f(1.0, 0.0);
glVertex3f(TileWidth + xOffset + (Cols * TileWidth), yOffset + (Rows * TileHeight),-999.0f);
glColor3ub(0, 255, 255);
//glTexCoord2f(1.0, 1.0);
glVertex3f(xOffset + (Cols * TileWidth), yOffset + (Rows * TileHeight),-999.0f);
glColor3ub(0, 0, 255);
//glTexCoord2f(0.0, 1.0);
glVertex3f(xOffset + (Cols * TileWidth), TileHeight + yOffset + (Rows * TileHeight),-999.0f);
glEnd();

}
}
}



And this is how it is drawn

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the screen.
glEnable2D();// Render a frame.

glLoadIdentity();
glTranslatef(150,150,11);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-50.0f, -50.0f, 10.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 50.0f, -50.0f, 10.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 50.0f, 50.0f, 10.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-50.0f, 50.0f, 10.0f);
glEnd();

Map.RenderMap();
Ship.UpdatePosition();
Ship.DrawShip(Map.xOffset,Map.yOffset); //This calls the trail - were the fading of the image seems to appear

GetFPS();
glDisable2D();
SwapBuffers(g_HDC);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this