Blurry 2D images

I’ve posted this question in another place and didn’t get much of an answer. Here’s my problem:
I’m doing a panel of an aeroplane. I’m creating a texture, applying it to a quad that is half the height of the screen and the full with of the screen. The problem is that the panel is blurry when i run the prog. I was told that using GL_LINEAR when i create the texture is the cause (something about linear interpolation or some such nonsense)so i changed it to GL_NEAREST and now it’s all pixelated. (i just can’t win) Any more ideas??? Is there any way i can get a middle ground. How come an image doesn’t look the same as it does when you draw it in paint or some other app, when you apply it as a texture to a quad or something? I figured it was because it’s getting stretched so I tried making the image the exact size it would appear on the screen .ie. the size of the quad. And it’s coming out lop-sided? I mean, it’s like it’s skewed in some way.
And skewed very badly, i’m not talkin about it being slightly to one side. A bit of one guage is appearing on the other side of the screen. It’s perfectly clear now though, no blurring or the like so at least i’ve got that much. But i have to tilt my head to see it . These are the texure parameters i’m using:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);

I’ve played around with these parameters to no avail.
I can’t figure out whats wrong. Us newbies are so useless…or maybe just me??

Anyway, to summarize - how in the name of satan, do you make an image appear nice and crystal clear on a quad??? A quad that is half the height, the full width and always in front of, the screen.
And yes, the image is clear when editing it in paint.

Please help, my panel looks like crap. And crap thats been stirred around for awhile!!!

What is the size of your texture vs. the size of your screen area?

What is your view setup ortho or perspective?

What do you use to load your texture?

Sound like maybe your texture coords wrong, but would have to see more code.

nehe.gamedev.net has a good tutors on the subject.

What is the size of your texture vs. the size of your screen area?

The texture is 600 * 225 (screen height and width is 600 * 450). I’ve got to constants in my prog, SCREEN_HEIGHT AND SCREEN_WIDTH with these values (450*600 respectively), this may sound stupid but if the screen in reality is 800 * 600 for example, is thats what is causing the blurring??

What is your view setup ortho or perspective?
Perspective then i change to ortho b4 drawing the panel, then back to perspective.

Code which changes to ortho:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho( left, right, bottom, top, 0, 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Code which changes back to perspective:
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );

What do you use to load your texture?
auxDIBImageLoad function from GLAUX library

Sound like maybe your texture coords wrong, but would have to see more code.
Code for apply texture and drawing quad:

glBegin(GL_QUADS);

	// Display the top left point of the 2D image
	glTexCoord2f(0.0f, 1.0f);	glVertex2f(0, SCREEN_HEIGHT/2);

	// Display the bottom left point of the 2D image
	glTexCoord2f(0.0f, 0.0f);	glVertex2f(0, SCREEN_HEIGHT);

	// Display the bottom right point of the 2D image
	glTexCoord2f(1.0f, 0.0f);	glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);

	// Display the top right point of the 2D image
	glTexCoord2f(1.0f, 1.0f);	glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT/2);

// Stop drawing
glEnd();

I hope there’s enough info there for you to help. Like i said above, it’s probably very obvious but my constants (SCR_HT & SCR_WT) have to be the same as the actual screen area.

Are you sure about the texture loading code ?
Usually “old” drivers doesn’t let you load non squared textures.

Well what constitutes an old driver? The texture is loading fine…i think! What i mean is, the image is there in it’s entirety just looking alittle blurred. It’s not as clear as i want it to be. Is this what you mean by “Usually “old” drivers don’t let you load non squared textures”. I’m guessin there’s no easy solution to this?? I thought mayb i was missing a parameter when telling opengl how to create the texture. Here’s my loading texture code:

AUX_RGBImageRec *pBitmap = NULL;

pBitmap = auxDIBImageLoad("Panel.bmp");

if(pBitmap == NULL)
	exit(0);
    glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);

[This message has been edited by I_NeedHelp (edited 02-26-2003).]

