Sign in to follow this  
Riddle

Textures messed up! (Scaled)

Recommended Posts

Hello! I currently have a problem I can't solve. All my textures are somehow suddenly scaled down: Image Hosted by ImageShack.us The textures look fine if I scale my objects for around 1.89! What do you guys think could be the problem? Should I post my texture loading code? I checked the modelview matrix before I was rendering the object above: 1, 0, 0, 0 0, 1, 0, 0 0, 0, 1, 0 0, 0, 0, 1 -> identity! Please help me, thank you!

Share this post


Link to post
Share on other sites
Could it be that you are using low-res render target? Window size doesn't matter, after all.

Or it could be, that it's using some low-level mipmap. In orthogonal mode it is possible. Render settings may be of use.

Just a thought...
/def

// Posting more code? Why not.

Share this post


Link to post
Share on other sites
Hi!

I added:
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );

to my loading code. If my objects are in identity mode then they look fine.
But If I rotate:

Image Hosted by ImageShack.us

Quite ugly.. Is this normal?

Thank you!


Some setup settings(scaled down to GL commands):

glViewport( 0, 0, window.Width, window.Height );

Gl.glMatrixMode( Gl.GL_PROJECTION );
Gl.glLoadIdentity();
Gl.glOrtho( 0.0f, window.Width, window.Height, 0.0f, -1.0f, 1.0 );

Gl.glEnable( gl.GL_BLEND );
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);


Texture loading(scaled down to the used textures):

Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAX_LEVEL, 0 );
// New:
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );

Gl.glTexImage2D( Gl.GL_TEXTURE_2D,
0,
hasAlpha ? Gl.GL_RGBA8 : Gl.GL_RGB8,
width, height, 0,
this.GLPixelFormat, Gl.GL_UNSIGNED_BYTE,
data );





Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
to my loading code. If my objects are in identity mode then they look fine.
But If I rotate:
[...]
Quite ugly.. Is this normal?


Seeems fine to me - not ugly at all. If you're using same render-target resolution as the size of the texture, it WILL BE somewhat screwed.

Quote:

Gl.glOrtho( 0.0f, window.Width, window.Height, 0.0f, -1.0f, 1.0 );


Ortho from -1.0 to 1.0? If you're placing the textured object at depth 0.0, it's relatively far from the viewer, and I wouldn't be surprised if a mipmap was used. Why don't just use (0.0, 1.0)?

Cheers.
/def

Share this post


Link to post
Share on other sites
Quote:

Seeems fine to me - not ugly at all. If you're using same render-target resolution as the size of the texture, it WILL BE somewhat screwed.


When I rotate the object there are some moving lines in the texture... This is not so pretty. But normal? Okay! There is also no difference with different resolutions.

Quote:

Ortho from -1.0 to 1.0? If you're placing the textured object at depth 0.0, it's relatively far from the viewer, and I wouldn't be surprised if a mipmap was used. Why don't just use (0.0, 1.0)?

Cheers.
/def


No difference between (0.0, 1.0) and (-1.0 to 1.0). But this is because
my objects don't have a depth value atm. Just one question: Do my object scale
with the above ortho projection when they have different depth(z) values?


Thank you! r++

Share this post


Link to post
Share on other sites
Quote:
Original post by deffer
Quote:

Gl.glOrtho( 0.0f, window.Width, window.Height, 0.0f, -1.0f, 1.0 );


Ortho from -1.0 to 1.0? If you're placing the textured object at depth 0.0, it's relatively far from the viewer, and I wouldn't be surprised if a mipmap was used. Why don't just use (0.0, 1.0)?

Cheers.
/def


A mipmap is only used if the screensize if different. It shouldn't be used if it's just far away.

In ortho mode objects will not be scaled if they are far away.

Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
There is also no difference with different resolutions.


Now this is NOT normal(at least not desirable). It's got to be a little screwed, but with high-res, it should be a smooth and "antialiased-like". Try experimenting a little with LINEAR_MIPMAP_LINEAR. Or post a high-res screen-shot.

Quote:

Just one question: Do my object scale with the above ortho projection when they have different depth(z) values?


No, as when Z column is (0,0,1,0), final z-value is equal to original z-value.

EDIT: @rick_appleton is right, being far away is not a reason for the card to use mipmap, it's being minimized, which doesn't happen in this case.

Share this post


Link to post
Share on other sites
Quote:

Now this is NOT normal(at least not desirable). It's got to be a little screwed, but with high-res, it should be a smooth and "antialiased-like". Try experimenting a little with LINEAR_MIPMAP_LINEAR. Or post a high-res screen-shot.


Ah! YOu are right.. I thought you mean the size of my render window.

Quote:

No, as when Z column is (0,0,1,0), final z-value is equal to original z-value.


Good! So I can use the Z value for depth sorting? And the Z value must be in range
znear, zfar of the ortho mode to be drawn?


My objects are still ugly when I rotate them. The strange moving lines..


Thanks again,
Riddle.

Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
My objects are still ugly when I rotate them. The strange moving lines..

