Re: Texture colour wrapping
Brice Thurin <[email protected]>
| Newsgroups | gmane.comp.python.opengl.user |
|---|---|
| Message-ID | <CAMww5+a4J5JFiFf0UwCLYDfNAoBUxeJNynq=DpOP4Cw0g=GJbQ@mail.gmail.com> |
Thanks a lot for the example. It helps me quite a bit however I am not sure how to do what I wish to do. I attached to this email an example of what i would like to do. On the left hand side is my original phase map data on a polar grid. I want to make a polar to cartesian transformation of this phase map so it looks like the middle plot in the figure attached, here the phase map is on a cartesian grid. For this two first figures the grayscale cover -5 to 25 radians. Finally I want to wrap the phase data so the maximum grayscale value is max 6.28 radians. I managed to do the first step (polar to cartesian) using quad strip and texture mapping but i am not sure how I can get the vertex value from the middle stage map as it is already a texture. I am certainly missing something but I can not see what. On 6 November 2011 05:23, Dirk Reiners <[email protected]> wrote: > > Hi Brice, > > > On 11/05/2011 03:37 PM, Brice Thurin wrote: > >> Hi Dirk, >> >> Thanks for your help. So if I understand properly, I first do the >> geometrical >> mapping to do the polar to cartesian transformation. Then I do the color >> mapping? >> > > Yes and no. The actual mapping to color is done by the texture, you just > need to feed your data into it in a way that puts the wraparound point at 0 > and 1. > > I appended a simple example. > > > That's sound pretty neat to me. >> > > It is! :) Its really cool, as you can mess with texture to show specific > important values or ranges, make it smooth or stepped (like in my example) > and many other cool tricks. > > Hope it helps > > Dirk > > > #!/usr/bin/python2.4 > # > # Use texture for visualizating a data value. > # > # Based on texturedQuad.py by "Peter Roesch" <[email protected]> > # > # This code is licensed under the PyOpenGL License. > # Details are given in the file license.txt included in this distribution. > > import sys > import array > import math > > try: > from OpenGL.GLUT import * > from OpenGL.GL import * > from OpenGL.GLU import * > except: > print ''' Error PyOpenGL not installed properly !!''' > sys.exit( ) > > def display( ): > """Glut display function.""" > glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) > glColor3f( 1, 1, 1 ) > > # Draw a regular grid > gridres=40 > for y in [y * 1. / gridres - 0.5 for y in range(0, gridres)]: > glBegin(GL_QUAD_STRIP) > > for x in [x * 1. / gridres - 0.5 for x in range(0, gridres + > 1)]: > > # This is where the data value goes... > glTexCoord1f( math.sin(x*x + y*y) * 5 ) > glVertex3f( x, y, 0 ) > > y1 = y + 1. / gridres > glTexCoord1f( math.sin(x*x + y1*y1) * 5 ) > glVertex3f( x, y1, 0 ) > glEnd( ) > > glutSwapBuffers ( ) > > def init( ): > """Glut init function.""" > > glClearColor ( 0, 0, 0, 0 ) > glShadeModel( GL_SMOOTH ) > > # Build texture. Just a trivial grey step one for now > # For a real app you would create a nice lookup table > nsteps = 8 > > ns = 256/nsteps > tmpList = [ int(i/ns)*ns for i in range(0, 256) ] > texdata = array.array( 'B', tmpList ).tostring( ) > texwidth = 256 > > glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT ) > glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) > glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) > > glTexImage1D( GL_TEXTURE_1D, 0, 3, texwidth, 0, > GL_LUMINANCE, GL_UNSIGNED_BYTE, texdata) > glEnable( GL_TEXTURE_1D ) > > glutInit( sys.argv ) > glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ) > glutInitWindowSize( 250, 250 ) > glutInitWindowPosition( 100, 100 ) > glutCreateWindow( sys.argv[0] ) > init( ) > glutDisplayFunc( display ) > glutMainLoop( ) > ------------------------------------------------------------------------------ RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1 _______________________________________________ PyOpenGL Homepage http://pyopengl.sourceforge.net _______________________________________________ PyOpenGL-Users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyopengl-users
example.jpg
(image/jpeg, 21 KB) - not displayed