hey look at ur texture dimensions.
ur texture dimensions shud be divisible by 4.
i too encountered this problem.both Height and Width shud be divisible by 4.
eg. 4x4 or 256x256 of 256x24 somehitng like that.
ur code looks good.try this i think this shud work.
sikander

I could not see anything that jumped out at me.

But I notice this part, not wrong but diffrent from how I change from orhto to prespective.

// I am guessing this is the start of the display routine, you have clear depth buffer, etc.

glMatrixMode(GL_PROJECTION);
glPushMatrix(); // Have you already setup perspective before here to save it.
glLoadIdentity(); // Clear Projection Matrix
glOrtho( left, right, bottom, top, 0, 1 );
glMatrixMode(GL_MODELVIEW); // Change model view for drawing
glLoadIdentity(); //Clear Matrix
Code which changes back to perspective:
glMatrixMode( GL_PROJECTION );
glPopMatrix(); // If a valid perspective has been setup before push then restored here.
// I just start my display routine in ortho mode to draw 2D stuff and then switch to perspective.
glMatrixMode( GL_MODELVIEW );

Now I saw playing around enlargeing my window size on a texture object I have, and started to get a pixelated look.

I will play around with some of the texture options and see what I come up with.

Originally posted by sikander:
hey look at ur texture dimensions.
ur texture dimensions shud be divisible by 4.
i too encountered this problem.both Height and Width shud be divisible by 4.
eg. 4x4 or 256x256 of 256x24 somehitng like that.
ur code looks good.try this i think this shud work.
sikander

Actually, they should be a power of 2. (ie 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, etc.)

256x24 would not be a valid texture size because 24 is not a power of 2.

OK, thanks for the help. Yes the perspective is set up before hand. Would it be wrong to assume the texture dimensions are right since i loaded the texture ok and it looks ok (besides a little bit of blurring). Like, i presume it wouldn’t load at all if they were wrong???

I think i may just live with the blurring, it’s not awful bad or anything. But i can’t understand how you can’t apply a texture with perfect results .ie. the quad looking the same as the picture you were looking at in the paint application. If it was being stretched, right fair enough, you’d expect it to lose alot of clarity. But my image shouldn’t be stretched, it’s the same dimensions as the quad i’m sticking it on.

Not to worry, i’ll live with it, thanks for the help folks.

ps nexusone, if you discover anyting, post it (same for all of you ). thanks

u r right.
Thanx for correcting me.

Originally posted by Deiussum:
[b] Actually, they should be a power of 2. (ie 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, etc.)

256x24 would not be a valid texture size because 24 is not a power of 2.

[/b]

change the dimensions and u’ll get the crystal clear results.Use any image editing tool and make it to acceptable dimensions.you’ll see the effect.
sikander

Originally posted by I_NeedHelp:
[b]OK, thanks for the help. Yes the perspective is set up before hand. Would it be wrong to assume the texture dimensions are right since i loaded the texture ok and it looks ok (besides a little bit of blurring). Like, i presume it wouldn’t load at all if they were wrong???

I think i may just live with the blurring, it’s not awful bad or anything. But i can’t understand how you can’t apply a texture with perfect results .ie. the quad looking the same as the picture you were looking at in the paint application. If it was being stretched, right fair enough, you’d expect it to lose alot of clarity. But my image shouldn’t be stretched, it’s the same dimensions as the quad i’m sticking it on.

Not to worry, i’ll live with it, thanks for the help folks.

ps nexusone, if you discover anyting, post it (same for all of you ). thanks[/b]

Holy sht batman, i changed the image to 512256 and it has improved the look of the texture. Thanx
It’s not true what they say about the internet, it isn’t just full of weirdos who know nothing LOL

Thanks again

[This message has been edited by I_NeedHelp (edited 02-27-2003).]

due to comp memory structure ^2 dimensions make sense for speed/alignment stuff. My problem, which I have had for a year and a half, is colour depth. My images are clearer in lower depth than higher! Check what your images look like next to, say a photoshop window of the same image.

You might try histogram equilization of your image if they look better at lower color depth. I think photoshop does it, and if you realy get desprite you can write code to do it yourself its not hard.