Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

multi image texture scaling problem

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 sjeps   Members   


Posted 20 December 2012 - 07:40 AM

Hi everybody.
I have some images stored one near each other in a single texture. I'm 2d drawing each of them specifing their positions in the texture's coordinate system (0.f-1.f). Everything works fine like that.
Anyway, when i try to zoom (glscalef) one of these images (portion of the whole texture) strange behaviors might occour.
Depending on the zoom size, in addition to the image i'm displaying, also a single line of one of the surronding images in the texture could be displayed. I'm using mag filter NEAREST and no texture wrappings. Using mag filter LINEAR the problem doesn't show up.
Is this some intended behavior? Or maybe a floating point number/rounding problem?
Thx for help

#2 Brother Bob   Moderators   


Posted 20 December 2012 - 07:52 AM

If everything was correctly setup, I would have expected nearest filtering to work and linear filtering to introduce some leakage from adjacent images. In general, sub-imaging doesn't play very well with anything but one-to-one pixel mappings. I could see this behavior showing up if you're not carefully setting up the vertex coordinates and texture coordinates. How, exactly, are you calculating the texture coordinates, and how are you drawing your objects?

#3 sjeps   Members   


Posted 22 December 2012 - 06:49 AM

This is my rendering function of the specified clip:

GLfloat s0,s1,t0,t1,w,h;

s0 = (GLfloat) (clip->x) /texw ;
s1 = (GLfloat) (clip->x+clip->w) /texw ;
t0 = (GLfloat) (clip->y) /texh ;
t1 = (GLfloat) (clip->y+clip->h) /texh ;
w = (GLfloat) (clip->w) ;
h = (GLfloat) (clip->h) ;

OglVertex vertex[4]={
{{ s0, t0 }, { -w/2.f, -h/2.f }},
{{ s1, t0 }, { w/2.f, -h/2.f }},
{{ s1, t1 }, { w/2.f, h/2.f }},
{{ s0, t1 }, { -w/2.f, h/2.f }},


glBindTexture(GL_TEXTURE_2D, texture);
glBindBuffer(GL_ARRAY_BUFFER, dvbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dibo);

glBufferSubData(GL_ARRAY_BUFFER, 0, 4*sizeof(OglVertex), vertex);

glTexCoordPointer(2, GL_FLOAT, sizeof(OglVertex), (GLvoid*)offsetof(OglVertex,texSyst));
glVertexPointer(2, GL_FLOAT, sizeof(OglVertex), (GLvoid*)offsetof(OglVertex, pos));



#4 sjeps   Members   


Posted 25 December 2012 - 01:08 PM

You are right, the problem seems to show up with GL_LINEAR.. This is my code, pretty simple as you can see.

#5 Brother Bob   Moderators   


Posted 26 December 2012 - 07:55 AM

That's only a fraction of the code needed to get something onto the screen, and most of it is not really relevant. For example, how about coordinate transformations such as matrices; do you use any and how do you define them? The matrices define the precise coordinates of your vertices on the screen and are probably the most important information along with the actual values of the vertices.


But as I stated, transformations and sub-imaging doesn't play very well together in the first place, and everything depends on the exact details about the coordinates along the edges of the sub-images.

#6 sjeps   Members   


Posted 26 December 2012 - 09:31 AM

Thanks for your answers!


I just pass integer values to my clips->x clips->y clips->w clips->h (despite their being GLfloats).

As for matrices tranformation nothing more than a simple glScalef with arbitrary float arguments


The enviroment is set up just like this



    glClearColor( 0, 0, 0, 0 );
    glEnable( GL_TEXTURE_2D ); // Need this to display a texture
    glEnable( GL_BLEND );
    glDisable( GL_DEPTH_TEST );
    glViewport( 0, 0, wwidth, wheight );
    glMatrixMode( GL_PROJECTION );
    glOrtho( 0, GAMEWIDTH, GAMEHEIGHT, 0, -1, 1 );
    glMatrixMode( GL_MODELVIEW );
If as you said transformations and sub-imaging does't go along very well, wich is the right way of doing this?
By now i just tought about leaving a transparent pixels line between each image to circumvent the problem

#7 Brother Bob   Moderators   


Posted 26 December 2012 - 11:47 AM

The right way depends on what you are willing to do. Adding a transparent border around each sub-image is one way. Not using sub-images, but separate images, is another.


A note on the border-method though. How exactly you approach this border depends on what accuracy you want. Since you're getting unwanted pixels, there is some difference between what you want and what you're doing.

  • If you add a transparent border, these unwanted pixels will (effectively) be removed from the rendered image. If you want pixel-precise rendering, then these transparent pixels will affect your pixel-precise rendering and produce a different set of pixels that what you expected. For example, if you draw a quad 100 pixels wide and the last column contains transparent pixels, then the quad is really 99 pixels wide and your pixel-precise renderer is now incorrect by one row.
  • If you instead add an opaque border, then your 100 pixels wide quad will remain 100 pixels wide, thus your renderer remains pixel-precise. Your sub-image, however, will not be entirely correct since you have a border that doesn't belong there. You can minimize the visual effect of this border by, for example, replicating the outer border pixels one step outwards. The effect is that the border blends nicely with the sub-image and you may not see the effect of the border anymore.

The border-method has other limitations as well. For example, it doesn't play well at all with mip-mapping. Or, to be correct, sub-imaging as a whole doesn't play well with mip-mapping either, not just the border. Mipmapping is for down-scaling only though, so if you only do up-scaling then mip-mapping serves no purpose and the issues with mip-mapping are eliminated.


If you're willing to add a border, then consider the points above and choose the correct type of border, and it may be sufficient for you. However, if not using sub-images at all is also fine, then I would recommend that over the border.

#8 sjeps   Members   


Posted 26 December 2012 - 12:22 PM

I'm trying to do 2d sprite animations.. And sometimes i need zooms.. Having separate images would probably be unpratical.. I''look into the transparent border (i don't need pixel precise zooms.. They are zooms after all :-) )thanks for your advices!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.