iDevGames Forums
Question about resolutions - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Question about resolutions (/thread-1685.html)

Pages: 1 2


Question about resolutions - NelsonMandella - Mar 3, 2009 01:14 PM

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?


Question about resolutions - NelsonMandella - Mar 3, 2009 11:26 PM

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.


Question about resolutions - AnotherJake - Mar 4, 2009 12:52 AM

You need to try uploading/linking your images again. Great idea to illustrate the situation!


Question about resolutions - NelsonMandella - Mar 4, 2009 01:25 AM

I can't seem to figure out how to upload a picture.


Question about resolutions - Bachus - Mar 4, 2009 09:57 AM

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.


Question about resolutions - stevejohnson - Mar 4, 2009 10:07 AM

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.


Question about resolutions - NelsonMandella - Mar 5, 2009 12:03 PM

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.


Question about resolutions - NelsonMandella - Mar 6, 2009 02:11 PM

..........anyone?


Question about resolutions - AnotherJake - Mar 6, 2009 02:29 PM

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);


Question about resolutions - arekkusu - Mar 7, 2009 09:45 AM

It looks exactly like what you'd expect to see from using a texture atlas with linear filtering.


Question about resolutions - NelsonMandella - Mar 7, 2009 01:43 PM

arekkusu Wrote:It looks exactly like what you'd expect to see from using a texture atlas with linear filtering.

Could you elaborate?


Question about resolutions - arekkusu - Mar 7, 2009 06:33 PM

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.


Question about resolutions - NelsonMandella - Mar 7, 2009 08:44 PM

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?.


Question about resolutions - arekkusu - Mar 7, 2009 09:16 PM

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.


Question about resolutions - NelsonMandella - Mar 7, 2009 09:41 PM

Turns out I had the wrong view resize setting in Interface Builder- now I really feel dumbBlush