Thread: [PyOpenGL-Users] I'm incapable of mapping a texture, in my small test.
Brought to you by:
mcfletch
From: Alfonso C. <mis...@gm...> - 2007-05-01 02:10:12
|
I exclude GLUT because it's malfunctioning, on my computer. I get the following exception, when I import GLUT: Traceback (most recent call last): File "C:\Documents and Settings\Alfonso\My Documents\Python\PyOpenGL\PyOpenGL- Demo-3.0.0a6\PyOpenGL-Demo\NeHe\lesson6.py", line 47, in <module> from OpenGL.GLUT import * File "build\bdist.win32\egg\OpenGL\GLUT\__init__.py", line 4, in <module> File "build\bdist.win32\egg\OpenGL\GLUT\special.py", line 73, in <module> AttributeError: 'NoneType' object has no attribute 'glutDestroyWindow' Since wxPython is operating well, I just left GLUT alone. In the test I wrote, I rasterize the display, create a polygon the size of the display-area, and *attempt* to render a mapped texture, on each cycle. I had experienced no troble, coloring the rendered polygon. I've opened the specified image, in a seperate program, and found that the image loads properly. From my previous inquiries, I've come to believe that I've set up OpenGL correctly. The texture ought to render. I do not understand what I am doing wrongly. from wx import * from wx.glcanvas import GLCanvas from OpenGL.GL import * from OpenGL.GLU import * import Image, sys, math SCREEN_WIDTH = 400 SCREEN_HEIGHT = 400 def load_image(image_name): image = Image.open(image_name) width = image.size[0] height = image.size[1] image_string = image.tostring('raw', 'RGBX', 0, -1) image_id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, image_id) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_string) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) return image_id class Canvas(GLCanvas): def __init__(self, parent, image_name): GLCanvas.__init__(self, parent, -1) EVT_PAINT(self, self.paint) self.texture_id = load_image(image_name) def paint(self, event): global SCREEN_WIDTH global SCREEN_HEIGHT dc = wx.PaintDC(self) self.SetCurrent() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1, 1) glScalef(1, -1, 1) glTranslatef(0, -SCREEN_HEIGHT, 0) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glEnable(GL_TEXTURE_2D) self.draw() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() self.SwapBuffers() #I kept draw() seperate to ease modifying the test-program. def draw(self): global SCREEN_WIDTH global SCREEN_HEIGHT glBindTexture(GL_TEXTURE_2D, self.texture_id) glBegin(GL_QUADS) glTexCoord2f(0, 0); glVertex2d( 0, 0) glTexCoord2f(1, 0); glVertex2d(SCREEN_WIDTH, 0) glTexCoord2f(1, 1); glVertex2d(SCREEN_WIDTH, SCREEN_HEIGHT) glTexCoord2f(0, 1); glVertex2d( 0, SCREEN_HEIGHT) glEnd() def main(): global SCREEN_WIDTH global SCREEN_HEIGHT app = PySimpleApp() frame = Frame(None, -1, '2D Graphics', DefaultPosition, Size(SCREEN_WIDTH,SCREEN_HEIGHT)) canvas = Canvas(frame, '128x128.bmp') #"128x128.bmp" is a place-holder. frame.Show() app.MainLoop() if __name__ == '__main__': main() -- ...LOLz0rz. |
From: Laurence P. <lau...@gm...> - 2007-06-22 00:03:09
|
I cannot get textures to work in PyOpenGL (Mac OS 10.4 with PyObjC). I think the problem is bogus results from glGenTextures(), as in this example: IDs = glGenTextures(10) print IDs (3356347L, 0L, 3343296L, 249236L, 25816960L, 25817200L, 25816660L, 0L, 3263844L, 0L) I previously wrote an OpenGL program in Objective C. There requesting 10 values reliably gives me the nice sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 I believe all the values returned in PyOpenGL, including 0, are bogus. Duplicate results don't make sense either. Certainly they don't work, and nor do textures work if you force a bind to 1 or 2, etc. -- Laurence |
From: Black <py...@bl...> - 2007-06-22 13:55:13
|
Well, textures certainly do work in PyOpenGL, so it isn't just the call to glGenTextures() that is the problem. It would be helpful to see more of the code that is failing, but my suspicion is that you are calling glGenTextures() before the OpenGL context has been initialized... On Jun 21, 2007, at 2:09 PM, Laurence Penney wrote: > I cannot get textures to work in PyOpenGL (Mac OS 10.4 with PyObjC). > > I think the problem is bogus results from glGenTextures(), as in this > example: > > IDs = glGenTextures(10) > print IDs > > (3356347L, 0L, 3343296L, 249236L, 25816960L, 25817200L, 25816660L, > 0L, 3263844L, 0L) > > I previously wrote an OpenGL program in Objective C. There > requesting 10 > values reliably gives me the nice sequence: > > 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 > > I believe all the values returned in PyOpenGL, including 0, are bogus. > Duplicate results don't make sense either. Certainly they don't > work, and > nor do textures work if you force a bind to 1 or 2, etc. > > -- Laurence > > > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |