• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
sjeps

multi image texture scaling problem

7 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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?
1

Share this post


Link to post
Share on other sites
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 }},
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

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

glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, NULL);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
0

Share this post


Link to post
Share on other sites
You are right, the problem seems to show up with GL_LINEAR.. This is my code, pretty simple as you can see.
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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 );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
 
    glViewport( 0, 0, wwidth, wheight );
 
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, GAMEWIDTH, GAMEHEIGHT, 0, -1, 1 );
    
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
 
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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites
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!
0

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  
Followers 0