(Gosh, this really seems to me like a problem with jumping texels, but since you're using GL_LINEAR... ugh, my head...)

Give some more info:
- texture size
- render target size
- window size

Quote:

And the Z value must be in range znear, zfar of the ortho mode to be drawn?

It's "near and far clipping plane", so, yeah, unless you do not have depth-test enabled.

Quote:

So I can use the Z value for depth sorting?

GPU does that for you, so why would you do that by hand? Only if you're doing some tricky blending, like in particle systemZ.
/def

Share this post


Link to post
Share on other sites
Quote:

Give some more info:
- texture size
- render target size
- window size


128/128
128/128
800/640 ( Same problem with all resolutions )

You see the lines in this picture:
Image Hosted by ImageShack.us

They rotate and move as I rotate my object. Looks really irritating!



Quote:

It's "near and far clipping plane", so, yeah, unless you do not have depth-test enabled.
GPU does that for you, so why would you do that by hand? Only if you're doing some tricky blending, like in particle systemZ.


Yes, I understand.

Thanks!

[Edited by - Riddle on June 24, 2005 5:02:20 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
128/128
128/128
800/640 ( Same problem with all resolutions )


If I got you straight, you made this mistake:

800/640 (window size) - this is not a resolution.
128/128 (render target size) - this is your resolution.

All internal rendering is made using render target(buffer), and after all is rendered (and in this case, somewhat screwed, as you say), it's scaled to fit into the window size(it's too late then).

Am I right?
/def

Share this post


Link to post
Share on other sites
Hmm! I though by render target you mean the object the texture is put on!

I don't really understand what you mean with render target!



And here one more picture: (So you can see what I mean)

Image Hosted by ImageShack.us

[Edited by - Riddle on June 24, 2005 5:20:50 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
I don't really understand what you mean with render target!


Bsically it's the pixel buffer, that the card is writing on. All rendering is performed on it. At the very end of the process, it's contents are scaled and put into the window.

Quote:

How do I setup and get the render target size?

((quoted phrase magically dissapeared))

It depends on what you use as layer between the app and gl. I'm using GLFW, so it does this for me, but only as the app starts. I cannot change it later (at least not with enlarging the window).
How do you init the window, and gl in the first place?
/def

Share this post


Link to post
Share on other sites
Quote:

Bsically it's the pixel buffer, that the card is writing on. All rendering is performed on it. At the very end of the process, it's contents are scaled and put into the window.


I didn't know this was the rendering target! Heh. (:
Quote:


[qoute]
It depends on what you use as layer between the app and gl. I'm using GLFW, so it does this for me, but only as the app starts. I cannot change it later (at least not with enlarging the window).
How do you init the window, and gl in the first place?

I use Tao.Sdl to createmy window:



if( Sdl.SDL_Init( Sdl.SDL_INIT_VIDEO ) < 0 )
{
throw new Water.Exceptions.WaterException( SDLStrings.CouldntInitSDLX, Sdl.SDL_GetError() );
}

int flags = Sdl.SDL_OPENGL;
if( isFullScreen == true )
{
flags |= Sdl.SDL_FULLSCREEN;
}

IntPtr videoPtr = Sdl.SDL_GetVideoInfo();
if( videoPtr == null )
{
throw new Water.Exceptions.WaterException( SDLStrings.AttemptToGetSDLVideoInfoFailed );
}

Sdl.SDL_VideoInfo videoInfo = DL_VideoInfo)System.Runtime.InteropServices.Marshal.PtrToStructure(
videoPtr, typeof( Sdl.SDL_VideoInfo ) );

if( videoInfo.hw_available != 0 )
flags |= Sdl.SDL_HWSURFACE;
else
flags |= Sdl.SDL_SWSURFACE;

if( videoInfo.blit_hw != 0 )
flags |= Sdl.SDL_HWACCEL;

Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 8 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_GREEN_SIZE, 8 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 8 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DEPTH_SIZE, 16 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 );

surface = Sdl.SDL_SetVideoMode( width, height, colorDepth, flags );


Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
I use Tao.Sdl to createmy window:
*** Source Snippet Removed ***


Looks fine to me. I think I can assume the render target is the same as the window size at creation time.

How about rendering a larger texture? How does this look? Gather information. Try to narrow this flaw a bit...
/def

Share this post


Link to post
Share on other sites
What are those red lines in the last image?

Anyway Riddle, there's no problem. You just get aliasing in the edges of the characters. If your card supports anti-aliasing, turn it on and you'll probably see some improvement.

Quote:

Quote:Original post by Riddle
I don't really understand what you mean with render target!


Bsically it's the pixel buffer, that the card is writing on. All rendering is performed on it. At the very end of the process, it's contents are scaled and put into the window.


Quote:
How do I setup and get the render target size?



((quoted phrase magically dissapeared))

It depends on what you use as layer between the app and gl. I'm using GLFW, so it does this for me, but only as the app starts. I cannot change it later (at least not with enlarging the window).
How do you init the window, and gl in the first place?
/def


