Created
April 25, 2011 01:30
-
-
Save sansumbrella/940048 to your computer and use it in GitHub Desktop.
Draw a repeating image in openGL with Cinder types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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