Thread: [PyOpenGL-Users] generating textures
Brought to you by:
mcfletch
From: Fulko v. W. <Ful...@dt...> - 2003-12-22 10:05:21
|
Hello, I'm rather new to Python and have only basic OpenGL knowledge. I started building a user interface using both. It works very fine (thanks to all developers!), but I can't figure out how to make a texture. For this display I draw a detailed map, and the drawing takes about 0.5s. Rotating the map is far to slow. To speed things up I want to turn the map into a texture, so I can rotate and shift the texture. Loading textures from an image-file is widely described, but I want/need to generate the texture using pyOpenGL. Can that be done?, and if so: how? All tutorials/books say: generate a bitmap. This sounds logical, but I have no idea how to draw a bitmap using OpenGL, let alone making one using Python. Thanks for your help, Fulko -- Fulko van Westrenen fu...@li... |
From: Mike C. F. <mcf...@ro...> - 2003-12-22 15:04:16
|
I'm assuming what you are describing is this: * You currently have OpenGL code that renders the map as geometric primitives (lines, triangles & such) * You want to render this geometry into a texture to allow for faster rendering and transformation See the demo OpenGLContext/tests/saveimage.py, which demonstrates the use of glReadPixels to read data back from the OpenGL buffers into an image (which can then be turned into a texture in the same way as you see done in all the "load from image file" demos). It's also possible to generate bitmaps using such things as setting values in Numpy arrays (particularly useful for creating fractals), using PyGame/wxPython to draw into in-memory surfaces/DCs (simple device-context-based drawing systems), or other mechanisms, btw. Images are just data to be manipulated, and the number of ways you can manipulate/create them is pretty large. Hope this helps, Mike Fulko van Westrenen wrote: >Hello, > >I'm rather new to Python and have only basic OpenGL knowledge. I started >building a user interface using both. It works very fine (thanks to all >developers!), but I can't figure out how to make a texture. > >For this display I draw a detailed map, and the drawing takes about 0.5s. >Rotating the map is far to slow. To speed things up I want to turn the >map into a texture, so I can rotate and shift the texture. Loading >textures from an image-file is widely described, but I want/need to generate >the texture using pyOpenGL. Can that be done?, and if so: how? >All tutorials/books say: generate a bitmap. This sounds logical, but I have >no idea how to draw a bitmap using OpenGL, let alone making one using Python. > >Thanks for your help, > >Fulko > > _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: Mike C. F. <mcf...@ro...> - 2003-12-22 19:39:27
|
Fulko van Westrenen wrote: >On Mon, Dec 22, 2003 at 10:04:07AM -0500, Mike C. Fletcher wrote: > > ... >> * You currently have OpenGL code that renders the map as geometric >> primitives (lines, triangles & such) >> * You want to render this geometry into a texture to allow for >> faster rendering and transformation >> >> >This is very correct. I'm clearly not a programmer, let alone a graphics >programmer. > > Hey, I'm a designer by training, so I'll never say boo on that grounds ;) . >>See the demo OpenGLContext/tests/saveimage.py, which demonstrates the >>use of glReadPixels to read data back from the OpenGL buffers into an >>image (which can then be turned into a texture in the same way as you >>see done in all the "load from image file" demos). >> >> >> >I checked my pyopengl 1.5.7, but no luck. Stop >OpenGLContext! I will download that right now. > > You should likely also download PyOpenGL 2.0.1, as 1.5.7 is over two years old, and playing with OpenGLContext is going to require that you use 2.0.x. >It was my hope that it would be possible to render the map in the >background. Using glReadPixels looks like it can only be used for an >image that is rendered for displaying. > > Easiest (and most reliably available) thing to do is this: * During setup (or whenever you can handle a 1/2 second delay in screen rendering), render your map to the back buffer (i.e. render as normal), do the glReadPixels, then call glClear(...) again and render the next frame of your game. Within Mesa, and other implementations, there are ways to create other off-screen buffers (there's also the "pbuffer" mechanism which is, IIRC done through an OpenGL extension) for this type of work, but none of those are particularly portable AFAIK. >>It's also possible to generate bitmaps using such things as setting >>values in Numpy arrays (particularly useful for creating fractals), >>using PyGame/wxPython to draw into in-memory surfaces/DCs (simple >>device-context-based drawing systems), or other mechanisms, btw. Images >>are just data to be manipulated, and the number of ways you can >>manipulate/create them is pretty large. >> >> > >This is a hard one. I do understand what you want to say, but for an >inexperienced programmer as myself this needs some serious studying >and experimenting. > > Well, rendering it with PyOpenGL and glReadPixels should work fine if you can handle the one-time 1/2 second "hiccup" in rendering. >Just to be complete: my map is a maritime map with coastlines, >depthlines, altitudelines, etc. > > Cool. >I hope I can figure it out tonight. > > Good luck, Mike PS: copied to PyOpenGL-Users for posterity :) _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |