[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. |