   Blit like SDL with dest and src
  Hi, i have a 2D game based in SDL, and want port to OpenGL without SDL, and one of my Classes (sprite), have a method to blit a surface part for another surface, that's trick enabled blit a animation frame to frame in a tiled sprite (common used. i believe). Anyone have idea how i can make that in OpenGL ? blit parts of a surface for another ? or maybe cut some part of a texture, cause if a try resize the image the texture don't cut, and resizes for images sizeint SDL_BlitSurface(source,source_rect,dest,rect_dest);   
Quote:Original post by durfosHi, i have a 2D game based in SDL, and want port to OpenGL without SDL, and one of my Classes (sprite), have a method to blit a surface part for another surface, that's trick enabled blit a animation frame to frame in a tiled sprite (common used. i believe). Anyone have idea how i can make that in OpenGL ? blit parts of a surface for another ? or maybe cut some part of a texture, cause if a try resize the image the texture don't cut, and resizes for images sizeint SDL_BlitSurface(source,source_rect,dest,rect_dest);The typical approach would be to render a textured quad, with texture coordinates set appropriately to render only the part of the texture you're interested in. For example, if the sprite you want to render occupies the lower-left quarter of the texture, you'd set up your texture coordinates like this:0,.5------.5,.5 | | | |0, 0------.5, 0;  Thanks,jyk that solution fits  good !   ;  You can blit from one framebuffer to another:http://www.opengl.org/registry/specs/ARB/framebuffer_object.txtIn that OpenGL extension the function glBlitFramebuffer is defined as follows:BlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1,   int dstX0, int dstY0, int dstX1, int dstY1,   bitfield mask, enum filter);Bind one of the framebuffers as the READ framebuffer, and bind the other framebuffer as the DRAW framebuffer. Now you can blit from READ to DRAW, using the specified coordinates. I guess, when you use double buffering, you could bind the frontbuffer as the read buffer, while the backbuffer is the one you draw too.However... I think what jyk proposed is a more natural way of doing this.   ;  Hummm, now i a have a simple problem, the calc to cut the parts:glTexCoord2d(Source.iLeft,Source.iBottom);glVertex2d(Dest.iLeft,Dest.iBottom); // Bottom LeftglTexCoord2d(Source.iRight,Source.iBottom);glVertex2d(Dest.iRight,Dest.iBottom); // Bottom RightglTexCoord2d(Source.iRight,Source.iTop);glVertex2d(Dest.iRight,Dest.iTop); // Top RightglTexCoord2d(Source.iLeft,Source.iTop);glVertex2d(Dest.iLeft,Dest.iTop); // Top LeftThe Source is piece of texture that i want to cut, and Dest is the Vertex destiny on Screen, maybe the calc to cut is wrong.Do i need any calc in Source structure, to cut the correct piece ?! Thanks !   ;  Texture coordinates are normalized (between 0 and 1). So you have to calculate the normalized coordinates of the piece of the texture you want to copy.   ;  Then i need normalize between float values, to cut pieces, because if normalize 0 or 1, i can't get the tiles, right !?   ;  i can't find the simple way to solve this problem, anyone know the calc to apply in texture cutting ?   ;  I'm just near of a solution, maybe with some more mathematics abilities. I have found some path. When the texture is complete over a GL_QUAD using 2D , i have the:0,1 ------- 1,1 | | | |0,0 ------- 1,0Ok, no news for experts, but for a beginner in OpenGL some confusions can happen, cause the coordinates are different from SDL Cartesian plan that i used before.Now my problem is simple, mathematics.My surface on memory is 64 width / 128 height, and now i just want to cut some pieces of texture. glTexCoord2f(??,??);glVertex2d(Dest.iLeft,Dest.iBottom); // Bottom LeftglTexCoord2f(??,??);glVertex2d(Dest.iRight,Dest.iBottom); // Bottom RightglTexCoord2f(??,??);glVertex2d(Dest.iRight,Dest.iTop); // Top RightglTexCoord2f(??,??);glVertex2d(Dest.iLeft,Dest.iTop); // Top LeftBut the normalize X and Y over glTexCoord2f is not working. My idea is make a formula to normalize the corrects values over glTexCoord2d using my Source class, that contains iLeft, iTop ... etc just like Dest class. When i try normalize values X and Y, the mess of number blit wrong my surface.Finally i need a little help here, i can't find the formula to normalize values next to 0.5, 0.8, 0.3 ... etc.   