Are you sure you're not confusing some things? The term "Render targets" is used in an entirely different context, when you want to render in other surfaces besides the framebuffer(in a texture for example). Riddle is definately not using render targets. When antialiasing is on, things get rendered in a bigger buffer than the window(2x,4x,8x...) and then get downsampled, but I imagine that's not what you mean. You don't setup up "render target size", you just setup the window size and the viewport size with glViewport(). What do you mean "I cannot change it later"? Sure you can. Resize the window, resize the viewport and you're done.

Share this post


Link to post
Share on other sites
Quote:

What are those red lines in the last image?


I made them to show you the lines in the original(left) image.

Quote:

Anyway Riddle, there's no problem. You just get aliasing in the edges of the characters. If your card supports anti-aliasing, turn it on and you'll probably see some improvement.

FSAA only improves the edges. The problem is inside the object!



I just tried three different objects.. and no problems!
1. Very small texture: 16/16 no alpha
2. Very big texture: 512/512 no alpha
3. Very big texture: 512/512 with alpha


I don't know why this texture gives me problems.. maybe because has only a few
pixels and then alpha again... hmm!

hmm!


Share this post


Link to post
Share on other sites
Quote:

FSAA only improves the edges. The problem is inside the object!


FSAA- Full Screen Anti Aliasing. It doesn't matter if the jaggies are the polygon edges or inside the texture. Have you tried it? Anyway, as I said, the result you get is perfectly normal.

Share this post


Link to post
Share on other sites
Quote:
Original post by Riddle
Hi!

I added:
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );
Looks like the normal effects of a bilinear filter to me.

Share this post


Link to post
Share on other sites
Quote:

FSAA- Full Screen Anti Aliasing. It doesn't matter if the jaggies are the polygon edges or inside the texture. Have you tried it? Anyway, as I said, the result you get is perfectly normal.


Oha, thank you for this info! I will try it now.
::edit::
Hah! I activated FSAA.. the strange lines didn't go away..
but the object itself now looks ugly too in identity rotation! Because FSAA
screwed up the pixels..


Quote:

Looks like the normal effects of a bilinear filter to me.


So how can I make it look better?
Different values for:
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );
?

Share this post


Link to post
Share on other sites
Well, I made a little test, just copied your texture and made a rotating quad. FSAA don't really make that much of a difference, other filters like GL_NEAREST look worse. What I happened to notice that the caption "Real texture" of the image I copied looked much clearer than the font characters, because your characters have hard edges, whereas the caption has soft edges.

Share this post


Link to post
Share on other sites
[quote]Original post by Riddle
Quote:
So how can I make it look better?
Different values for:
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );
?
Change youe texture. fill the letters all the way in black

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
Are you sure you're not confusing some things? The term "Render targets" is used in an entirely different context, when you want to render in other surfaces besides the framebuffer(in a texture for example). Riddle is definately not using render targets.

"The framebuffer" is the same as "main render target". As you can always switch your framebuffer for something else I don't see why it would be any different.

Quote:

You don't setup up "render target size", you just setup the window size and the viewport size with glViewport(). What do you mean "I cannot change it later"? Sure you can. Resize the window, resize the viewport and you're done.

Yes, you do <<setup up "render target size">>. In gl with glViewport. I worked with Direct3D for a long time and it was a little bigger deal there. So I think of it as an OPeration. My bad I made too big a deal of it.

However with bigger framebuffer, the effect of flickering texels should have dissapeared. And it's not. (That's why I thought the framebuffer was small afterall.)
Is that "perfectly normal"?
/def

Share this post


Link to post
Share on other sites
Thank you for all your affort!


[qoute]
Well, I made a little test, just copied your texture and made a rotating quad. FSAA don't really make that much of a difference, other filters like GL_NEAREST look worse. What I happened to notice that the caption "Real texture" of the image I copied looked much clearer than the font characters, because your characters have hard edges, whereas the caption has soft edges.
[/qoute]

Did you see the lines? If not.. did you add alpha to the texture(not inside the screeni)?

Quote:
Change youe texture. fill the letters all the way in black

Haha! That would be a nice bitmap font.. (:



Gl.glViewport( 0, 0, window.Width, window.Height );
Gl.glScissor( 0, 0, window.W, window.Height );






::edit::
Just made a test with the font texture without an alpha component..
and no lines! Hmm~

Share this post


Link to post
Share on other sites
Quote:

Yes, you do <<setup up "render target size">>. In gl with glViewport. I worked with Direct3D for a long time and it was a little bigger deal there. So I think of it as an OPeration. My bad I made too big a deal of it.

However with bigger framebuffer, the effect of flickering texels should have dissapeared. And it's not. (That's why I thought the framebuffer was small afterall.)


No. The framebuffer is the same size as the window. With glViewport, you define the viewport, which specifies the transformation of x and y from normalized coordinates to window coordinates. Nothing prevents you from writing pixels outside that area(you use glScissor() to do that). When you call glClear() for instance, you clear the whole framebuffer, which could be larger than the viewport. That's how you render split-screen in games for example. You don't have to clear for both split-screens, just once.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this