PDA

View Full Version : Switched to glortho, now textures are TINY!? Help!



12-31-2001, 10:43 PM
I switch from perspective to ortho, since I am making 2d game. Problem, now all my textures are VERY small, and I can't understand why.

my setup code is:



glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glOrtho(0, width,height,0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,width,height);

and my textures are size 128x64, and 32x64, and when display on screen now, they look like few pixels. I can do scale(50,50,50); then I see then again, but I do not understand why I need to do this?

when I use perspective then the textures are correct!

I am confused why I need to scale, or do
glvertex2f(50.0,50.0) from glvertex2f(1.0,1.0)!!

Oh yes, also I notice I do glscale(-50,50,50) since now textures are flipped?

I look at many books, and they no say why!

Help!
Many thanks friends!

--Clancy

thebamaman
01-02-2002, 10:12 AM
All of your problems are happening because of your glOrtho call:

glOrtho(0, width, height, 0, -1, 1);

The order of your arguments should be:

glOrtho(left, right, bottom, top, near, far);

You have your height and 0 switched, which is why you have to scale in the negative direction. And if you want to use the window width and height as your dimensions (ex. 400 x 400 pixels) then your coordinates should be relative to this. If you want 1.0 to be the rightmost coordinate, declare glOrtho this way:

glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

If you use a quad with dimensions here:

glBegin(GL_QUADS);
glVertex2f(0.0, 0.0);
glVertex2f(1.0, 0.0);
glVertex2f(1.0, 1.0);
glVertex2f(0.0, 1.0);
glEnd();

and the above glOrtho call, your quad will fill the screen. Hope I helped.

01-02-2002, 10:35 AM
I make the glOrtho call like this so I can have screen coordinates.
As I understand, I have it set up so upper left is (0,0) and bottom right = 640,480), top right = (640,0) and bottom left = (0,480)Is this not the case?


I see what you mean about height & 0 switched, that was needed to make screen pixel coordinates. So I guess I have to flip the textures to make correct.


Thanks for tip!

thebamaman
01-02-2002, 10:50 AM
Ok, so you want to do screen coordinates like windows with the origin in the upper left corner huh? Well then, your glOrtho call is correct. Since you mentioned textures, here is an example, similar to the full screen quad with my earlier post.

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2i(0, 0);
glTexCoord2f(0.0, 1.0); glVertex2i(0, height);
glTexCoord2f(1.0, 1.0); glVertex2i(width, height);
glTexCoord2f(1.0, 0.0); glVertex2i(width, 0);
glEnd();

I believe this will create the same full window quad with the texture upside down. For one, texture coordinates are much easier to work with using the floating point version of the call, and two, texture coordinates are relative to the actual texture, therefore this is upside down. So to flip it, you need to rearrange the glTexCoord calls. I think you can figure this out. Again, hope I helped.

Bob
01-02-2002, 12:39 PM
For exact screen corodinates, that ortho call is not correct, but almost. The upper left corner of the window is NOT the same as the center of the upper left pixel, but the corner of that pixel. If you want to hit the pixel right in the center, you have to offset the coordinate by one half.

And if your window is 640x480 pixels big, then the lower right pixel's coordinate is (639, 479), not (640, 480).

For proper coordinate-pixel match, this is what I think you have to do.



glOrtho(-0.5, width-0.5, height-0.5, -0.5, -1, 1);

That way you will hit the pixel in the center, not in the corner.

01-02-2002, 07:20 PM
I was thinking of either doing the texutre fix with either the glscalef(-1,1,1) (to mirror it, and that does work, or as you say I could also do it with the texcoord flipped. Does it make a difference? I assume the gltexcoord2f is better since it results in less calls?

Bob, that is very intresting, I will make the fix of the .05 now! Thanks!

Thanks again friends!

Oh yes, I was reading that I should actually use scale to fix, since then I can correct the texture size versus screen size, so if all my textures would be scaled to look good in bigger screen size. (so 512/640=.8, so I should use glscalef(-.8,.8,.8) to get the textures to look correct in that screen size?
I hope this makes sense!

01-03-2002, 11:09 AM
I make mistake, I mean 640/512 = 1.25 aspect ratio.

Sorry.

Bob
01-05-2002, 03:59 AM
Whether you multiply the coordinate by -1 directly, or scale is by -1, doesn't make much difference. The result should be the same.