Jump to content
  • Advertisement
Sign in to follow this  
ElPeque2

texture mapping and orthogonal projections

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

I have the following problem. I load a texture that is 30 x 30 pixels. The image consists of just its borders in red, and nothing else. (everything else is transparent). then i draw a quad that is also 30x30 with that texture binded. And what i get is ALMOST but not what i was expecting. I get a red square, but the sides up, down and left are 2 pixels thick and those extra pixels are not the correct tone of red. i took a screenshot, and the square is effectively 30 x 30 pixels on-screen. ¿what is happening? thanks for reading.

Share this post


Link to post
Share on other sites
Advertisement
should i reformulate my problem? :S

please help. i still cant figure what the problem is. ill put up a couple screenshots if that helps.

Share this post


Link to post
Share on other sites
I asked this question a while ago, you have to offset your view cube by 0.375, something that has to do with the pixels centers... its on the redbook I believe, I'll see if I can look it up.

anyway, my glOrtho call looks like this:

glOrtho(-0.375f,width,height,-0.375f, 0.0f, 1.0f);

try it.


Edit: Ah! found it check the OpenGL Correctness Tips (11th bullet) on the appendix.

Oh and use GL_NEAREST for GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER (glTexParameteri).

Share this post


Link to post
Share on other sites
almost!

i used

glOrtho(+0.375f, muiWidth, muiHeight, +0.375f, 0.0f, 1.0f);

and now only one of the sides of the square is drawn too thick.

so it got better, now i've been messing around with those values, but couldn't fix it completely.

any suggestions?


And thanks! You've been very helpful already :). I'll be checking my redbook now.

Share this post


Link to post
Share on other sites
Have you tried GL_NEAREST?

here is a code sample:


/* Bind texture, glEnable, etc goes here) */
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glBegin(GL_QUADS);
/* ... */
glEnd();



You don't have to call glTexParameteri right before the call to glBegin, in fact, if all you're doing is drawing tiles this way, you should only call it during your OpenGL initialization code, but you get the idea.

Share this post


Link to post
Share on other sites
yes, i had already set to NEAREST.

it looks better, but still have one double edge.

im done for today, ill take another look to it tomorrow :S

thanks for your help, any further ideas are welcome :)

Share this post


Link to post
Share on other sites
Ah! it was my mistake, you have to adjust the width and height too, so change your:

glOrtho(+0.375f, muiWidth, muiHeight, +0.375f, 0.0f, 1.0f);

to

glOrtho(+0.375f, muiWidth+0.375f, muiHeight+0.375f, +0.375f, 0.0f, 1.0f);

I adjust my width and height before the call which is why I don't do it in the call itself, my complete sequence is:


glGetIntegerv(GL_VIEWPORT, viewport);
width = float((viewport[2]-viewport[0]))-0.375f;
height = float((viewport[3]-viewport[1]))-0.375f;
glOrtho(-0.375f,width,height,-0.375f, 0.0f, 1.0f);

Share this post


Link to post
Share on other sites
i had left this unfixed to be able to advance on other issues and yesterday i finally got back to it.

I was still unable to fix it.

I was trying almost random-heuristic-voodoo fixes and could fix it :S.

Then i thought the problem could be with the texture itself. (I recalled OpenGL expected textures to be square and POT). My texture was actually 30 x 30 ( as i stated in the first post).

I changed it for a POT texture and it began working just perfect :|. Even without any of the fixes on the projection matrix.

Im certainly puzzled.

Share this post


Link to post
Share on other sites
Quote:
Original post by ElPeque2
I changed it for a POT texture and it began working just perfect :|. Even without any of the fixes on the projection matrix.

Im certainly puzzled.
Are you using gluBuild2DMipmaps to create the texture? It internally resizes the image data to the nearest power-of-two dimensions before creating the mipmap chain, so that could certainly have been the source of your problem.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!