Question about resolutions

Member
Posts: 194
Joined: 2009.02
Post: #1
I am working on a 2d isometric engine using opengl(2d textured quads). My engine looks and feels great in and around 800x600 resolution(I'm trying to achieve a particular and very pixelated looks). My desire is to force the user to switch resolutions upon startup, but I have a few concerns. One, am I in any danger of future OS resolution deprecations or anything(perhaps if the day of total resolution independence ever arrive)? Does every machine/monitor have 800x600 capability? Also, might there be a more effective way to achieve this by scaling opengl against the resolution of the machine?
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #2
If I may, I'd like to amend my post. It seems that I have not been using 800x600 but 1280x800. This is a screenshot from my engine running in 1280x800:

/Users/ari/Desktop/before.png

and this is a screenshot of it running in 800x600:

/Users/ari/Desktop/after.png

So in addition to my last question, might anyone have an idea of what's going on here? My quads and textures all have dimensions with power of two.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #3
You need to try uploading/linking your images again. Great idea to illustrate the situation!
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #4
I can't seem to figure out how to upload a picture.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #5
You need to upload the images to a web-site like Photobucket or whatever and link to them.

Since I can't see them, I'll just guess. Check your gluPerspective and/or glOrtho2D/glOrthof, and glViewport calls. Particularly the aspect ratio part of gluPerspective since 800x600 and 1280x800 have different ratios. If you're hard coding for one the other won't look right.
Quote this message in a reply
Moderator
Posts: 682
Joined: 2002.11
Post: #6
If all you want to do is restrict the viewport to no bigger than 800x600, then just use glScalef() to scale everything up to fill the screen. I can give you sample code if you like, since that's what I did for gw0rp.

My web site - Games, music, Python stuff
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #7
Okay here is a screenshot using 1280x800 res:

[Image: before1.jpg]

and here is one in 800x600 res:

[Image: after1.jpg]

The problem seems to be causing my tiles not to line up correctly as you see in the 800x600 photo.


And here is my opengl setup code:

Code:
NSRect viewBounds;

    
    viewBounds = [self bounds];
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_ALPHA_TEST);    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glLoadIdentity();
    gluOrtho2D(0, viewBounds.size.width,
                 0, viewBounds.size.height);

    glMatrixMode(GL_MODELVIEW);


    init_interface();
    
    NSLog(@"prepare");


I might also mention that I use png textures with alpha channels.

And yes Diordna, I would love to see your code.

I should also say that I am a very poor programmer and know little about opengl.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #8
..........anyone?
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #9
Beats me. Looks like maybe a floating point issue with your texture coordinates, or possibly your geometry if you're using one quad per tile. You might try subtracting a smidgen off your texture coordinates to see if they stretch to fit a little better. OR you might try using glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); and glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
It looks exactly like what you'd expect to see from using a texture atlas with linear filtering.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #11
arekkusu Wrote:It looks exactly like what you'd expect to see from using a texture atlas with linear filtering.

Could you elaborate?
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #12
If you put multiple tiles into one texture (that is, dissimilar graphics placed next to each other in one atlas) and draw geometry to the screen, the result will only "look good" if the rasterized pixels sample texels exactly 1:1. If you scale or translate your geometry so that you no longer have a 1:1 mapping, texturing filtering will sample texels from the adjacent tile in the atlas, causing exactly this artifact.

For example, let's say you have one texture which is 8x4 and contains two tiles, one red and one green:
Code:
#define R 0xFF,0x00,0x00
#define G 0x00,0xFF,0x00
GLubyte atlas[32*3] = { R,R,R,R,G,G,G,G,
                        R,R,R,R,G,G,G,G,
                        R,R,R,R,G,G,G,G,
                        R,R,R,R,G,G,G,G };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 8, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, atlas);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

And then you draw a screen aligned 4x4 quad using the red tile:
Code:
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, 0, h, -1, 1);

...

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0, 0.0); glVertex2f(100, 100);
glTexCoord2f(0.5, 0.0); glVertex2f(104, 100);
glTexCoord2f(0.0, 1.0); glVertex2f(100, 104);
glTexCoord2f(0.5, 1.0); glVertex2f(104, 104);
glEnd();

That will look fine. But draw the same quad scaled (or rotated, or translated by a fractional amount):
Code:
glScalef(2, 2, 1);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0, 0.0); glVertex2f(100, 100);
glTexCoord2f(0.5, 0.0); glVertex2f(104, 100);
glTexCoord2f(0.0, 1.0); glVertex2f(100, 104);
glTexCoord2f(0.5, 1.0); glVertex2f(104, 104);
glEnd();
And you'll see that it has green-tinged edges. The linear texture filtering is doing exactly what you told it to do.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #13
arekkusu Wrote:If you put multiple tiles into one texture (that is, dissimilar graphics placed next to each other in one atlas) and draw geometry to the screen, the result will only "look good" if the rasterized pixels sample texels exactly 1:1. If you scale or translate your geometry so that you no longer have a 1:1 mapping, texturing filtering will sample texels from the adjacent tile in the atlas, causing exactly this artifact.

For example, let's say you have one texture which is 8x4 and contains two tiles, one red and one green:

....

And then you draw a screen aligned 4x4 quad using the red tile:


That will look fine. But draw the same quad scaled (or rotated, or translated by a fractional amount):

....
And you'll see that it has green-tinged edges. The linear texture filtering is doing exactly what you told it to do.


I believe I understand what you are saying. However, I do not scale, rotate, or translate my quads in any way and the geometry to texel thing you mentioned is always 1:1.

Could it be the case that when switching my screen resolution opengl applies scaling transformations to my geometry which creates this effect?.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #14
If you compare the two pictures you posted, you can see that "before" is 1:1 and "after" is not. Compare the stone tiles on the house-- you can see everything is slightly smudged if you look at it closely.

The 1:1 mapping is a function of your texture, texture coordinates, vertex positions, projection, and viewport. Changing any of those things can affect the scaling.

So, changing either the viewport or the modelview via glScale can introduce this error.
The screen resolution itself is irrelevant, but you typically use glViewport to fill the screen, so that matters.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #15
Turns out I had the wrong view resize setting in Interface Builder- now I really feel dumbBlush
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  AGL - Possible resolutions Duane 3 2,617 May 5, 2005 02:47 PM
Last Post: Duane