Skip to content

Instantly share code, notes, and snippets.

@sansumbrella
Created April 25, 2011 01:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansumbrella/940048 to your computer and use it in GitHub Desktop.
Save sansumbrella/940048 to your computer and use it in GitHub Desktop.
Draw a repeating image in openGL with Cinder types
void drawRepeatingTexture( const gl::Texture& tex, const Rectf& destRect, const Vec2f& textureBounds )
{
tex.enableAndBind();
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
GLfloat verts[8];
GLfloat texCoords[8];
glVertexPointer( 2, GL_FLOAT, 0, verts );
glTexCoordPointer( 2, GL_FLOAT, 0, texCoords );
verts[0*2+0] = destRect.getX2(); verts[0*2+1] = destRect.getY1();
verts[1*2+0] = destRect.getX1(); verts[1*2+1] = destRect.getY1();
verts[2*2+0] = destRect.getX2(); verts[2*2+1] = destRect.getY2();
verts[3*2+0] = destRect.getX1(); verts[3*2+1] = destRect.getY2();
texCoords[0*2+0] = textureBounds.x; texCoords[0*2+1] = 0;
texCoords[1*2+0] = 0; texCoords[1*2+1] = 0;
texCoords[2*2+0] = textureBounds.x; texCoords[2*2+1] = textureBounds.y;
texCoords[3*2+0] = 0; texCoords[3*2+1] = textureBounds.y;
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment