Trying to do 2D tiling

Hello, I’ve created a sprite engine with OpenGL ( http://www.tinrocket.com/content/superspritesurface/index.html ) but I’m having problems tiling images. I’m using quads with texture maps, and the problem I’m having is getting the images to draw 1:1 with the pixels on the screen.

This is how I’ve set up my camera:

gluOrtho2D(0.0,SurfaceWidth-1.0,SurfaceHeight-1.0,0.0)

below is an image tile:

I’m incrementing the X & Y translation in a double loop, stepping by the height and width of the image. This is how I think I should be drawing the image tiles:

    glBegin(GL_QUADS)
    glTexCoord2d(0.0,0.0)
    glVertex2d(0.0,0.0)
    glTexCoord2d(0.0,1.0)
    glVertex2d(0.0,Image.Height-1.0)
    glTexCoord2d(1.0,1.0)
    glVertex2d(Image.Width-1.0,Image.Height-1.0)
    glTexCoord2d(1.0,0.0)
    glVertex2d(Image.Width-1.0,0.0)
    glEnd

but this is the output I’m getting:

it seems that each tile is drawing 1 pixel short on the top and bottom. I think now I might be messing up where I’m assigning the texture coordinates. I’ve tried a bunch of things in various permutations:

offsetting the UV coordinates by half a pixel
offsetting the translated coordinate by half a pixel
offsetting the quad coordinates

but nothing is allowing me to get a 1:1 mapping to the screen. Can anyone help?

Thank you,
John Balestrieri

John,

Not sure if this will help, but perhaps this project would point you in the right direction.
http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/Texture_Clamp_Test.htm

Thomas C.

Thanks, Thomas. That was not it, but I eventually found the problems (two!):

  1. I mistakenly set up the surface’s height & width with the exact number of pixel, rather than the number of pixels+1

  2. I assumed that the GL_TEXTURE_MAG_FILTER was GL_NEAREST by default, rather than GL_LINEAR (which contributed to the artifact problem).

John

Did you know that you can also use one hugh quad and get the texture to repeat by have texture cco-ordinates bigger than 1.

fringe

Originally posted by tinrocket:
[b]

  1. I mistakenly set up the surface’s height & width with the exact number of pixel, rather than the number of pixels+1
    [/b]

If your textures are n*m you should specify this dimension not n+1/m+1 to glTexImage2D. Who told you to do +1?