[PyOpenGL-Users] loading textures
Brought to you by:
mcfletch
From: Prashant S. <ani...@ya...> - 2008-04-18 13:12:37
|
I am trying to load and draw texture on a polygon. Here are the two functions I have written: textures = [] def loadBitmap(fileName): global textures #load in the file textureSurface = pygame.image.load(fileName) textureData = pygame.image.tostring(textureSurface, "RGBX", 1) #Bind it to a texture textures = glGenTextures(2) glBindTexture(GL_TEXTURE_2D, textures[0]) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, textureSurface.get_width(), textureSurface.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData ) def drawBitmap(x,y,width,height): global textures glBindTexture(GL_TEXTURE_2D, textures[0]) glBegin(GL_QUADS) glTexCoord2i(0, 0); glVertex2i(x, y) glTexCoord2i(1, 0); glVertex2i(x+width, y) glTexCoord2i(1, 1); glVertex2i(x+width, y+height) glTexCoord2i(0, 1); glVertex2i(x,y+height) glEnd() and in the draw function I am calling 'drawBitmap(400,400,256,256)' the texture file is of 256x256 resolution. The application I am writing here is 2D. There is no depth test. It's disabled. I am getting a gray colored square instead of textured one...? I am using selection/picking on mouse down. When ever I click the gray square flicks...? Rest of the drawing is having no problem at all. In 'loadBitmap' function if I try to load a single texture using 'textures = glGenTextures(1)' I get an error. How do I solve this...? Best regards. Cheers ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ |