   stretching/shrinking a texture in a quad
  How can I adjust the texture to a quad to avoid it being repeated all ovver the quad area?   
  Set the texture coordinates for the quad vertices to 0.0f and 1.0f (depending on where you are on the quad). Eg (assuming a lower left screen origin):glTexCoord2f(0.0f, 1.0f); glVertex2f(x, y);glTexCoord2f(1.0f, 1.0f); glVertex2f(x+32, y);glTexCoord2f(1.0f, 0.0f); glVertex2f(x+32, y+32);glTexCoord2f(0.0f, 0.0f); glVertex2f(x, y+32);   ;  How can i know the origin? I have tried different orders and I always get a mess or the texture inverted and repeated.   ;Quote:Original post by rogerdvHow can i know the origin? I have tried different orders and I always get a mess or the texture inverted and repeated.I thought we've solved this problem in the other thread, where I asked you to reverse the vertex order and see if it all works out. The origin is where you specify it with glOrtho. So, the example above assumes glOrtho(0.0f,width,0.0f,height,-1.0f,1.0f), which places the origin at the lower left. DMINATOR states that your example draws fine, but when I do it your way, all my quads are black (aka I "see" the backfaces but I have backfaces culling on). If you want to keep the origin at the upper left (as you originally had, and as is most common in many GUI's), then (to the best of my knowledge) you have to draw your quads clockwise.   ;  Well I only checked that it draws atleast but without texture. So I don't have any idea how the texture is rendered. Besides it is not so easy to confirm, some of my texture managers, flip texture so its hard to get accurate result for everyone I think.   ;Quote:Well I only checked that it draws atleast but without texture. So I don't have any idea how the texture is rendered. Besides it is not so easy to confirm, some of my texture managers, flip texture so its hard to get accurate result for everyone I think.Fair enough, but the texturing shouldn't matter to the issue about the backfaces I think. But then again, the OP probably did not disable backface drawing :S. One reason I can think of why you'd see the flipping problem is that when you save a texture as TGA (are you using that format?) you put the origin "in the wrong place", since with TGA you can define the origin.In case the OP wants more explicit code, here's an actual example that works in my "engine" to draw the mouse cursor on screen, concatenated into one function so that it's easier to understand:glDisable(GL_DEPTH_TEST);glDisable(GL_LIGHTING);glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();glOrtho(0,width,0,height,-1,1);glMatrixMode(GL_MODELVIEW);glPushMatrix();glLoadIdentity();glBindTexture(GL_TEXTURE_2D, texcursor);glEnable(GL_BLEND);glBegin(GL_QUADS);glTexCoord2f(0.0f, 1.0f); glVertex2f(x, y);glTexCoord2f(1.0f, 1.0f); glVertex2f(x+32, y);glTexCoord2f(1.0f, 0.0f); glVertex2f(x+32, y+32);glTexCoord2f(0.0f, 0.0f); glVertex2f(x, y+32);glEnd(); glMatrixMode(GL_PROJECTION);glPopMatrix();glMatrixMode(GL_MODELVIEW);glPopMatrix();glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);This was originally java code - I've formatted it the C++ way for you, it should work without many modifications but let me know if you run into problems.   ;  Im using png files, loaded with sdl_image. After that, I reverse the order as to convert the sdl_surface to a texture useable by open gl. Im using png because I plan to use transparency later.Here is what I get:And here is the drawing code:[source language="C"]void window::draw_tbar() //draw title bar{    glBindTexture(GL_TEXTURE_2D, theme::getTheme()->tbar_back);    glBegin(GL_QUADS);    glTexCoord2f(0.0,0.0);    glVertex2f(x,y);    glTexCoord2f(1.0,0.0);    glVertex2f(x+w,y);    glTexCoord2f(1.0,1.0);    glVertex2f(x+w,y+24);    glTexCoord2f(0.0,1.0);    glVertex2f(x,y+24);    //Draw close button   glEnd();  return;}void window::redraw(){    if (!visible) {   printf("No es visible\n");   return;   //double check   }    //printf("Windows redraw\n");  // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer    glMatrixMode(GL_PROJECTION);    glPushMatrix();    glLoadIdentity();/* Reset The Projection Matrix */   glOrtho(0.0f,640,480,0,-1.0f,1.0f);   glMatrixMode(GL_MODELVIEW);    glPushMatrix();    glLoadIdentity();glDisable(GL_DEPTH_TEST);//draw dialog window    glBindTexture(GL_TEXTURE_2D, theme::getTheme()->dialog_back);    glBegin(GL_QUADS);    glTexCoord2f(0,0);    glVertex2f(x,y);    glTexCoord2f(1,0);    glVertex2f(x+w,y);    glTexCoord2f(1,1);    glVertex2f(x+w,y+h);    glTexCoord2f(0,1);    glVertex2f(x,y+h);   glEnd();   draw_tbar();   glMatrixMode(GL_MODELVIEW);    glPopMatrix();    glMatrixMode(GL_PROJECTION);    glPopMatrix();    glMatrixMode(GL_MODELVIEW);    glEnable(GL_DEPTH_TEST);  return;}SDL_Surface *invert_surf(SDL_Surface *surface) //code to fix surface{    Uint8 *rowhi, *rowlo;    Uint8 *tmpbuf, tmpch;    int i, j;    if ( surface == NULL ) {   printf( "Unable to load \n");   return(NULL);    }    /* GL surfaces are upsidedown and RGB, not BGR :-) */    tmpbuf = (Uint8 *)malloc(surface->pitch);    if ( tmpbuf == NULL ) {   fprintf(stderr, "Out of memory\n");   return(NULL);    }    rowhi = (Uint8 *)surface->pixels;    rowlo = rowhi + (surface->h * surface->pitch) - surface->pitch;    for ( i=0; i<surface->h/2; ++i ) {   for ( j=0; j<surface->w; ++j ) {  tmpch = rowhi[j*3];  rowhi[j*3] = rowhi[j*3+2];  rowhi[j*3+2] = tmpch;  tmpch = rowlo[j*3];  rowlo[j*3] = rowlo[j*3+2];  rowlo[j*3+2] = tmpch;   }   memcpy(tmpbuf, rowhi, surface->pitch);   memcpy(rowhi, rowlo, surface->pitch);   memcpy(rowlo, tmpbuf, surface->pitch);   rowhi += surface->pitch;   rowlo -= surface->pitch;    }    free(tmpbuf);    return(surface);};  Your gl code looks ok. I'm not familiar at all with SDL but my first suspect for the strange tiling would be your image invertion algorithm. Maybe you should try dumping the output of that function to a bmp file and taking a look at it.Edit: OGL textures are not "upside down" per se, just that the origin is in the lower left. ^_^ I also don't remember PNG being in BGR format, are you sure about that?[Edited by - lightbringer on December 9, 2005 7:15:33 AM];  I removed flipping code and I got this:the dialog title bar should look this way:;  You are loading an RGBA (which png usually should be, afaik) into an RGB but assuming that it is stored as BGR. I can't help you with SDL unfortunately beyound the fact that I know that PNG work fine when loaded with DevIL (I do this quite a bit), and with transparency too :S If you post the entire loading code, maybe someone else can help you out.   